]> granicus.if.org Git - python/commitdiff
This test relied on short-circuiting details of dictobject.py to avoid
authorArmin Rigo <arigo@tunes.org>
Sun, 15 May 2005 13:29:26 +0000 (13:29 +0000)
committerArmin Rigo <arigo@tunes.org>
Sun, 15 May 2005 13:29:26 +0000 (13:29 +0000)
crashing, and indirectly on the fact that hash codes in
random.randrange(1000000000) were very unlikely to exhibit collisions.
To see the problem, replace this number with 500 and observe the crash on
either del target[key] or del keys[i].

The fix prevents recursive mutation, just as in the key insertion case.

Lib/test/test_mutants.py

index 60a17aa8e53e67875f30277d589f4c24d4b83b7e..d495704c688caf3e9f17d67cb03c8a7b2282b779 100644 (file)
@@ -69,14 +69,12 @@ def maybe_mutate():
 
     elif keys:
         # Delete a key at random.
+        mutate = 0   # disable mutation until key deleted
         i = random.randrange(len(keys))
         key = keys[i]
         del target[key]
-        # CAUTION:  don't use keys.remove(key) here.  Or do <wink>.  The
-        # point is that .remove() would trigger more comparisons, and so
-        # also more calls to this routine.  We're mutating often enough
-        # without that.
         del keys[i]
+        mutate = 1
 
 # A horrid class that triggers random mutations of dict1 and dict2 when
 # instances are compared.