[Python-Dev] Need help with test_mutants.py

Tim Peters tim.peters at gmail.com
Thu Aug 24 21:46:30 CEST 2006


[Guido]
> There's a unit test "test_mutants" which I don't understand. If anyone
> remembers what it's doing, please contact me -- after ripping out
> dictionary ordering in Py3k,

Is any form of dictionary comparison still supported, and, if so, what
does "dict1 cmp_op dict2" mean now?

> it stops working.

Traceback?

> In particular, the code in test_one() requires changes, but I don't
> know how... Please help!

The keys and values of dict1 and dict2 are filled with objects of a
user-defined class whose __cmp__ method randomly mutates dict1 and
dict2.  dict1 and dict2 are initially forced to have the same number
of elements, so in current Python:

        c = cmp(dict1, dict2)

triggers a world of pain, with the internal dict code doing fancy
stuff comparing keys and values.  However, every key and value
comparison /may/ mutate the dicts in arbitrary ways, so this is
testing whether the dict comparison implementation blows up
(segfaults, etc) when the dicts it's comparing mutate during
comparison.

If it's only ordering comparisons that have gone away for dicts, then,
e.g., replacing

    c = cmp(dict1, dict2)

with

    c = dict1 == dict2

instead will still meet the test's intent.

No particular /result/ is expected.  The test passes if and only if
Python doesn't crash.  When the test was introduced, it uncovered at
least six distinct failure (crashing) modes across the first 20 times
it was run, so it's well worth keeping around in some form.


More information about the Python-Dev mailing list