Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(208)

Side by Side Diff: Lib/test/test_mutants.py

Issue 602: range: lean and mean (Closed) SVN Base: http://svn.python.org/view/*checkout*/python/branches/py3k/
Patch Set: __len__ is back! Created 5 months, 1 week ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 from test.test_support import verbose, TESTFN 1 from test.test_support import verbose, TESTFN
2 import random 2 import random
3 import os 3 import os
4 4
5 # From SF bug #422121: Insecurities in dict comparison. 5 # From SF bug #422121: Insecurities in dict comparison.
6 6
7 # Safety of code doing comparisons has been an historical Python weak spot. 7 # Safety of code doing comparisons has been an historical Python weak spot.
8 # The problem is that comparison of structures written in C *naturally* 8 # The problem is that comparison of structures written in C *naturally*
9 # wants to hold on to things like the size of the container, or "the 9 # wants to hold on to things like the size of the container, or "the
10 # biggest" containee so far, across a traversal of the container; but 10 # biggest" containee so far, across a traversal of the container; but
(...skipping 110 matching lines...) Show 10 above Show 10 below
121 # Test one pair of randomly generated dicts, each with n entries. 121 # Test one pair of randomly generated dicts, each with n entries.
122 # Note that dict comparison is trivial if they don't have the same number 122 # Note that dict comparison is trivial if they don't have the same number
123 # of entires (then the "shorter" dict is instantly considered to be the 123 # of entires (then the "shorter" dict is instantly considered to be the
124 # smaller one, without even looking at the entries). 124 # smaller one, without even looking at the entries).
125 125
126 def test_one(n): 126 def test_one(n):
127 global mutate, dict1, dict2, dict1keys, dict2keys 127 global mutate, dict1, dict2, dict1keys, dict2keys
128 128
129 # Fill the dicts without mutating them. 129 # Fill the dicts without mutating them.
130 mutate = 0 130 mutate = 0
131 dict1keys = fill_dict(dict1, range(n), n) 131 dict1keys = fill_dict(dict1, list(range(n)), n)
132 dict2keys = fill_dict(dict2, range(n), n) 132 dict2keys = fill_dict(dict2, list(range(n)), n)
133 133
134 # Enable mutation, then compare the dicts so long as they have the 134 # Enable mutation, then compare the dicts so long as they have the
135 # same size. 135 # same size.
136 mutate = 1 136 mutate = 1
137 if verbose: 137 if verbose:
138 print("trying w/ lengths", len(dict1), len(dict2), end=' ') 138 print("trying w/ lengths", len(dict1), len(dict2), end=' ')
139 while dict1 and len(dict1) == len(dict2): 139 while dict1 and len(dict1) == len(dict2):
140 if verbose: 140 if verbose:
141 print(".", end=' ') 141 print(".", end=' ')
142 c = dict1 == dict2 142 c = dict1 == dict2
(...skipping 139 matching lines...) Show 10 above Show 10 below
282 try: 282 try:
283 print(dict[Machiavelli3(2)], file=f) 283 print(dict[Machiavelli3(2)], file=f)
284 except KeyError: 284 except KeyError:
285 pass 285 pass
286 finally: 286 finally:
287 f.close() 287 f.close()
288 os.unlink(TESTFN) 288 os.unlink(TESTFN)
289 289
290 del dict 290 del dict
291 del dict1, dict2, dict1keys, dict2keys 291 del dict1, dict2, dict1keys, dict2keys
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r338