• Home
  • Raw
  • Download

Lines Matching refs:self

21     def __hash__(self):  argument
23 def __cmp__(self, other): argument
28 def __repr__(self): argument
29 return repr(self.value)
33 def __init__(self, *args): argument
34 self.hash_count = 0
35 def __hash__(self): argument
36 self.hash_count += 1
37 return int.__hash__(self)
42 def setUp(self): argument
43 self.word = word = 'simsalabim'
44 self.otherword = 'madagascar'
45 self.letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
46 self.s = self.thetype(word)
47 self.d = dict.fromkeys(word)
49 def test_new_or_init(self): argument
50 self.assertRaises(TypeError, self.thetype, [], 2)
51 self.assertRaises(TypeError, set().__init__, a=1)
53 def test_uniquification(self): argument
54 actual = sorted(self.s)
55 expected = sorted(self.d)
56 self.assertEqual(actual, expected)
57 self.assertRaises(PassThru, self.thetype, check_pass_thru())
58 self.assertRaises(TypeError, self.thetype, [[]])
60 def test_len(self): argument
61 self.assertEqual(len(self.s), len(self.d))
63 def test_contains(self): argument
64 for c in self.letters:
65 self.assertEqual(c in self.s, c in self.d)
66 self.assertRaises(TypeError, self.s.__contains__, [[]])
67 s = self.thetype([frozenset(self.letters)])
68 self.assertIn(self.thetype(self.letters), s)
70 def test_union(self): argument
71 u = self.s.union(self.otherword)
72 for c in self.letters:
73 self.assertEqual(c in u, c in self.d or c in self.otherword)
74 self.assertEqual(self.s, self.thetype(self.word))
75 self.assertEqual(type(u), self.thetype)
76 self.assertRaises(PassThru, self.s.union, check_pass_thru())
77 self.assertRaises(TypeError, self.s.union, [[]])
79 self.assertEqual(self.thetype('abcba').union(C('cdc')), set('abcd'))
80 self.assertEqual(self.thetype('abcba').union(C('efgfe')), set('abcefg'))
81 self.assertEqual(self.thetype('abcba').union(C('ccb')), set('abc'))
82 self.assertEqual(self.thetype('abcba').union(C('ef')), set('abcef'))
83 self.assertEqual(self.thetype('abcba').union(C('ef'), C('fg')), set('abcefg'))
86 x = self.thetype()
87 self.assertEqual(x.union(set([1]), x, set([2])), self.thetype([1, 2]))
89 def test_or(self): argument
90 i = self.s.union(self.otherword)
91 self.assertEqual(self.s | set(self.otherword), i)
92 self.assertEqual(self.s | frozenset(self.otherword), i)
94 self.s | self.otherword
98 self.fail("s|t did not screen-out general iterables")
100 def test_intersection(self): argument
101 i = self.s.intersection(self.otherword)
102 for c in self.letters:
103 self.assertEqual(c in i, c in self.d and c in self.otherword)
104 self.assertEqual(self.s, self.thetype(self.word))
105 self.assertEqual(type(i), self.thetype)
106 self.assertRaises(PassThru, self.s.intersection, check_pass_thru())
108 self.assertEqual(self.thetype('abcba').intersection(C('cdc')), set('cc'))
109 self.assertEqual(self.thetype('abcba').intersection(C('efgfe')), set(''))
110 self.assertEqual(self.thetype('abcba').intersection(C('ccb')), set('bc'))
111 self.assertEqual(self.thetype('abcba').intersection(C('ef')), set(''))
112 self.assertEqual(self.thetype('abcba').intersection(C('cbcf'), C('bag')), set('b'))
113 s = self.thetype('abcba')
115 if self.thetype == frozenset():
116 self.assertEqual(id(s), id(z))
118 self.assertNotEqual(id(s), id(z))
120 def test_isdisjoint(self): argument
125 s1 = self.thetype(larg)
131 self.assertEqual(actual, expected)
132 self.assertTrue(actual is True or actual is False)
134 def test_and(self): argument
135 i = self.s.intersection(self.otherword)
136 self.assertEqual(self.s & set(self.otherword), i)
137 self.assertEqual(self.s & frozenset(self.otherword), i)
139 self.s & self.otherword
143 self.fail("s&t did not screen-out general iterables")
145 def test_difference(self): argument
146 i = self.s.difference(self.otherword)
147 for c in self.letters:
148 self.assertEqual(c in i, c in self.d and c not in self.otherword)
149 self.assertEqual(self.s, self.thetype(self.word))
150 self.assertEqual(type(i), self.thetype)
151 self.assertRaises(PassThru, self.s.difference, check_pass_thru())
152 self.assertRaises(TypeError, self.s.difference, [[]])
154 self.assertEqual(self.thetype('abcba').difference(C('cdc')), set('ab'))
155 self.assertEqual(self.thetype('abcba').difference(C('efgfe')), set('abc'))
156 self.assertEqual(self.thetype('abcba').difference(C('ccb')), set('a'))
157 self.assertEqual(self.thetype('abcba').difference(C('ef')), set('abc'))
158 self.assertEqual(self.thetype('abcba').difference(), set('abc'))
159 self.assertEqual(self.thetype('abcba').difference(C('a'), C('b')), set('c'))
161 def test_sub(self): argument
162 i = self.s.difference(self.otherword)
163 self.assertEqual(self.s - set(self.otherword), i)
164 self.assertEqual(self.s - frozenset(self.otherword), i)
166 self.s - self.otherword
170 self.fail("s-t did not screen-out general iterables")
172 def test_symmetric_difference(self): argument
173 i = self.s.symmetric_difference(self.otherword)
174 for c in self.letters:
175 self.assertEqual(c in i, (c in self.d) ^ (c in self.otherword))
176 self.assertEqual(self.s, self.thetype(self.word))
177 self.assertEqual(type(i), self.thetype)
178 self.assertRaises(PassThru, self.s.symmetric_difference, check_pass_thru())
179 self.assertRaises(TypeError, self.s.symmetric_difference, [[]])
181 self.assertEqual(self.thetype('abcba').symmetric_difference(C('cdc')), set('abd'))
182 self.assertEqual(self.thetype('abcba').symmetric_difference(C('efgfe')), set('abcefg'))
183 self.assertEqual(self.thetype('abcba').symmetric_difference(C('ccb')), set('a'))
184 self.assertEqual(self.thetype('abcba').symmetric_difference(C('ef')), set('abcef'))
186 def test_xor(self): argument
187 i = self.s.symmetric_difference(self.otherword)
188 self.assertEqual(self.s ^ set(self.otherword), i)
189 self.assertEqual(self.s ^ frozenset(self.otherword), i)
191 self.s ^ self.otherword
195 self.fail("s^t did not screen-out general iterables")
197 def test_equality(self): argument
198 self.assertEqual(self.s, set(self.word))
199 self.assertEqual(self.s, frozenset(self.word))
200 self.assertEqual(self.s == self.word, False)
201 self.assertNotEqual(self.s, set(self.otherword))
202 self.assertNotEqual(self.s, frozenset(self.otherword))
203 self.assertEqual(self.s != self.word, True)
205 def test_setOfFrozensets(self): argument
207 s = self.thetype(t)
208 self.assertEqual(len(s), 3)
210 def test_compare(self): argument
211 self.assertRaises(TypeError, self.s.__cmp__, self.s)
213 def test_sub_and_super(self): argument
214 p, q, r = map(self.thetype, ['ab', 'abcde', 'def'])
215 self.assertTrue(p < q)
216 self.assertTrue(p <= q)
217 self.assertTrue(q <= q)
218 self.assertTrue(q > p)
219 self.assertTrue(q >= p)
220 self.assertFalse(q < r)
221 self.assertFalse(q <= r)
222 self.assertFalse(q > r)
223 self.assertFalse(q >= r)
224 self.assertTrue(set('a').issubset('abc'))
225 self.assertTrue(set('abc').issuperset('a'))
226 self.assertFalse(set('a').issubset('cbs'))
227 self.assertFalse(set('cbs').issuperset('a'))
229 def test_pickling(self): argument
231 p = pickle.dumps(self.s, i)
233 self.assertEqual(self.s, dup, "%s != %s" % (self.s, dup))
234 if type(self.s) not in (set, frozenset):
235 self.s.x = 10
236 p = pickle.dumps(self.s, i)
238 self.assertEqual(self.s.x, dup.x)
240 def test_deepcopy(self): argument
242 def __init__(self, value): argument
243 self.value = value
244 def __hash__(self): argument
245 return self.value
246 def __deepcopy__(self, memo=None): argument
247 return Tracer(self.value + 1)
249 s = self.thetype([t])
251 self.assertNotEqual(id(s), id(dup))
254 self.assertNotEqual(id(t), id(newt))
255 self.assertEqual(t.value + 1, newt.value)
257 def test_gc(self): argument
267 def test_subclass_with_custom_hash(self): argument
269 class H(self.thetype):
270 def __hash__(self): argument
271 return int(id(self) & 0x7fffffff)
275 self.assertIn(s, f)
280 def test_badcmp(self): argument
281 s = self.thetype([BadCmp()])
283 self.assertRaises(RuntimeError, self.thetype, [BadCmp(), BadCmp()])
284 self.assertRaises(RuntimeError, s.__contains__, BadCmp())
287 self.assertRaises(RuntimeError, s.add, BadCmp())
288 self.assertRaises(RuntimeError, s.discard, BadCmp())
289 self.assertRaises(RuntimeError, s.remove, BadCmp())
291 def test_cyclical_repr(self): argument
293 s = self.thetype([w])
296 self.assertEqual(repr(s), '%s([%s(...)])' % (name, name))
298 def test_cyclical_print(self): argument
300 s = self.thetype([w])
307 self.assertEqual(fo.read(), repr(s))
312 def test_do_not_rehash_dict_keys(self): argument
315 self.assertEqual(sum(elem.hash_count for elem in d), n)
316 s = self.thetype(d)
317 self.assertEqual(sum(elem.hash_count for elem in d), n)
319 self.assertEqual(sum(elem.hash_count for elem in d), n)
322 self.assertEqual(sum(elem.hash_count for elem in d), n)
324 self.assertEqual(sum(elem.hash_count for elem in d), n)
326 self.assertEqual(sum(elem.hash_count for elem in d), n)
328 self.assertEqual(sum(elem.hash_count for elem in d), n)
329 self.assertEqual(d3, dict.fromkeys(d, 123))
331 def test_container_iterator(self): argument
341 self.assertTrue(ref() is None, "Cycle was not collected")
343 def test_free_after_iterating(self): argument
344 test_support.check_free_after_iterating(self, iter, self.thetype)
349 def test_init(self): argument
350 s = self.thetype()
351 s.__init__(self.word)
352 self.assertEqual(s, set(self.word))
353 s.__init__(self.otherword)
354 self.assertEqual(s, set(self.otherword))
355 self.assertRaises(TypeError, s.__init__, s, 2);
356 self.assertRaises(TypeError, s.__init__, 1);
358 def test_constructor_identity(self): argument
359 s = self.thetype(range(3))
360 t = self.thetype(s)
361 self.assertNotEqual(id(s), id(t))
363 def test_set_literal_insertion_order(self): argument
366 self.assertEqual(len(s), 1)
368 self.assertEqual(type(stored_value), int)
370 def test_set_literal_evaluation_order(self): argument
376 self.assertEqual(events, [1, 2, 3])
378 def test_hash(self): argument
379 self.assertRaises(TypeError, hash, self.s)
381 def test_clear(self): argument
382 self.s.clear()
383 self.assertEqual(self.s, set())
384 self.assertEqual(len(self.s), 0)
386 def test_copy(self): argument
387 dup = self.s.copy()
388 self.assertEqual(self.s, dup)
389 self.assertNotEqual(id(self.s), id(dup))
391 def test_add(self): argument
392 self.s.add('Q')
393 self.assertIn('Q', self.s)
394 dup = self.s.copy()
395 self.s.add('Q')
396 self.assertEqual(self.s, dup)
397 self.assertRaises(TypeError, self.s.add, [])
399 def test_remove(self): argument
400 self.s.remove('a')
401 self.assertNotIn('a', self.s)
402 self.assertRaises(KeyError, self.s.remove, 'Q')
403 self.assertRaises(TypeError, self.s.remove, [])
404 s = self.thetype([frozenset(self.word)])
405 self.assertIn(self.thetype(self.word), s)
406 s.remove(self.thetype(self.word))
407 self.assertNotIn(self.thetype(self.word), s)
408 self.assertRaises(KeyError, self.s.remove, self.thetype(self.word))
410 def test_remove_keyerror_unpacking(self): argument
414 self.s.remove(v1)
417 self.assertEqual(v1, v2)
419 self.fail()
421 def test_remove_keyerror_set(self): argument
422 key = self.thetype([3, 4])
424 self.s.remove(key)
426 self.assertTrue(e.args[0] is key,
430 self.fail()
432 def test_discard(self): argument
433 self.s.discard('a')
434 self.assertNotIn('a', self.s)
435 self.s.discard('Q')
436 self.assertRaises(TypeError, self.s.discard, [])
437 s = self.thetype([frozenset(self.word)])
438 self.assertIn(self.thetype(self.word), s)
439 s.discard(self.thetype(self.word))
440 self.assertNotIn(self.thetype(self.word), s)
441 s.discard(self.thetype(self.word))
443 def test_pop(self): argument
444 for i in xrange(len(self.s)):
445 elem = self.s.pop()
446 self.assertNotIn(elem, self.s)
447 self.assertRaises(KeyError, self.s.pop)
449 def test_update(self): argument
450 retval = self.s.update(self.otherword)
451 self.assertEqual(retval, None)
452 for c in (self.word + self.otherword):
453 self.assertIn(c, self.s)
454 self.assertRaises(PassThru, self.s.update, check_pass_thru())
455 self.assertRaises(TypeError, self.s.update, [[]])
458 s = self.thetype('abcba')
459 self.assertEqual(s.update(C(p)), None)
460 self.assertEqual(s, set(q))
464 s = self.thetype('abcba')
465 self.assertEqual(s.update(C(p), C(q)), None)
466 self.assertEqual(s, set(s) | set(p) | set(q))
468 def test_ior(self): argument
469 self.s |= set(self.otherword)
470 for c in (self.word + self.otherword):
471 self.assertIn(c, self.s)
473 def test_intersection_update(self): argument
474 retval = self.s.intersection_update(self.otherword)
475 self.assertEqual(retval, None)
476 for c in (self.word + self.otherword):
477 if c in self.otherword and c in self.word:
478 self.assertIn(c, self.s)
480 self.assertNotIn(c, self.s)
481 self.assertRaises(PassThru, self.s.intersection_update, check_pass_thru())
482 self.assertRaises(TypeError, self.s.intersection_update, [[]])
485 s = self.thetype('abcba')
486 self.assertEqual(s.intersection_update(C(p)), None)
487 self.assertEqual(s, set(q))
489 s = self.thetype(ss)
491 self.assertEqual(s.intersection_update(C(p), C(t)), None)
492 self.assertEqual(s, set('abcba')&set(p)&set(t))
494 def test_iand(self): argument
495 self.s &= set(self.otherword)
496 for c in (self.word + self.otherword):
497 if c in self.otherword and c in self.word:
498 self.assertIn(c, self.s)
500 self.assertNotIn(c, self.s)
502 def test_difference_update(self): argument
503 retval = self.s.difference_update(self.otherword)
504 self.assertEqual(retval, None)
505 for c in (self.word + self.otherword):
506 if c in self.word and c not in self.otherword:
507 self.assertIn(c, self.s)
509 self.assertNotIn(c, self.s)
510 self.assertRaises(PassThru, self.s.difference_update, check_pass_thru())
511 self.assertRaises(TypeError, self.s.difference_update, [[]])
512 self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]])
515 s = self.thetype('abcba')
516 self.assertEqual(s.difference_update(C(p)), None)
517 self.assertEqual(s, set(q))
519 s = self.thetype('abcdefghih')
521 self.assertEqual(s, self.thetype('abcdefghih'))
523 s = self.thetype('abcdefghih')
525 self.assertEqual(s, self.thetype('cdefghih'))
527 s = self.thetype('abcdefghih')
529 self.assertEqual(s, self.thetype('efghih'))
531 def test_isub(self): argument
532 self.s -= set(self.otherword)
533 for c in (self.word + self.otherword):
534 if c in self.word and c not in self.otherword:
535 self.assertIn(c, self.s)
537 self.assertNotIn(c, self.s)
539 def test_symmetric_difference_update(self): argument
540 retval = self.s.symmetric_difference_update(self.otherword)
541 self.assertEqual(retval, None)
542 for c in (self.word + self.otherword):
543 if (c in self.word) ^ (c in self.otherword):
544 self.assertIn(c, self.s)
546 self.assertNotIn(c, self.s)
547 self.assertRaises(PassThru, self.s.symmetric_difference_update, check_pass_thru())
548 self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]])
551 s = self.thetype('abcba')
552 self.assertEqual(s.symmetric_difference_update(C(p)), None)
553 self.assertEqual(s, set(q))
555 def test_ixor(self): argument
556 self.s ^= set(self.otherword)
557 for c in (self.word + self.otherword):
558 if (c in self.word) ^ (c in self.otherword):
559 self.assertIn(c, self.s)
561 self.assertNotIn(c, self.s)
563 def test_inplace_on_self(self): argument
564 t = self.s.copy()
566 self.assertEqual(t, self.s)
568 self.assertEqual(t, self.s)
570 self.assertEqual(t, self.thetype())
571 t = self.s.copy()
573 self.assertEqual(t, self.thetype())
575 def test_weakref(self): argument
576 s = self.thetype('gallahad')
578 self.assertEqual(str(p), str(s))
580 self.assertRaises(ReferenceError, str, p)
584 def test_c_api(self): argument
585 self.assertEqual(set().test_c_api(), True)
594 def __init__(self, iterable=[], newarg=None): argument
595 set.__init__(self, iterable)
599 def test_keywords_in_subclass(self): argument
606 def test_init(self): argument
607 s = self.thetype(self.word)
608 s.__init__(self.otherword)
609 self.assertEqual(s, set(self.word))
611 def test_singleton_empty_frozenset(self): argument
618 self.assertEqual(len(set(map(id, efs))), 1)
620 def test_constructor_identity(self): argument
621 s = self.thetype(range(3))
622 t = self.thetype(s)
623 self.assertEqual(id(s), id(t))
625 def test_hash(self): argument
626 self.assertEqual(hash(self.thetype('abcdeb')),
627 hash(self.thetype('ebecda')))
635 results.add(hash(self.thetype(seq)))
636 self.assertEqual(len(results), 1)
638 def test_copy(self): argument
639 dup = self.s.copy()
640 self.assertEqual(id(self.s), id(dup))
642 def test_frozen_as_dictkey(self): argument
644 key1 = self.thetype(seq)
645 key2 = self.thetype(reversed(seq))
646 self.assertEqual(key1, key2)
647 self.assertNotEqual(id(key1), id(key2))
650 self.assertEqual(d[key2], 42)
652 def test_hash_caching(self): argument
653 f = self.thetype('abcdcda')
654 self.assertEqual(hash(f), hash(f))
656 def test_hash_effectiveness(self): argument
663 self.assertEqual(len(hashvalues), 2**n)
671 def test_constructor_identity(self): argument
672 s = self.thetype(range(3))
673 t = self.thetype(s)
674 self.assertNotEqual(id(s), id(t))
676 def test_copy(self): argument
677 dup = self.s.copy()
678 self.assertNotEqual(id(self.s), id(dup))
680 def test_nested_empty_constructor(self): argument
681 s = self.thetype()
682 t = self.thetype(s)
683 self.assertEqual(s, t)
685 def test_singleton_empty_frozenset(self): argument
686 Frozenset = self.thetype
694 self.assertEqual(len(set(map(id, efs))), len(efs))
704 def test_repr(self): argument
705 if self.repr is not None:
706 self.assertEqual(repr(self.set), self.repr)
708 def check_repr_against_values(self): argument
709 text = repr(self.set)
710 self.assertTrue(text.startswith('{'))
711 self.assertTrue(text.endswith('}'))
715 sorted_repr_values = [repr(value) for value in self.values]
717 self.assertEqual(result, sorted_repr_values)
719 def test_print(self): argument
722 print >> fo, self.set,
725 self.assertEqual(fo.read(), repr(self.set))
730 def test_length(self): argument
731 self.assertEqual(len(self.set), self.length)
733 def test_self_equality(self): argument
734 self.assertEqual(self.set, self.set)
736 def test_equivalent_equality(self): argument
737 self.assertEqual(self.set, self.dup)
739 def test_copy(self): argument
740 self.assertEqual(self.set.copy(), self.dup)
742 def test_self_union(self): argument
743 result = self.set | self.set
744 self.assertEqual(result, self.dup)
746 def test_empty_union(self): argument
747 result = self.set | empty_set
748 self.assertEqual(result, self.dup)
750 def test_union_empty(self): argument
751 result = empty_set | self.set
752 self.assertEqual(result, self.dup)
754 def test_self_intersection(self): argument
755 result = self.set & self.set
756 self.assertEqual(result, self.dup)
758 def test_empty_intersection(self): argument
759 result = self.set & empty_set
760 self.assertEqual(result, empty_set)
762 def test_intersection_empty(self): argument
763 result = empty_set & self.set
764 self.assertEqual(result, empty_set)
766 def test_self_isdisjoint(self): argument
767 result = self.set.isdisjoint(self.set)
768 self.assertEqual(result, not self.set)
770 def test_empty_isdisjoint(self): argument
771 result = self.set.isdisjoint(empty_set)
772 self.assertEqual(result, True)
774 def test_isdisjoint_empty(self): argument
775 result = empty_set.isdisjoint(self.set)
776 self.assertEqual(result, True)
778 def test_self_symmetric_difference(self): argument
779 result = self.set ^ self.set
780 self.assertEqual(result, empty_set)
782 def test_empty_symmetric_difference(self): argument
783 result = self.set ^ empty_set
784 self.assertEqual(result, self.set)
786 def test_self_difference(self): argument
787 result = self.set - self.set
788 self.assertEqual(result, empty_set)
790 def test_empty_difference(self): argument
791 result = self.set - empty_set
792 self.assertEqual(result, self.dup)
794 def test_empty_difference_rev(self): argument
795 result = empty_set - self.set
796 self.assertEqual(result, empty_set)
798 def test_iteration(self): argument
799 for v in self.set:
800 self.assertIn(v, self.values)
801 setiter = iter(self.set)
804 self.assertEqual(setiter.__length_hint__(), len(self.set))
806 def test_pickling(self): argument
808 p = pickle.dumps(self.set, proto)
810 self.assertEqual(self.set, copy,
811 "%s != %s" % (self.set, copy))
816 def setUp(self): argument
817 self.case = "empty set"
818 self.values = []
819 self.set = set(self.values)
820 self.dup = set(self.values)
821 self.length = 0
822 self.repr = "set([])"
827 def setUp(self): argument
828 self.case = "unit set (number)"
829 self.values = [3]
830 self.set = set(self.values)
831 self.dup = set(self.values)
832 self.length = 1
833 self.repr = "set([3])"
835 def test_in(self): argument
836 self.assertIn(3, self.set)
838 def test_not_in(self): argument
839 self.assertNotIn(2, self.set)
844 def setUp(self): argument
845 self.case = "unit set (tuple)"
846 self.values = [(0, "zero")]
847 self.set = set(self.values)
848 self.dup = set(self.values)
849 self.length = 1
850 self.repr = "set([(0, 'zero')])"
852 def test_in(self): argument
853 self.assertIn((0, "zero"), self.set)
855 def test_not_in(self): argument
856 self.assertNotIn(9, self.set)
861 def setUp(self): argument
862 self.case = "triple set"
863 self.values = [0, "zero", operator.add]
864 self.set = set(self.values)
865 self.dup = set(self.values)
866 self.length = 3
867 self.repr = None
872 def setUp(self): argument
873 self.case = "string set"
874 self.values = ["a", "b", "c"]
875 self.set = set(self.values)
876 self.dup = set(self.values)
877 self.length = 3
879 def test_repr(self): argument
880 self.check_repr_against_values()
885 def setUp(self): argument
886 self.case = "unicode set"
887 self.values = [u"a", u"b", u"c"]
888 self.set = set(self.values)
889 self.dup = set(self.values)
890 self.length = 3
892 def test_repr(self): argument
893 self.check_repr_against_values()
898 def setUp(self): argument
899 self.case = "string and bytes set"
900 self.values = ["a", "b", u"a", u"b"]
901 self.set = set(self.values)
902 self.dup = set(self.values)
903 self.length = 4
905 def test_repr(self): argument
907 self.check_repr_against_values()
921 def test_instanceWithException(self): argument
922 self.assertRaises(TypeError, set, baditer())
924 def test_instancesWithoutException(self): argument
933 def test_changingSizeWhileIterating(self): argument
941 self.fail("no exception when changing size during iteration")
946 def test_constructor(self): argument
950 self.assertEqual(type(element), frozenset)
953 self.assertEqual(outer, set()) # Verify that remove worked
959 def setUp(self): argument
960 self.set = set((2, 4, 6))
962 def test_eq(self): # SF bug 643115 argument
963 self.assertEqual(self.set, set({2:1,4:3,6:5}))
965 def test_union_subset(self): argument
966 result = self.set | set([2])
967 self.assertEqual(result, set((2, 4, 6)))
969 def test_union_superset(self): argument
970 result = self.set | set([2, 4, 6, 8])
971 self.assertEqual(result, set([2, 4, 6, 8]))
973 def test_union_overlap(self): argument
974 result = self.set | set([3, 4, 5])
975 self.assertEqual(result, set([2, 3, 4, 5, 6]))
977 def test_union_non_overlap(self): argument
978 result = self.set | set([8])
979 self.assertEqual(result, set([2, 4, 6, 8]))
981 def test_intersection_subset(self): argument
982 result = self.set & set((2, 4))
983 self.assertEqual(result, set((2, 4)))
985 def test_intersection_superset(self): argument
986 result = self.set & set([2, 4, 6, 8])
987 self.assertEqual(result, set([2, 4, 6]))
989 def test_intersection_overlap(self): argument
990 result = self.set & set([3, 4, 5])
991 self.assertEqual(result, set([4]))
993 def test_intersection_non_overlap(self): argument
994 result = self.set & set([8])
995 self.assertEqual(result, empty_set)
997 def test_isdisjoint_subset(self): argument
998 result = self.set.isdisjoint(set((2, 4)))
999 self.assertEqual(result, False)
1001 def test_isdisjoint_superset(self): argument
1002 result = self.set.isdisjoint(set([2, 4, 6, 8]))
1003 self.assertEqual(result, False)
1005 def test_isdisjoint_overlap(self): argument
1006 result = self.set.isdisjoint(set([3, 4, 5]))
1007 self.assertEqual(result, False)
1009 def test_isdisjoint_non_overlap(self): argument
1010 result = self.set.isdisjoint(set([8]))
1011 self.assertEqual(result, True)
1013 def test_sym_difference_subset(self): argument
1014 result = self.set ^ set((2, 4))
1015 self.assertEqual(result, set([6]))
1017 def test_sym_difference_superset(self): argument
1018 result = self.set ^ set((2, 4, 6, 8))
1019 self.assertEqual(result, set([8]))
1021 def test_sym_difference_overlap(self): argument
1022 result = self.set ^ set((3, 4, 5))
1023 self.assertEqual(result, set([2, 3, 5, 6]))
1025 def test_sym_difference_non_overlap(self): argument
1026 result = self.set ^ set([8])
1027 self.assertEqual(result, set([2, 4, 6, 8]))
1029 def test_cmp(self): argument
1031 self.assertRaises(TypeError, cmp, a, b)
1037 self.assertEqual(cmp(a, a), 0)
1043 def setUp(self): argument
1044 self.set = set((2, 4, 6))
1046 def test_union_subset(self): argument
1047 self.set |= set([2])
1048 self.assertEqual(self.set, set((2, 4, 6)))
1050 def test_union_superset(self): argument
1051 self.set |= set([2, 4, 6, 8])
1052 self.assertEqual(self.set, set([2, 4, 6, 8]))
1054 def test_union_overlap(self): argument
1055 self.set |= set([3, 4, 5])
1056 self.assertEqual(self.set, set([2, 3, 4, 5, 6]))
1058 def test_union_non_overlap(self): argument
1059 self.set |= set([8])
1060 self.assertEqual(self.set, set([2, 4, 6, 8]))
1062 def test_union_method_call(self): argument
1063 self.set.update(set([3, 4, 5]))
1064 self.assertEqual(self.set, set([2, 3, 4, 5, 6]))
1066 def test_intersection_subset(self): argument
1067 self.set &= set((2, 4))
1068 self.assertEqual(self.set, set((2, 4)))
1070 def test_intersection_superset(self): argument
1071 self.set &= set([2, 4, 6, 8])
1072 self.assertEqual(self.set, set([2, 4, 6]))
1074 def test_intersection_overlap(self): argument
1075 self.set &= set([3, 4, 5])
1076 self.assertEqual(self.set, set([4]))
1078 def test_intersection_non_overlap(self): argument
1079 self.set &= set([8])
1080 self.assertEqual(self.set, empty_set)
1082 def test_intersection_method_call(self): argument
1083 self.set.intersection_update(set([3, 4, 5]))
1084 self.assertEqual(self.set, set([4]))
1086 def test_sym_difference_subset(self): argument
1087 self.set ^= set((2, 4))
1088 self.assertEqual(self.set, set([6]))
1090 def test_sym_difference_superset(self): argument
1091 self.set ^= set((2, 4, 6, 8))
1092 self.assertEqual(self.set, set([8]))
1094 def test_sym_difference_overlap(self): argument
1095 self.set ^= set((3, 4, 5))
1096 self.assertEqual(self.set, set([2, 3, 5, 6]))
1098 def test_sym_difference_non_overlap(self): argument
1099 self.set ^= set([8])
1100 self.assertEqual(self.set, set([2, 4, 6, 8]))
1102 def test_sym_difference_method_call(self): argument
1103 self.set.symmetric_difference_update(set([3, 4, 5]))
1104 self.assertEqual(self.set, set([2, 3, 5, 6]))
1106 def test_difference_subset(self): argument
1107 self.set -= set((2, 4))
1108 self.assertEqual(self.set, set([6]))
1110 def test_difference_superset(self): argument
1111 self.set -= set((2, 4, 6, 8))
1112 self.assertEqual(self.set, set([]))
1114 def test_difference_overlap(self): argument
1115 self.set -= set((3, 4, 5))
1116 self.assertEqual(self.set, set([2, 6]))
1118 def test_difference_non_overlap(self): argument
1119 self.set -= set([8])
1120 self.assertEqual(self.set, set([2, 4, 6]))
1122 def test_difference_method_call(self): argument
1123 self.set.difference_update(set([3, 4, 5]))
1124 self.assertEqual(self.set, set([2, 6]))
1129 def setUp(self): argument
1130 self.values = ["a", "b", "c"]
1131 self.set = set(self.values)
1133 def test_add_present(self): argument
1134 self.set.add("c")
1135 self.assertEqual(self.set, set("abc"))
1137 def test_add_absent(self): argument
1138 self.set.add("d")
1139 self.assertEqual(self.set, set("abcd"))
1141 def test_add_until_full(self): argument
1144 for v in self.values:
1147 self.assertEqual(len(tmp), expected_len)
1148 self.assertEqual(tmp, self.set)
1150 def test_remove_present(self): argument
1151 self.set.remove("b")
1152 self.assertEqual(self.set, set("ac"))
1154 def test_remove_absent(self): argument
1156 self.set.remove("d")
1157 self.fail("Removing missing element should have raised LookupError")
1161 def test_remove_until_empty(self): argument
1162 expected_len = len(self.set)
1163 for v in self.values:
1164 self.set.remove(v)
1166 self.assertEqual(len(self.set), expected_len)
1168 def test_discard_present(self): argument
1169 self.set.discard("c")
1170 self.assertEqual(self.set, set("ab"))
1172 def test_discard_absent(self): argument
1173 self.set.discard("d")
1174 self.assertEqual(self.set, set("abc"))
1176 def test_clear(self): argument
1177 self.set.clear()
1178 self.assertEqual(len(self.set), 0)
1180 def test_pop(self): argument
1182 while self.set:
1183 popped[self.set.pop()] = None
1184 self.assertEqual(len(popped), len(self.values))
1185 for v in self.values:
1186 self.assertIn(v, popped)
1188 def test_update_empty_tuple(self): argument
1189 self.set.update(())
1190 self.assertEqual(self.set, set(self.values))
1192 def test_update_unit_tuple_overlap(self): argument
1193 self.set.update(("a",))
1194 self.assertEqual(self.set, set(self.values))
1196 def test_update_unit_tuple_non_overlap(self): argument
1197 self.set.update(("a", "z"))
1198 self.assertEqual(self.set, set(self.values + ["z"]))
1216 def test_issubset(self): argument
1217 x = self.left
1218 y = self.right
1220 expected = case in self.cases
1223 self.assertEqual(result, expected)
1228 self.assertEqual(result, expected)
1233 self.assertEqual(result, expected)
1237 self.assertEqual(result, expected)
1282 def test_eq_ne(self): argument
1284 self.assertEqual(self.other == self.set, False)
1285 self.assertEqual(self.set == self.other, False)
1286 self.assertEqual(self.other != self.set, True)
1287 self.assertEqual(self.set != self.other, True)
1289 def test_update_operator(self): argument
1291 self.set |= self.other
1295 self.fail("expected TypeError")
1297 def test_update(self): argument
1298 if self.otherIsIterable:
1299 self.set.update(self.other)
1301 self.assertRaises(TypeError, self.set.update, self.other)
1303 def test_union(self): argument
1304 self.assertRaises(TypeError, lambda: self.set | self.other)
1305 self.assertRaises(TypeError, lambda: self.other | self.set)
1306 if self.otherIsIterable:
1307 self.set.union(self.other)
1309 self.assertRaises(TypeError, self.set.union, self.other)
1311 def test_intersection_update_operator(self): argument
1313 self.set &= self.other
1317 self.fail("expected TypeError")
1319 def test_intersection_update(self): argument
1320 if self.otherIsIterable:
1321 self.set.intersection_update(self.other)
1323 self.assertRaises(TypeError,
1324 self.set.intersection_update,
1325 self.other)
1327 def test_intersection(self): argument
1328 self.assertRaises(TypeError, lambda: self.set & self.other)
1329 self.assertRaises(TypeError, lambda: self.other & self.set)
1330 if self.otherIsIterable:
1331 self.set.intersection(self.other)
1333 self.assertRaises(TypeError, self.set.intersection, self.other)
1335 def test_sym_difference_update_operator(self): argument
1337 self.set ^= self.other
1341 self.fail("expected TypeError")
1343 def test_sym_difference_update(self): argument
1344 if self.otherIsIterable:
1345 self.set.symmetric_difference_update(self.other)
1347 self.assertRaises(TypeError,
1348 self.set.symmetric_difference_update,
1349 self.other)
1351 def test_sym_difference(self): argument
1352 self.assertRaises(TypeError, lambda: self.set ^ self.other)
1353 self.assertRaises(TypeError, lambda: self.other ^ self.set)
1354 if self.otherIsIterable:
1355 self.set.symmetric_difference(self.other)
1357 self.assertRaises(TypeError, self.set.symmetric_difference, self.other)
1359 def test_difference_update_operator(self): argument
1361 self.set -= self.other
1365 self.fail("expected TypeError")
1367 def test_difference_update(self): argument
1368 if self.otherIsIterable:
1369 self.set.difference_update(self.other)
1371 self.assertRaises(TypeError,
1372 self.set.difference_update,
1373 self.other)
1375 def test_difference(self): argument
1376 self.assertRaises(TypeError, lambda: self.set - self.other)
1377 self.assertRaises(TypeError, lambda: self.other - self.set)
1378 if self.otherIsIterable:
1379 self.set.difference(self.other)
1381 self.assertRaises(TypeError, self.set.difference, self.other)
1386 def setUp(self): argument
1387 self.set = set((1, 2, 3))
1388 self.other = 19
1389 self.otherIsIterable = False
1394 def setUp(self): argument
1395 self.set = set((1, 2, 3))
1396 self.other = {1:2, 3:4}
1397 self.otherIsIterable = True
1402 def setUp(self): argument
1403 self.set = set((1, 2, 3))
1404 self.other = (2, 4, 6)
1405 self.otherIsIterable = True
1410 def setUp(self): argument
1411 self.set = set((1, 2, 3))
1412 self.other = 'abc'
1413 self.otherIsIterable = True
1418 def setUp(self): argument
1422 self.set = set((1, 2, 3))
1423 self.other = gen()
1424 self.otherIsIterable = True
1430 def test_copy(self): argument
1431 dup = list(self.set.copy())
1432 self.assertEqual(len(dup), len(self.set))
1433 for el in self.set:
1434 self.assertIn(el, dup)
1436 self.assertIs(el, dup.pop(pos))
1437 self.assertFalse(dup)
1439 def test_deep_copy(self): argument
1440 dup = copy.deepcopy(self.set)
1441 self.assertSetEqual(dup, self.set)
1446 def setUp(self): argument
1447 self.set = set()
1452 def setUp(self): argument
1453 self.set = set(["hello"])
1458 def setUp(self): argument
1459 self.set = set(["zero", 0, None])
1464 def setUp(self): argument
1465 self.set = set([(1, 2)])
1470 def setUp(self): argument
1471 self.set = set([((1, 2), (3, 4))])
1476 def setUp(self): argument
1477 self.a = set('abracadabra')
1478 self.b = set('alacazam')
1480 def test_binopsVsSubsets(self): argument
1481 a, b = self.a, self.b
1482 self.assertTrue(a - b < a)
1483 self.assertTrue(b - a < b)
1484 self.assertTrue(a & b < a)
1485 self.assertTrue(a & b < b)
1486 self.assertTrue(a | b > a)
1487 self.assertTrue(a | b > b)
1488 self.assertTrue(a ^ b < a | b)
1490 def test_commutativity(self): argument
1491 a, b = self.a, self.b
1492 self.assertEqual(a&b, b&a)
1493 self.assertEqual(a|b, b|a)
1494 self.assertEqual(a^b, b^a)
1496 self.assertNotEqual(a-b, b-a)
1498 def test_summations(self): argument
1500 a, b = self.a, self.b
1501 self.assertEqual((a-b)|(a&b)|(b-a), a|b)
1502 self.assertEqual((a&b)|(a^b), a|b)
1503 self.assertEqual(a|(b-a), a|b)
1504 self.assertEqual((a-b)|b, a|b)
1505 self.assertEqual((a-b)|(a&b), a)
1506 self.assertEqual((b-a)|(a&b), b)
1507 self.assertEqual((a-b)|(b-a), a^b)
1509 def test_exclusion(self): argument
1511 a, b, zero = self.a, self.b, set()
1512 self.assertEqual((a-b)&b, zero)
1513 self.assertEqual((b-a)&a, zero)
1514 self.assertEqual((a&b)&(a^b), zero)
1525 def __init__(self, seqn): argument
1526 self.seqn = seqn
1527 def __getitem__(self, i): argument
1528 return self.seqn[i]
1532 def __init__(self, seqn): argument
1533 self.seqn = seqn
1534 self.i = 0
1535 def __iter__(self): argument
1536 return self
1537 def next(self): argument
1538 if self.i >= len(self.seqn): raise StopIteration
1539 v = self.seqn[self.i]
1540 self.i += 1
1545 def __init__(self, seqn): argument
1546 self.seqn = seqn
1547 self.i = 0
1548 def __iter__(self): argument
1549 for val in self.seqn:
1554 def __init__(self, seqn): argument
1555 self.seqn = seqn
1556 self.i = 0
1557 def next(self): argument
1558 if self.i >= len(self.seqn): raise StopIteration
1559 v = self.seqn[self.i]
1560 self.i += 1
1565 def __init__(self, seqn): argument
1566 self.seqn = seqn
1567 self.i = 0
1568 def __iter__(self): argument
1569 return self
1573 def __init__(self, seqn): argument
1574 self.seqn = seqn
1575 self.i = 0
1576 def __iter__(self): argument
1577 return self
1578 def next(self): argument
1583 def __init__(self, seqn): argument
1585 def __iter__(self): argument
1586 return self
1587 def next(self): argument
1597 def test_constructor(self): argument
1601 self.assertSetEqual(cons(g(s)), set(g(s)))
1602 self.assertRaises(TypeError, cons , X(s))
1603 self.assertRaises(TypeError, cons , N(s))
1604 self.assertRaises(ZeroDivisionError, cons , E(s))
1606 def test_inline_methods(self): argument
1614 self.assertEqual(actual, expected)
1616 self.assertSetEqual(actual, expected)
1617 self.assertRaises(TypeError, meth, X(s))
1618 self.assertRaises(TypeError, meth, N(s))
1619 self.assertRaises(ZeroDivisionError, meth, E(s))
1621 def test_inplace_methods(self): argument
1630 self.assertSetEqual(s, t)
1632 self.assertRaises(TypeError, getattr(set('january'), methname), X(data))
1633 self.assertRaises(TypeError, getattr(set('january'), methname), N(data))
1634 self.assertRaises(ZeroDivisionError, getattr(set('january'), methname), E(data))
1637 def __eq__(self, other): argument
1641 return self is other
1642 def __hash__(self): argument
1646 def __eq__(self, other): argument
1649 return self is other
1650 def __hash__(self): argument
1654 def test_8420_set_merge(self): argument
1661 self.assertRaises(ZeroDivisionError, set1.update, set2)
1669 def test_iter_and_mutate(self): argument
1739 def test_cube(self): argument
1743 self.assertEqual(len(vertices1), 8) # eight vertices
1745 self.assertEqual(len(edge), 3) # each vertex connects to three edges
1747 self.assertEqual(vertices1, vertices2) # edge vertices in original set
1750 self.assertEqual(len(cubefaces), 6) # six faces
1752 self.assertEqual(len(face), 4) # each face is a square
1754 def test_cuboctahedron(self): argument
1762 self.assertEqual(len(cuboctahedron), 12)# twelve vertices
1766 self.assertEqual(len(edges), 4) # each vertex connects to four other vertices
1768 self.assertEqual(vertices, othervertices) # edge vertices in original set
1774 self.assertEqual(facesizes[3], 8) # eight triangular faces
1775 self.assertEqual(facesizes[4], 6) # six square faces
1779 self.assertEqual(len(edge), 2) # Two cube vertices define an edge
1781 self.assertIn(cubevert, g)