Back to index

python3.2  3.2.2
Classes | Functions | Variables
test.test_mutants Namespace Reference

Classes

class  Horrid
class  Child
 Another segfault bug, distilled by Michael Hudson from a c.l.py post. More...
class  Parent
class  Machiavelli
class  Machiavelli2
class  Machiavelli3

Functions

def maybe_mutate
def fill_dict
def test_one
def test

Variables

dictionary dict1 = {}
dictionary dict2 = {}
list dict1keys = []
list dict2keys = []
int mutate = 0
tuple f = open(TESTFN, "w")
dictionary dict = {}
 And another core-dumper from Michael Hudson.

Function Documentation

def test.test_mutants.fill_dict (   d,
  candidates,
  numentries 
)

Definition at line 114 of file test_mutants.py.

00114 
00115 def fill_dict(d, candidates, numentries):
00116     d.clear()
00117     for i in range(numentries):
00118         d[Horrid(random.choice(candidates))] = \
00119             Horrid(random.choice(candidates))
00120     return list(d.keys())
00121 
00122 # Test one pair of randomly generated dicts, each with n entries.
00123 # Note that dict comparison is trivial if they don't have the same number
00124 # of entires (then the "shorter" dict is instantly considered to be the
00125 # smaller one, without even looking at the entries).

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 47 of file test_mutants.py.

00047 
00048 def maybe_mutate():
00049     global mutate
00050     if not mutate:
00051         return
00052     if random.random() < 0.5:
00053         return
00054 
00055     if random.random() < 0.5:
00056         target, keys = dict1, dict1keys
00057     else:
00058         target, keys = dict2, dict2keys
00059 
00060     if random.random() < 0.2:
00061         # Insert a new key.
00062         mutate = 0   # disable mutation until key inserted
00063         while 1:
00064             newkey = Horrid(random.randrange(100))
00065             if newkey not in target:
00066                 break
00067         target[newkey] = Horrid(random.randrange(100))
00068         keys.append(newkey)
00069         mutate = 1
00070 
00071     elif keys:
00072         # Delete a key at random.
00073         mutate = 0   # disable mutation until key deleted
00074         i = random.randrange(len(keys))
00075         key = keys[i]
00076         del target[key]
00077         del keys[i]
00078         mutate = 1
00079 
00080 # A horrid class that triggers random mutations of dict1 and dict2 when
00081 # instances are compared.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 154 of file test_mutants.py.

00154 
00155 def test(n):
00156     for i in range(n):
00157         test_one(random.randrange(1, 100))
00158 
00159 # See last comment block for clues about good values for n.
00160 test(100)

Here is the call graph for this function:

Definition at line 126 of file test_mutants.py.

00126 
00127 def test_one(n):
00128     global mutate, dict1, dict2, dict1keys, dict2keys
00129 
00130     # Fill the dicts without mutating them.
00131     mutate = 0
00132     dict1keys = fill_dict(dict1, range(n), n)
00133     dict2keys = fill_dict(dict2, range(n), n)
00134 
00135     # Enable mutation, then compare the dicts so long as they have the
00136     # same size.
00137     mutate = 1
00138     if verbose:
00139         print("trying w/ lengths", len(dict1), len(dict2), end=' ')
00140     while dict1 and len(dict1) == len(dict2):
00141         if verbose:
00142             print(".", end=' ')
00143         c = dict1 == dict2
00144     if verbose:
00145         print()
00146 
00147 # Run test_one n times.  At the start (before the bugs were fixed), 20
00148 # consecutive runs of this test each blew up on or before the sixth time
00149 # test_one was run.  So n doesn't have to be large to get an interesting
00150 # test.
00151 # OTOH, calling with large n is also interesting, to ensure that the fixed
00152 # code doesn't hold on to refcounts *too* long (in which case memory would
00153 # leak).

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

And another core-dumper from Michael Hudson.

Definition at line 196 of file test_mutants.py.

Definition at line 31 of file test_mutants.py.

Definition at line 36 of file test_mutants.py.

Definition at line 32 of file test_mutants.py.

Definition at line 37 of file test_mutants.py.

tuple test.test_mutants.f = open(TESTFN, "w")

Definition at line 188 of file test_mutants.py.

Definition at line 40 of file test_mutants.py.