0001 import unittest 0002 from test import test_support 0003 from weakref import proxy 0004 import operator 0005 import copy 0006 import pickle 0007 import os 0008 0009 class PassThru(Exception): 0010 pass 0011 0012 def check_pass_thru(): 0013 raise PassThru 0014 yield 1 0015 0016 class TestJointOps(unittest.TestCase): 0017 # Tests common to both set and frozenset 0018 0019 def setUp(self): 0020 self.word = word = 'simsalabim' 0021 self.otherword = 'madagascar' 0022 self.letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' 0023 self.s = self.thetype(word) 0024 self.d = dict.fromkeys(word) 0025 0026 def test_new_or_init(self): 0027 self.assertRaises(TypeError, self.thetype, [], 2) 0028 0029 def test_uniquification(self): 0030 actual = sorted(self.s) 0031 expected = sorted(self.d) 0032 self.assertEqual(actual, expected) 0033 self.assertRaises(PassThru, self.thetype, check_pass_thru()) 0034 self.assertRaises(TypeError, self.thetype, [[]]) 0035 0036 def test_len(self): 0037 self.assertEqual(len(self.s), len(self.d)) 0038 0039 def test_contains(self): 0040 for c in self.letters: 0041 self.assertEqual(c in self.s, c in self.d) 0042 self.assertRaises(TypeError, self.s.__contains__, [[]]) 0043 s = self.thetype([frozenset(self.letters)]) 0044 self.assert_(self.thetype(self.letters) in s) 0045 0046 def test_union(self): 0047 u = self.s.union(self.otherword) 0048 for c in self.letters: 0049 self.assertEqual(c in u, c in self.d or c in self.otherword) 0050 self.assertEqual(self.s, self.thetype(self.word)) 0051 self.assertEqual(type(u), self.thetype) 0052 self.assertRaises(PassThru, self.s.union, check_pass_thru()) 0053 self.assertRaises(TypeError, self.s.union, [[]]) 0054 for C in set, frozenset, dict.fromkeys, str, unicode, list, tuple: 0055 self.assertEqual(self.thetype('abcba').union(C('cdc')), set('abcd')) 0056 self.assertEqual(self.thetype('abcba').union(C('efgfe')), set('abcefg')) 0057 self.assertEqual(self.thetype('abcba').union(C('ccb')), set('abc')) 0058 self.assertEqual(self.thetype('abcba').union(C('ef')), set('abcef')) 0059 0060 def test_or(self): 0061 i = self.s.union(self.otherword) 0062 self.assertEqual(self.s | set(self.otherword), i) 0063 self.assertEqual(self.s | frozenset(self.otherword), i) 0064 try: 0065 self.s | self.otherword 0066 except TypeError: 0067 pass 0068 else: 0069 self.fail("s|t did not screen-out general iterables") 0070 0071 def test_intersection(self): 0072 i = self.s.intersection(self.otherword) 0073 for c in self.letters: 0074 self.assertEqual(c in i, c in self.d and c in self.otherword) 0075 self.assertEqual(self.s, self.thetype(self.word)) 0076 self.assertEqual(type(i), self.thetype) 0077 self.assertRaises(PassThru, self.s.intersection, check_pass_thru()) 0078 for C in set, frozenset, dict.fromkeys, str, unicode, list, tuple: 0079 self.assertEqual(self.thetype('abcba').intersection(C('cdc')), set('cc')) 0080 self.assertEqual(self.thetype('abcba').intersection(C('efgfe')), set('')) 0081 self.assertEqual(self.thetype('abcba').intersection(C('ccb')), set('bc')) 0082 self.assertEqual(self.thetype('abcba').intersection(C('ef')), set('')) 0083 0084 def test_and(self): 0085 i = self.s.intersection(self.otherword) 0086 self.assertEqual(self.s & set(self.otherword), i) 0087 self.assertEqual(self.s & frozenset(self.otherword), i) 0088 try: 0089 self.s & self.otherword 0090 except TypeError: 0091 pass 0092 else: 0093 self.fail("s&t did not screen-out general iterables") 0094 0095 def test_difference(self): 0096 i = self.s.difference(self.otherword) 0097 for c in self.letters: 0098 self.assertEqual(c in i, c in self.d and c not in self.otherword) 0099 self.assertEqual(self.s, self.thetype(self.word)) 0100 self.assertEqual(type(i), self.thetype) 0101 self.assertRaises(PassThru, self.s.difference, check_pass_thru()) 0102 self.assertRaises(TypeError, self.s.difference, [[]]) 0103 for C in set, frozenset, dict.fromkeys, str, unicode, list, tuple: 0104 self.assertEqual(self.thetype('abcba').difference(C('cdc')), set('ab')) 0105 self.assertEqual(self.thetype('abcba').difference(C('efgfe')), set('abc')) 0106 self.assertEqual(self.thetype('abcba').difference(C('ccb')), set('a')) 0107 self.assertEqual(self.thetype('abcba').difference(C('ef')), set('abc')) 0108 0109 def test_sub(self): 0110 i = self.s.difference(self.otherword) 0111 self.assertEqual(self.s - set(self.otherword), i) 0112 self.assertEqual(self.s - frozenset(self.otherword), i) 0113 try: 0114 self.s - self.otherword 0115 except TypeError: 0116 pass 0117 else: 0118 self.fail("s-t did not screen-out general iterables") 0119 0120 def test_symmetric_difference(self): 0121 i = self.s.symmetric_difference(self.otherword) 0122 for c in self.letters: 0123 self.assertEqual(c in i, (c in self.d) ^ (c in self.otherword)) 0124 self.assertEqual(self.s, self.thetype(self.word)) 0125 self.assertEqual(type(i), self.thetype) 0126 self.assertRaises(PassThru, self.s.symmetric_difference, check_pass_thru()) 0127 self.assertRaises(TypeError, self.s.symmetric_difference, [[]]) 0128 for C in set, frozenset, dict.fromkeys, str, unicode, list, tuple: 0129 self.assertEqual(self.thetype('abcba').symmetric_difference(C('cdc')), set('abd')) 0130 self.assertEqual(self.thetype('abcba').symmetric_difference(C('efgfe')), set('abcefg')) 0131 self.assertEqual(self.thetype('abcba').symmetric_difference(C('ccb')), set('a')) 0132 self.assertEqual(self.thetype('abcba').symmetric_difference(C('ef')), set('abcef')) 0133 0134 def test_xor(self): 0135 i = self.s.symmetric_difference(self.otherword) 0136 self.assertEqual(self.s ^ set(self.otherword), i) 0137 self.assertEqual(self.s ^ frozenset(self.otherword), i) 0138 try: 0139 self.s ^ self.otherword 0140 except TypeError: 0141 pass 0142 else: 0143 self.fail("s^t did not screen-out general iterables") 0144 0145 def test_equality(self): 0146 self.assertEqual(self.s, set(self.word)) 0147 self.assertEqual(self.s, frozenset(self.word)) 0148 self.assertEqual(self.s == self.word, False) 0149 self.assertNotEqual(self.s, set(self.otherword)) 0150 self.assertNotEqual(self.s, frozenset(self.otherword)) 0151 self.assertEqual(self.s != self.word, True) 0152 0153 def test_setOfFrozensets(self): 0154 t = map(frozenset, ['abcdef', 'bcd', 'bdcb', 'fed', 'fedccba']) 0155 s = self.thetype(t) 0156 self.assertEqual(len(s), 3) 0157 0158 def test_compare(self): 0159 self.assertRaises(TypeError, self.s.__cmp__, self.s) 0160 0161 def test_sub_and_super(self): 0162 p, q, r = map(self.thetype, ['ab', 'abcde', 'def']) 0163 self.assert_(p < q) 0164 self.assert_(p <= q) 0165 self.assert_(q <= q) 0166 self.assert_(q > p) 0167 self.assert_(q >= p) 0168 self.failIf(q < r) 0169 self.failIf(q <= r) 0170 self.failIf(q > r) 0171 self.failIf(q >= r) 0172 self.assert_(set('a').issubset('abc')) 0173 self.assert_(set('abc').issuperset('a')) 0174 self.failIf(set('a').issubset('cbs')) 0175 self.failIf(set('cbs').issuperset('a')) 0176 0177 def test_pickling(self): 0178 p = pickle.dumps(self.s) 0179 dup = pickle.loads(p) 0180 self.assertEqual(self.s, dup, "%s != %s" % (self.s, dup)) 0181 0182 def test_deepcopy(self): 0183 class Tracer: 0184 def __init__(self, value): 0185 self.value = value 0186 def __hash__(self): 0187 return self.value 0188 def __deepcopy__(self, memo=None): 0189 return Tracer(self.value + 1) 0190 t = Tracer(10) 0191 s = self.thetype([t]) 0192 dup = copy.deepcopy(s) 0193 self.assertNotEqual(id(s), id(dup)) 0194 for elem in dup: 0195 newt = elem 0196 self.assertNotEqual(id(t), id(newt)) 0197 self.assertEqual(t.value + 1, newt.value) 0198 0199 class TestSet(TestJointOps): 0200 thetype = set 0201 0202 def test_init(self): 0203 s = self.thetype() 0204 s.__init__(self.word) 0205 self.assertEqual(s, set(self.word)) 0206 s.__init__(self.otherword) 0207 self.assertEqual(s, set(self.otherword)) 0208 self.assertRaises(TypeError, s.__init__, s, 2); 0209 self.assertRaises(TypeError, s.__init__, 1); 0210 0211 def test_constructor_identity(self): 0212 s = self.thetype(range(3)) 0213 t = self.thetype(s) 0214 self.assertNotEqual(id(s), id(t)) 0215 0216 def test_hash(self): 0217 self.assertRaises(TypeError, hash, self.s) 0218 0219 def test_clear(self): 0220 self.s.clear() 0221 self.assertEqual(self.s, set()) 0222 self.assertEqual(len(self.s), 0) 0223 0224 def test_copy(self): 0225 dup = self.s.copy() 0226 self.assertEqual(self.s, dup) 0227 self.assertNotEqual(id(self.s), id(dup)) 0228 0229 def test_add(self): 0230 self.s.add('Q') 0231 self.assert_('Q' in self.s) 0232 dup = self.s.copy() 0233 self.s.add('Q') 0234 self.assertEqual(self.s, dup) 0235 self.assertRaises(TypeError, self.s.add, []) 0236 0237 def test_remove(self): 0238 self.s.remove('a') 0239 self.assert_('a' not in self.s) 0240 self.assertRaises(KeyError, self.s.remove, 'Q') 0241 self.assertRaises(TypeError, self.s.remove, []) 0242 s = self.thetype([frozenset(self.word)]) 0243 self.assert_(self.thetype(self.word) in s) 0244 s.remove(self.thetype(self.word)) 0245 self.assert_(self.thetype(self.word) not in s) 0246 self.assertRaises(KeyError, self.s.remove, self.thetype(self.word)) 0247 0248 def test_discard(self): 0249 self.s.discard('a') 0250 self.assert_('a' not in self.s) 0251 self.s.discard('Q') 0252 self.assertRaises(TypeError, self.s.discard, []) 0253 s = self.thetype([frozenset(self.word)]) 0254 self.assert_(self.thetype(self.word) in s) 0255 s.discard(self.thetype(self.word)) 0256 self.assert_(self.thetype(self.word) not in s) 0257 s.discard(self.thetype(self.word)) 0258 0259 def test_pop(self): 0260 for i in xrange(len(self.s)): 0261 elem = self.s.pop() 0262 self.assert_(elem not in self.s) 0263 self.assertRaises(KeyError, self.s.pop) 0264 0265 def test_update(self): 0266 retval = self.s.update(self.otherword) 0267 self.assertEqual(retval, None) 0268 for c in (self.word + self.otherword): 0269 self.assert_(c in self.s) 0270 self.assertRaises(PassThru, self.s.update, check_pass_thru()) 0271 self.assertRaises(TypeError, self.s.update, [[]]) 0272 for p, q in (('cdc', 'abcd'), ('efgfe', 'abcefg'), ('ccb', 'abc'), ('ef', 'abcef')): 0273 for C in set, frozenset, dict.fromkeys, str, unicode, list, tuple: 0274 s = self.thetype('abcba') 0275 self.assertEqual(s.update(C(p)), None) 0276 self.assertEqual(s, set(q)) 0277 0278 def test_ior(self): 0279 self.s |= set(self.otherword) 0280 for c in (self.word + self.otherword): 0281 self.assert_(c in self.s) 0282 0283 def test_intersection_update(self): 0284 retval = self.s.intersection_update(self.otherword) 0285 self.assertEqual(retval, None) 0286 for c in (self.word + self.otherword): 0287 if c in self.otherword and c in self.word: 0288 self.assert_(c in self.s) 0289 else: 0290 self.assert_(c not in self.s) 0291 self.assertRaises(PassThru, self.s.intersection_update, check_pass_thru()) 0292 self.assertRaises(TypeError, self.s.intersection_update, [[]]) 0293 for p, q in (('cdc', 'c'), ('efgfe', ''), ('ccb', 'bc'), ('ef', '')): 0294 for C in set, frozenset, dict.fromkeys, str, unicode, list, tuple: 0295 s = self.thetype('abcba') 0296 self.assertEqual(s.intersection_update(C(p)), None) 0297 self.assertEqual(s, set(q)) 0298 0299 def test_iand(self): 0300 self.s &= set(self.otherword) 0301 for c in (self.word + self.otherword): 0302 if c in self.otherword and c in self.word: 0303 self.assert_(c in self.s) 0304 else: 0305 self.assert_(c not in self.s) 0306 0307 def test_difference_update(self): 0308 retval = self.s.difference_update(self.otherword) 0309 self.assertEqual(retval, None) 0310 for c in (self.word + self.otherword): 0311 if c in self.word and c not in self.otherword: 0312 self.assert_(c in self.s) 0313 else: 0314 self.assert_(c not in self.s) 0315 self.assertRaises(PassThru, self.s.difference_update, check_pass_thru()) 0316 self.assertRaises(TypeError, self.s.difference_update, [[]]) 0317 self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]]) 0318 for p, q in (('cdc', 'ab'), ('efgfe', 'abc'), ('ccb', 'a'), ('ef', 'abc')): 0319 for C in set, frozenset, dict.fromkeys, str, unicode, list, tuple: 0320 s = self.thetype('abcba') 0321 self.assertEqual(s.difference_update(C(p)), None) 0322 self.assertEqual(s, set(q)) 0323 0324 def test_isub(self): 0325 self.s -= set(self.otherword) 0326 for c in (self.word + self.otherword): 0327 if c in self.word and c not in self.otherword: 0328 self.assert_(c in self.s) 0329 else: 0330 self.assert_(c not in self.s) 0331 0332 def test_symmetric_difference_update(self): 0333 retval = self.s.symmetric_difference_update(self.otherword) 0334 self.assertEqual(retval, None) 0335 for c in (self.word + self.otherword): 0336 if (c in self.word) ^ (c in self.otherword): 0337 self.assert_(c in self.s) 0338 else: 0339 self.assert_(c not in self.s) 0340 self.assertRaises(PassThru, self.s.symmetric_difference_update, check_pass_thru()) 0341 self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]]) 0342 for p, q in (('cdc', 'abd'), ('efgfe', 'abcefg'), ('ccb', 'a'), ('ef', 'abcef')): 0343 for C in set, frozenset, dict.fromkeys, str, unicode, list, tuple: 0344 s = self.thetype('abcba') 0345 self.assertEqual(s.symmetric_difference_update(C(p)), None) 0346 self.assertEqual(s, set(q)) 0347 0348 def test_ixor(self): 0349 self.s ^= set(self.otherword) 0350 for c in (self.word + self.otherword): 0351 if (c in self.word) ^ (c in self.otherword): 0352 self.assert_(c in self.s) 0353 else: 0354 self.assert_(c not in self.s) 0355 0356 def test_weakref(self): 0357 s = self.thetype('gallahad') 0358 p = proxy(s) 0359 self.assertEqual(str(p), str(s)) 0360 s = None 0361 self.assertRaises(ReferenceError, str, p) 0362 0363 class SetSubclass(set): 0364 pass 0365 0366 class TestSetSubclass(TestSet): 0367 thetype = SetSubclass 0368 0369 class TestFrozenSet(TestJointOps): 0370 thetype = frozenset 0371 0372 def test_init(self): 0373 s = self.thetype(self.word) 0374 s.__init__(self.otherword) 0375 self.assertEqual(s, set(self.word)) 0376 0377 def test_constructor_identity(self): 0378 s = self.thetype(range(3)) 0379 t = self.thetype(s) 0380 self.assertEqual(id(s), id(t)) 0381 0382 def test_hash(self): 0383 self.assertEqual(hash(self.thetype('abcdeb')), 0384 hash(self.thetype('ebecda'))) 0385 0386 def test_copy(self): 0387 dup = self.s.copy() 0388 self.assertEqual(id(self.s), id(dup)) 0389 0390 def test_frozen_as_dictkey(self): 0391 seq = range(10) + list('abcdefg') + ['apple'] 0392 key1 = self.thetype(seq) 0393 key2 = self.thetype(reversed(seq)) 0394 self.assertEqual(key1, key2) 0395 self.assertNotEqual(id(key1), id(key2)) 0396 d = {} 0397 d[key1] = 42 0398 self.assertEqual(d[key2], 42) 0399 0400 def test_hash_caching(self): 0401 f = self.thetype('abcdcda') 0402 self.assertEqual(hash(f), hash(f)) 0403 0404 def test_hash_effectiveness(self): 0405 n = 13 0406 hashvalues = set() 0407 addhashvalue = hashvalues.add 0408 elemmasks = [(i+1, 1<<i) for i in range(n)] 0409 for i in xrange(2**n): 0410 addhashvalue(hash(frozenset([e for e, m in elemmasks if m&i]))) 0411 self.assertEqual(len(hashvalues), 2**n) 0412 0413 class FrozenSetSubclass(frozenset): 0414 pass 0415 0416 class TestFrozenSetSubclass(TestFrozenSet): 0417 thetype = FrozenSetSubclass 0418 0419 def test_constructor_identity(self): 0420 s = self.thetype(range(3)) 0421 t = self.thetype(s) 0422 self.assertNotEqual(id(s), id(t)) 0423 0424 def test_copy(self): 0425 dup = self.s.copy() 0426 self.assertNotEqual(id(self.s), id(dup)) 0427 0428 def test_nested_empty_constructor(self): 0429 s = self.thetype() 0430 t = self.thetype(s) 0431 self.assertEqual(s, t) 0432 0433 # Tests taken from test_sets.py ============================================= 0434 0435 empty_set = set() 0436 0437 #============================================================================== 0438 0439 class TestBasicOps(unittest.TestCase): 0440 0441 def test_repr(self): 0442 if self.repr is not None: 0443 self.assertEqual(repr(self.set), self.repr) 0444 0445 def test_print(self): 0446 try: 0447 fo = open(test_support.TESTFN, "wb") 0448 print >> fo, self.set, 0449 fo.close() 0450 fo = open(test_support.TESTFN, "rb") 0451 self.assertEqual(fo.read(), repr(self.set)) 0452 finally: 0453 fo.close() 0454 os.remove(test_support.TESTFN) 0455 0456 def test_length(self): 0457 self.assertEqual(len(self.set), self.length) 0458 0459 def test_self_equality(self): 0460 self.assertEqual(self.set, self.set) 0461 0462 def test_equivalent_equality(self): 0463 self.assertEqual(self.set, self.dup) 0464 0465 def test_copy(self): 0466 self.assertEqual(self.set.copy(), self.dup) 0467 0468 def test_self_union(self): 0469 result = self.set | self.set 0470 self.assertEqual(result, self.dup) 0471 0472 def test_empty_union(self): 0473 result = self.set | empty_set 0474 self.assertEqual(result, self.dup) 0475 0476 def test_union_empty(self): 0477 result = empty_set | self.set 0478 self.assertEqual(result, self.dup) 0479 0480 def test_self_intersection(self): 0481 result = self.set & self.set 0482 self.assertEqual(result, self.dup) 0483 0484 def test_empty_intersection(self): 0485 result = self.set & empty_set 0486 self.assertEqual(result, empty_set) 0487 0488 def test_intersection_empty(self): 0489 result = empty_set & self.set 0490 self.assertEqual(result, empty_set) 0491 0492 def test_self_symmetric_difference(self): 0493 result = self.set ^ self.set 0494 self.assertEqual(result, empty_set) 0495 0496 def checkempty_symmetric_difference(self): 0497 result = self.set ^ empty_set 0498 self.assertEqual(result, self.set) 0499 0500 def test_self_difference(self): 0501 result = self.set - self.set 0502 self.assertEqual(result, empty_set) 0503 0504 def test_empty_difference(self): 0505 result = self.set - empty_set 0506 self.assertEqual(result, self.dup) 0507 0508 def test_empty_difference_rev(self): 0509 result = empty_set - self.set 0510 self.assertEqual(result, empty_set) 0511 0512 def test_iteration(self): 0513 for v in self.set: 0514 self.assert_(v in self.values) 0515 0516 def test_pickling(self): 0517 p = pickle.dumps(self.set) 0518 copy = pickle.loads(p) 0519 self.assertEqual(self.set, copy, 0520 "%s != %s" % (self.set, copy)) 0521 0522 #------------------------------------------------------------------------------ 0523 0524 class TestBasicOpsEmpty(TestBasicOps): 0525 def setUp(self): 0526 self.case = "empty set" 0527 self.values = [] 0528 self.set = set(self.values) 0529 self.dup = set(self.values) 0530 self.length = 0 0531 self.repr = "set([])" 0532 0533 #------------------------------------------------------------------------------ 0534 0535 class TestBasicOpsSingleton(TestBasicOps): 0536 def setUp(self): 0537 self.case = "unit set (number)" 0538 self.values = [3] 0539 self.set = set(self.values) 0540 self.dup = set(self.values) 0541 self.length = 1 0542 self.repr = "set([3])" 0543 0544 def test_in(self): 0545 self.failUnless(3 in self.set) 0546 0547 def test_not_in(self): 0548 self.failUnless(2 not in self.set) 0549 0550 #------------------------------------------------------------------------------ 0551 0552 class TestBasicOpsTuple(TestBasicOps): 0553 def setUp(self): 0554 self.case = "unit set (tuple)" 0555 self.values = [(0, "zero")] 0556 self.set = set(self.values) 0557 self.dup = set(self.values) 0558 self.length = 1 0559 self.repr = "set([(0, 'zero')])" 0560 0561 def test_in(self): 0562 self.failUnless((0, "zero") in self.set) 0563 0564 def test_not_in(self): 0565 self.failUnless(9 not in self.set) 0566 0567 #------------------------------------------------------------------------------ 0568 0569 class TestBasicOpsTriple(TestBasicOps): 0570 def setUp(self): 0571 self.case = "triple set" 0572 self.values = [0, "zero", operator.add] 0573 self.set = set(self.values) 0574 self.dup = set(self.values) 0575 self.length = 3 0576 self.repr = None 0577 0578 #============================================================================== 0579 0580 def baditer(): 0581 raise TypeError 0582 yield True 0583 0584 def gooditer(): 0585 yield True 0586 0587 class TestExceptionPropagation(unittest.TestCase): 0588 """SF 628246: Set constructor should not trap iterator TypeErrors""" 0589 0590 def test_instanceWithException(self): 0591 self.assertRaises(TypeError, set, baditer()) 0592 0593 def test_instancesWithoutException(self): 0594 # All of these iterables should load without exception. 0595 set([1,2,3]) 0596 set((1,2,3)) 0597 set({'one':1, 'two':2, 'three':3}) 0598 set(xrange(3)) 0599 set('abc') 0600 set(gooditer()) 0601 0602 #============================================================================== 0603 0604 class TestSetOfSets(unittest.TestCase): 0605 def test_constructor(self): 0606 inner = frozenset([1]) 0607 outer = set([inner]) 0608 element = outer.pop() 0609 self.assertEqual(type(element), frozenset) 0610 outer.add(inner) # Rebuild set of sets with .add method 0611 outer.remove(inner) 0612 self.assertEqual(outer, set()) # Verify that remove worked 0613 outer.discard(inner) # Absence of KeyError indicates working fine 0614 0615 #============================================================================== 0616 0617 class TestBinaryOps(unittest.TestCase): 0618 def setUp(self): 0619 self.set = set((2, 4, 6)) 0620 0621 def test_eq(self): # SF bug 643115 0622 self.assertEqual(self.set, set({2:1,4:3,6:5})) 0623 0624 def test_union_subset(self): 0625 result = self.set | set([2]) 0626 self.assertEqual(result, set((2, 4, 6))) 0627 0628 def test_union_superset(self): 0629 result = self.set | set([2, 4, 6, 8]) 0630 self.assertEqual(result, set([2, 4, 6, 8])) 0631 0632 def test_union_overlap(self): 0633 result = self.set | set([3, 4, 5]) 0634 self.assertEqual(result, set([2, 3, 4, 5, 6])) 0635 0636 def test_union_non_overlap(self): 0637 result = self.set | set([8]) 0638 self.assertEqual(result, set([2, 4, 6, 8])) 0639 0640 def test_intersection_subset(self): 0641 result = self.set & set((2, 4)) 0642 self.assertEqual(result, set((2, 4))) 0643 0644 def test_intersection_superset(self): 0645 result = self.set & set([2, 4, 6, 8]) 0646 self.assertEqual(result, set([2, 4, 6])) 0647 0648 def test_intersection_overlap(self): 0649 result = self.set & set([3, 4, 5]) 0650 self.assertEqual(result, set([4])) 0651 0652 def test_intersection_non_overlap(self): 0653 result = self.set & set([8]) 0654 self.assertEqual(result, empty_set) 0655 0656 def test_sym_difference_subset(self): 0657 result = self.set ^ set((2, 4)) 0658 self.assertEqual(result, set([6])) 0659 0660 def test_sym_difference_superset(self): 0661 result = self.set ^ set((2, 4, 6, 8)) 0662 self.assertEqual(result, set([8])) 0663 0664 def test_sym_difference_overlap(self): 0665 result = self.set ^ set((3, 4, 5)) 0666 self.assertEqual(result, set([2, 3, 5, 6])) 0667 0668 def test_sym_difference_non_overlap(self): 0669 result = self.set ^ set([8]) 0670 self.assertEqual(result, set([2, 4, 6, 8])) 0671 0672 def test_cmp(self): 0673 a, b = set('a'), set('b') 0674 self.assertRaises(TypeError, cmp, a, b) 0675 0676 # You can view this as a buglet: cmp(a, a) does not raise TypeError, 0677 # because __eq__ is tried before __cmp__, and a.__eq__(a) returns True, 0678 # which Python thinks is good enough to synthesize a cmp() result 0679 # without calling __cmp__. 0680 self.assertEqual(cmp(a, a), 0) 0681 0682 self.assertRaises(TypeError, cmp, a, 12) 0683 self.assertRaises(TypeError, cmp, "abc", a) 0684 0685 #============================================================================== 0686 0687 class TestUpdateOps(unittest.TestCase): 0688 def setUp(self): 0689 self.set = set((2, 4, 6)) 0690 0691 def test_union_subset(self): 0692 self.set |= set([2]) 0693 self.assertEqual(self.set, set((2, 4, 6))) 0694 0695 def test_union_superset(self): 0696 self.set |= set([2, 4, 6, 8]) 0697 self.assertEqual(self.set, set([2, 4, 6, 8])) 0698 0699 def test_union_overlap(self): 0700 self.set |= set([3, 4, 5]) 0701 self.assertEqual(self.set, set([2, 3, 4, 5, 6])) 0702 0703 def test_union_non_overlap(self): 0704 self.set |= set([8]) 0705 self.assertEqual(self.set, set([2, 4, 6, 8])) 0706 0707 def test_union_method_call(self): 0708 self.set.update(set([3, 4, 5])) 0709 self.assertEqual(self.set, set([2, 3, 4, 5, 6])) 0710 0711 def test_intersection_subset(self): 0712 self.set &= set((2, 4)) 0713 self.assertEqual(self.set, set((2, 4))) 0714 0715 def test_intersection_superset(self): 0716 self.set &= set([2, 4, 6, 8]) 0717 self.assertEqual(self.set, set([2, 4, 6])) 0718 0719 def test_intersection_overlap(self): 0720 self.set &= set([3, 4, 5]) 0721 self.assertEqual(self.set, set([4])) 0722 0723 def test_intersection_non_overlap(self): 0724 self.set &= set([8]) 0725 self.assertEqual(self.set, empty_set) 0726 0727 def test_intersection_method_call(self): 0728 self.set.intersection_update(set([3, 4, 5])) 0729 self.assertEqual(self.set, set([4])) 0730 0731 def test_sym_difference_subset(self): 0732 self.set ^= set((2, 4)) 0733 self.assertEqual(self.set, set([6])) 0734 0735 def test_sym_difference_superset(self): 0736 self.set ^= set((2, 4, 6, 8)) 0737 self.assertEqual(self.set, set([8])) 0738 0739 def test_sym_difference_overlap(self): 0740 self.set ^= set((3, 4, 5)) 0741 self.assertEqual(self.set, set([2, 3, 5, 6])) 0742 0743 def test_sym_difference_non_overlap(self): 0744 self.set ^= set([8]) 0745 self.assertEqual(self.set, set([2, 4, 6, 8])) 0746 0747 def test_sym_difference_method_call(self): 0748 self.set.symmetric_difference_update(set([3, 4, 5])) 0749 self.assertEqual(self.set, set([2, 3, 5, 6])) 0750 0751 def test_difference_subset(self): 0752 self.set -= set((2, 4)) 0753 self.assertEqual(self.set, set([6])) 0754 0755 def test_difference_superset(self): 0756 self.set -= set((2, 4, 6, 8)) 0757 self.assertEqual(self.set, set([])) 0758 0759 def test_difference_overlap(self): 0760 self.set -= set((3, 4, 5)) 0761 self.assertEqual(self.set, set([2, 6])) 0762 0763 def test_difference_non_overlap(self): 0764 self.set -= set([8]) 0765 self.assertEqual(self.set, set([2, 4, 6])) 0766 0767 def test_difference_method_call(self): 0768 self.set.difference_update(set([3, 4, 5])) 0769 self.assertEqual(self.set, set([2, 6])) 0770 0771 #============================================================================== 0772 0773 class TestMutate(unittest.TestCase): 0774 def setUp(self): 0775 self.values = ["a", "b", "c"] 0776 self.set = set(self.values) 0777 0778 def test_add_present(self): 0779 self.set.add("c") 0780 self.assertEqual(self.set, set("abc")) 0781 0782 def test_add_absent(self): 0783 self.set.add("d") 0784 self.assertEqual(self.set, set("abcd")) 0785 0786 def test_add_until_full(self): 0787 tmp = set() 0788 expected_len = 0 0789 for v in self.values: 0790 tmp.add(v) 0791 expected_len += 1 0792 self.assertEqual(len(tmp), expected_len) 0793 self.assertEqual(tmp, self.set) 0794 0795 def test_remove_present(self): 0796 self.set.remove("b") 0797 self.assertEqual(self.set, set("ac")) 0798 0799 def test_remove_absent(self): 0800 try: 0801 self.set.remove("d") 0802 self.fail("Removing missing element should have raised LookupError") 0803 except LookupError: 0804 pass 0805 0806 def test_remove_until_empty(self): 0807 expected_len = len(self.set) 0808 for v in self.values: 0809 self.set.remove(v) 0810 expected_len -= 1 0811 self.assertEqual(len(self.set), expected_len) 0812 0813 def test_discard_present(self): 0814 self.set.discard("c") 0815 self.assertEqual(self.set, set("ab")) 0816 0817 def test_discard_absent(self): 0818 self.set.discard("d") 0819 self.assertEqual(self.set, set("abc")) 0820 0821 def test_clear(self): 0822 self.set.clear() 0823 self.assertEqual(len(self.set), 0) 0824 0825 def test_pop(self): 0826 popped = {} 0827 while self.set: 0828 popped[self.set.pop()] = None 0829 self.assertEqual(len(popped), len(self.values)) 0830 for v in self.values: 0831 self.failUnless(v in popped) 0832 0833 def test_update_empty_tuple(self): 0834 self.set.update(()) 0835 self.assertEqual(self.set, set(self.values)) 0836 0837 def test_update_unit_tuple_overlap(self): 0838 self.set.update(("a",)) 0839 self.assertEqual(self.set, set(self.values)) 0840 0841 def test_update_unit_tuple_non_overlap(self): 0842 self.set.update(("a", "z")) 0843 self.assertEqual(self.set, set(self.values + ["z"])) 0844 0845 #============================================================================== 0846 0847 class TestSubsets(unittest.TestCase): 0848 0849 case2method = {"<=": "issubset", 0850 ">=": "issuperset", 0851 } 0852 0853 reverse = {"==": "==", 0854 "!=": "!=", 0855 "<": ">", 0856 ">": "<", 0857 "<=": ">=", 0858 ">=": "<=", 0859 } 0860 0861 def test_issubset(self): 0862 x = self.left 0863 y = self.right 0864 for case in "!=", "==", "<", "<=", ">", ">=": 0865 expected = case in self.cases 0866 # Test the binary infix spelling. 0867 result = eval("x" + case + "y", locals()) 0868 self.assertEqual(result, expected) 0869 # Test the "friendly" method-name spelling, if one exists. 0870 if case in TestSubsets.case2method: 0871 method = getattr(x, TestSubsets.case2method[case]) 0872 result = method(y) 0873 self.assertEqual(result, expected) 0874 0875 # Now do the same for the operands reversed. 0876 rcase = TestSubsets.reverse[case] 0877 result = eval("y" + rcase + "x", locals()) 0878 self.assertEqual(result, expected) 0879 if rcase in TestSubsets.case2method: 0880 method = getattr(y, TestSubsets.case2method[rcase]) 0881 result = method(x) 0882 self.assertEqual(result, expected) 0883 #------------------------------------------------------------------------------ 0884 0885 class TestSubsetEqualEmpty(TestSubsets): 0886 left = set() 0887 right = set() 0888 name = "both empty" 0889 cases = "==", "<=", ">=" 0890 0891 #------------------------------------------------------------------------------ 0892 0893 class TestSubsetEqualNonEmpty(TestSubsets): 0894 left = set([1, 2]) 0895 right = set([1, 2]) 0896 name = "equal pair" 0897 cases = "==", "<=", ">=" 0898 0899 #------------------------------------------------------------------------------ 0900 0901 class TestSubsetEmptyNonEmpty(TestSubsets): 0902 left = set() 0903 right = set([1, 2]) 0904 name = "one empty, one non-empty" 0905 cases = "!=", "<", "<=" 0906 0907 #------------------------------------------------------------------------------ 0908 0909 class TestSubsetPartial(TestSubsets): 0910 left = set([1]) 0911 right = set([1, 2]) 0912 name = "one a non-empty proper subset of other" 0913 cases = "!=", "<", "<=" 0914 0915 #------------------------------------------------------------------------------ 0916 0917 class TestSubsetNonOverlap(TestSubsets): 0918 left = set([1]) 0919 right = set([2]) 0920 name = "neither empty, neither contains" 0921 cases = "!=" 0922 0923 #============================================================================== 0924 0925 class TestOnlySetsInBinaryOps(unittest.TestCase): 0926 0927 def test_eq_ne(self): 0928 # Unlike the others, this is testing that == and != *are* allowed. 0929 self.assertEqual(self.other == self.set, False) 0930 self.assertEqual(self.set == self.other, False) 0931 self.assertEqual(self.other != self.set, True) 0932 self.assertEqual(self.set != self.other, True) 0933 0934 def test_ge_gt_le_lt(self): 0935 self.assertRaises(TypeError, lambda: self.set < self.other) 0936 self.assertRaises(TypeError, lambda: self.set <= self.other) 0937 self.assertRaises(TypeError, lambda: self.set > self.other) 0938 self.assertRaises(TypeError, lambda: self.set >= self.other) 0939 0940 self.assertRaises(TypeError, lambda: self.other < self.set) 0941 self.assertRaises(TypeError, lambda: self.other <= self.set) 0942 self.assertRaises(TypeError, lambda: self.other > self.set) 0943 self.assertRaises(TypeError, lambda: self.other >= self.set) 0944 0945 def test_update_operator(self): 0946 try: 0947 self.set |= self.other 0948 except TypeError: 0949 pass 0950 else: 0951 self.fail("expected TypeError") 0952 0953 def test_update(self): 0954 if self.otherIsIterable: 0955 self.set.update(self.other) 0956 else: 0957 self.assertRaises(TypeError, self.set.update, self.other) 0958 0959 def test_union(self): 0960 self.assertRaises(TypeError, lambda: self.set | self.other) 0961 self.assertRaises(TypeError, lambda: self.other | self.set) 0962 if self.otherIsIterable: 0963 self.set.union(self.other) 0964 else: 0965 self.assertRaises(TypeError, self.set.union, self.other) 0966 0967 def test_intersection_update_operator(self): 0968 try: 0969 self.set &= self.other 0970 except TypeError: 0971 pass 0972 else: 0973 self.fail("expected TypeError") 0974 0975 def test_intersection_update(self): 0976 if self.otherIsIterable: 0977 self.set.intersection_update(self.other) 0978 else: 0979 self.assertRaises(TypeError, 0980 self.set.intersection_update, 0981 self.other) 0982 0983 def test_intersection(self): 0984 self.assertRaises(TypeError, lambda: self.set & self.other) 0985 self.assertRaises(TypeError, lambda: self.other & self.set) 0986 if self.otherIsIterable: 0987 self.set.intersection(self.other) 0988 else: 0989 self.assertRaises(TypeError, self.set.intersection, self.other) 0990 0991 def test_sym_difference_update_operator(self): 0992 try: 0993 self.set ^= self.other 0994 except TypeError: 0995 pass 0996 else: 0997 self.fail("expected TypeError") 0998 0999 def test_sym_difference_update(self): 1000 if self.otherIsIterable: 1001 self.set.symmetric_difference_update(self.other) 1002 else: 1003 self.assertRaises(TypeError, 1004 self.set.symmetric_difference_update, 1005 self.other) 1006 1007 def test_sym_difference(self): 1008 self.assertRaises(TypeError, lambda: self.set ^ self.other) 1009 self.assertRaises(TypeError, lambda: self.other ^ self.set) 1010 if self.otherIsIterable: 1011 self.set.symmetric_difference(self.other) 1012 else: 1013 self.assertRaises(TypeError, self.set.symmetric_difference, self.other) 1014 1015 def test_difference_update_operator(self): 1016 try: 1017 self.set -= self.other 1018 except TypeError: 1019 pass 1020 else: 1021 self.fail("expected TypeError") 1022 1023 def test_difference_update(self): 1024 if self.otherIsIterable: 1025 self.set.difference_update(self.other) 1026 else: 1027 self.assertRaises(TypeError, 1028 self.set.difference_update, 1029 self.other) 1030 1031 def test_difference(self): 1032 self.assertRaises(TypeError, lambda: self.set - self.other) 1033 self.assertRaises(TypeError, lambda: self.other - self.set) 1034 if self.otherIsIterable: 1035 self.set.difference(self.other) 1036 else: 1037 self.assertRaises(TypeError, self.set.difference, self.other) 1038 1039 #------------------------------------------------------------------------------ 1040 1041 class TestOnlySetsNumeric(TestOnlySetsInBinaryOps): 1042 def setUp(self): 1043 self.set = set((1, 2, 3)) 1044 self.other = 19 1045 self.otherIsIterable = False 1046 1047 #------------------------------------------------------------------------------ 1048 1049 class TestOnlySetsDict(TestOnlySetsInBinaryOps): 1050 def setUp(self): 1051 self.set = set((1, 2, 3)) 1052 self.other = {1:2, 3:4} 1053 self.otherIsIterable = True 1054 1055 #------------------------------------------------------------------------------ 1056 1057 class TestOnlySetsOperator(TestOnlySetsInBinaryOps): 1058 def setUp(self): 1059 self.set = set((1, 2, 3)) 1060 self.other = operator.add 1061 self.otherIsIterable = False 1062 1063 #------------------------------------------------------------------------------ 1064 1065 class TestOnlySetsTuple(TestOnlySetsInBinaryOps): 1066 def setUp(self): 1067 self.set = set((1, 2, 3)) 1068 self.other = (2, 4, 6) 1069 self.otherIsIterable = True 1070 1071 #------------------------------------------------------------------------------ 1072 1073 class TestOnlySetsString(TestOnlySetsInBinaryOps): 1074 def setUp(self): 1075 self.set = set((1, 2, 3)) 1076 self.other = 'abc' 1077 self.otherIsIterable = True 1078 1079 #------------------------------------------------------------------------------ 1080 1081 class TestOnlySetsGenerator(TestOnlySetsInBinaryOps): 1082 def setUp(self): 1083 def gen(): 1084 for i in xrange(0, 10, 2): 1085 yield i 1086 self.set = set((1, 2, 3)) 1087 self.other = gen() 1088 self.otherIsIterable = True 1089 1090 #============================================================================== 1091 1092 class TestCopying(unittest.TestCase): 1093 1094 def test_copy(self): 1095 dup = self.set.copy() 1096 dup_list = list(dup); dup_list.sort() 1097 set_list = list(self.set); set_list.sort() 1098 self.assertEqual(len(dup_list), len(set_list)) 1099 for i in range(len(dup_list)): 1100 self.failUnless(dup_list[i] is set_list[i]) 1101 1102 def test_deep_copy(self): 1103 dup = copy.deepcopy(self.set) 1104 ##print type(dup), repr(dup) 1105 dup_list = list(dup); dup_list.sort() 1106 set_list = list(self.set); set_list.sort() 1107 self.assertEqual(len(dup_list), len(set_list)) 1108 for i in range(len(dup_list)): 1109 self.assertEqual(dup_list[i], set_list[i]) 1110 1111 #------------------------------------------------------------------------------ 1112 1113 class TestCopyingEmpty(TestCopying): 1114 def setUp(self): 1115 self.set = set() 1116 1117 #------------------------------------------------------------------------------ 1118 1119 class TestCopyingSingleton(TestCopying): 1120 def setUp(self): 1121 self.set = set(["hello"]) 1122 1123 #------------------------------------------------------------------------------ 1124 1125 class TestCopyingTriple(TestCopying): 1126 def setUp(self): 1127 self.set = set(["zero", 0, None]) 1128 1129 #------------------------------------------------------------------------------ 1130 1131 class TestCopyingTuple(TestCopying): 1132 def setUp(self): 1133 self.set = set([(1, 2)]) 1134 1135 #------------------------------------------------------------------------------ 1136 1137 class TestCopyingNested(TestCopying): 1138 def setUp(self): 1139 self.set = set([((1, 2), (3, 4))]) 1140 1141 #============================================================================== 1142 1143 class TestIdentities(unittest.TestCase): 1144 def setUp(self): 1145 self.a = set('abracadabra') 1146 self.b = set('alacazam') 1147 1148 def test_binopsVsSubsets(self): 1149 a, b = self.a, self.b 1150 self.assert_(a - b < a) 1151 self.assert_(b - a < b) 1152 self.assert_(a & b < a) 1153 self.assert_(a & b < b) 1154 self.assert_(a | b > a) 1155 self.assert_(a | b > b) 1156 self.assert_(a ^ b < a | b) 1157 1158 def test_commutativity(self): 1159 a, b = self.a, self.b 1160 self.assertEqual(a&b, b&a) 1161 self.assertEqual(a|b, b|a) 1162 self.assertEqual(a^b, b^a) 1163 if a != b: 1164 self.assertNotEqual(a-b, b-a) 1165 1166 def test_summations(self): 1167 # check that sums of parts equal the whole 1168 a, b = self.a, self.b 1169 self.assertEqual((a-b)|(a&b)|(b-a), a|b) 1170 self.assertEqual((a&b)|(a^b), a|b) 1171 self.assertEqual(a|(b-a), a|b) 1172 self.assertEqual((a-b)|b, a|b) 1173 self.assertEqual((a-b)|(a&b), a) 1174 self.assertEqual((b-a)|(a&b), b) 1175 self.assertEqual((a-b)|(b-a), a^b) 1176 1177 def test_exclusion(self): 1178 # check that inverse operations show non-overlap 1179 a, b, zero = self.a, self.b, set() 1180 self.assertEqual((a-b)&b, zero) 1181 self.assertEqual((b-a)&a, zero) 1182 self.assertEqual((a&b)&(a^b), zero) 1183 1184 # Tests derived from test_itertools.py ======================================= 1185 1186 def R(seqn): 1187 'Regular generator' 1188 for i in seqn: 1189 yield i 1190 1191 class G: 1192 'Sequence using __getitem__' 1193 def __init__(self, seqn): 1194 self.seqn = seqn 1195 def __getitem__(self, i): 1196 return self.seqn[i] 1197 1198 class I: 1199 'Sequence using iterator protocol' 1200 def __init__(self, seqn): 1201 self.seqn = seqn 1202 self.i = 0 1203 def __iter__(self): 1204 return self 1205 def next(self): 1206 if self.i >= len(self.seqn): raise StopIteration 1207 v = self.seqn[self.i] 1208 self.i += 1 1209 return v 1210 1211 class Ig: 1212 'Sequence using iterator protocol defined with a generator' 1213 def __init__(self, seqn): 1214 self.seqn = seqn 1215 self.i = 0 1216 def __iter__(self): 1217 for val in self.seqn: 1218 yield val 1219 1220 class X: 1221 'Missing __getitem__ and __iter__' 1222 def __init__(self, seqn): 1223 self.seqn = seqn 1224 self.i = 0 1225 def next(self): 1226 if self.i >= len(self.seqn): raise StopIteration 1227 v = self.seqn[self.i] 1228 self.i += 1 1229 return v 1230 1231 class N: 1232 'Iterator missing next()' 1233 def __init__(self, seqn): 1234 self.seqn = seqn 1235 self.i = 0 1236 def __iter__(self): 1237 return self 1238 1239 class E: 1240 'Test propagation of exceptions' 1241 def __init__(self, seqn): 1242 self.seqn = seqn 1243 self.i = 0 1244 def __iter__(self): 1245 return self 1246 def next(self): 1247 3 // 0 1248 1249 class S: 1250 'Test immediate stop' 1251 def __init__(self, seqn): 1252 pass 1253 def __iter__(self): 1254 return self 1255 def next(self): 1256 raise StopIteration 1257 1258 from itertools import chain, imap 1259 def L(seqn): 1260 'Test multiple tiers of iterators' 1261 return chain(imap(lambda x:x, R(Ig(G(seqn))))) 1262 1263 class TestVariousIteratorArgs(unittest.TestCase): 1264 1265 def test_constructor(self): 1266 for cons in (set, frozenset): 1267 for s in ("123", "", range(1000), ('do', 1.2), xrange(2000,2200,5)): 1268 for g in (G, I, Ig, S, L, R): 1269 self.assertEqual(sorted(cons(g(s))), sorted(g(s))) 1270 self.assertRaises(TypeError, cons , X(s)) 1271 self.assertRaises(TypeError, cons , N(s)) 1272 self.assertRaises(ZeroDivisionError, cons , E(s)) 1273 1274 def test_inline_methods(self): 1275 s = set('november') 1276 for data in ("123", "", range(1000), ('do', 1.2), xrange(2000,2200,5), 'december'): 1277 for meth in (s.union, s.intersection, s.difference, s.symmetric_difference): 1278 for g in (G, I, Ig, L, R): 1279 expected = meth(data) 1280 actual = meth(G(data)) 1281 self.assertEqual(sorted(actual), sorted(expected)) 1282 self.assertRaises(TypeError, meth, X(s)) 1283 self.assertRaises(TypeError, meth, N(s)) 1284 self.assertRaises(ZeroDivisionError, meth, E(s)) 1285 1286 def test_inplace_methods(self): 1287 for data in ("123", "", range(1000), ('do', 1.2), xrange(2000,2200,5), 'december'): 1288 for methname in ('update', 'intersection_update', 1289 'difference_update', 'symmetric_difference_update'): 1290 for g in (G, I, Ig, S, L, R): 1291 s = set('january') 1292 t = s.copy() 1293 getattr(s, methname)(list(g(data))) 1294 getattr(t, methname)(g(data)) 1295 self.assertEqual(sorted(s), sorted(t)) 1296 1297 self.assertRaises(TypeError, getattr(set('january'), methname), X(data)) 1298 self.assertRaises(TypeError, getattr(set('january'), methname), N(data)) 1299 self.assertRaises(ZeroDivisionError, getattr(set('january'), methname), E(data)) 1300 1301 #============================================================================== 1302 1303 def test_main(verbose=None): 1304 import sys 1305 from test import test_sets 1306 test_classes = ( 1307 TestSet, 1308 TestSetSubclass, 1309 TestFrozenSet, 1310 TestFrozenSetSubclass, 1311 TestSetOfSets, 1312 TestExceptionPropagation, 1313 TestBasicOpsEmpty, 1314 TestBasicOpsSingleton, 1315 TestBasicOpsTuple, 1316 TestBasicOpsTriple, 1317 TestBinaryOps, 1318 TestUpdateOps, 1319 TestMutate, 1320 TestSubsetEqualEmpty, 1321 TestSubsetEqualNonEmpty, 1322 TestSubsetEmptyNonEmpty, 1323 TestSubsetPartial, 1324 TestSubsetNonOverlap, 1325 TestOnlySetsNumeric, 1326 TestOnlySetsDict, 1327 TestOnlySetsOperator, 1328 TestOnlySetsTuple, 1329 TestOnlySetsString, 1330 TestOnlySetsGenerator, 1331 TestCopyingEmpty, 1332 TestCopyingSingleton, 1333 TestCopyingTriple, 1334 TestCopyingTuple, 1335 TestCopyingNested, 1336 TestIdentities, 1337 TestVariousIteratorArgs, 1338 ) 1339 1340 test_support.run_unittest(*test_classes) 1341 1342 # verify reference counting 1343 if verbose and hasattr(sys, "gettotalrefcount"): 1344 import gc 1345 counts = [None] * 5 1346 for i in xrange(len(counts)): 1347 test_support.run_unittest(*test_classes) 1348 gc.collect() 1349 counts[i] = sys.gettotalrefcount() 1350 print counts 1351 1352 if __name__ == "__main__": 1353 test_main(verbose=True) 1354
Generated by PyXR 0.9.4