Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
test.test_set.TestSet Class Reference
Inheritance diagram for test.test_set.TestSet:
Inheritance graph
[legend]
Collaboration diagram for test.test_set.TestSet:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_init
def test_constructor_identity
def test_set_literal
def test_hash
def test_clear
def test_copy
def test_add
def test_remove
def test_remove_keyerror_unpacking
def test_remove_keyerror_set
def test_discard
def test_pop
def test_update
def test_ior
def test_intersection_update
def test_iand
def test_difference_update
def test_isub
def test_symmetric_difference_update
def test_ixor
def test_inplace_on_self
def test_weakref
def test_rich_compare
def test_c_api
def setUp
def test_new_or_init
def test_uniquification
def test_len
def test_contains
def test_union
def test_or
def test_intersection
def test_isdisjoint
def test_and
def test_difference
def test_sub
def test_symmetric_difference
def test_xor
def test_equality
def test_setOfFrozensets
def test_sub_and_super
def test_pickling
def test_deepcopy
def test_gc
def test_subclass_with_custom_hash
def test_badcmp
def test_cyclical_repr
def test_cyclical_print
def test_do_not_rehash_dict_keys
def test_container_iterator

Public Attributes

 gt_called
 lt_called
 ge_called
 le_called
 word
 otherword
 letters
 s
 d
 value

Static Public Attributes

 thetype = set
 basetype = set

Detailed Description

Definition at line 343 of file test_set.py.


Member Function Documentation

def test.test_set.TestJointOps.setUp (   self) [inherited]

Definition at line 42 of file test_set.py.

00042 
00043     def setUp(self):
00044         self.word = word = 'simsalabim'
00045         self.otherword = 'madagascar'
00046         self.letters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
00047         self.s = self.thetype(word)
00048         self.d = dict.fromkeys(word)

Here is the caller graph for this function:

Definition at line 380 of file test_set.py.

00380 
00381     def test_add(self):
00382         self.s.add('Q')
00383         self.assertIn('Q', self.s)
00384         dup = self.s.copy()
00385         self.s.add('Q')
00386         self.assertEqual(self.s, dup)
00387         self.assertRaises(TypeError, self.s.add, [])

Here is the call graph for this function:

def test.test_set.TestJointOps.test_and (   self) [inherited]

Definition at line 134 of file test_set.py.

00134 
00135     def test_and(self):
00136         i = self.s.intersection(self.otherword)
00137         self.assertEqual(self.s & set(self.otherword), i)
00138         self.assertEqual(self.s & frozenset(self.otherword), i)
00139         try:
00140             self.s & self.otherword
00141         except TypeError:
00142             pass
00143         else:
00144             self.fail("s&t did not screen-out general iterables")

Here is the call graph for this function:

def test.test_set.TestJointOps.test_badcmp (   self) [inherited]

Definition at line 277 of file test_set.py.

00277 
00278     def test_badcmp(self):
00279         s = self.thetype([BadCmp()])
00280         # Detect comparison errors during insertion and lookup
00281         self.assertRaises(RuntimeError, self.thetype, [BadCmp(), BadCmp()])
00282         self.assertRaises(RuntimeError, s.__contains__, BadCmp())
00283         # Detect errors during mutating operations
00284         if hasattr(s, 'add'):
00285             self.assertRaises(RuntimeError, s.add, BadCmp())
00286             self.assertRaises(RuntimeError, s.discard, BadCmp())
00287             self.assertRaises(RuntimeError, s.remove, BadCmp())

Here is the call graph for this function:

Definition at line 609 of file test_set.py.

00609 
00610         def test_c_api(self):
00611             self.assertEqual(set().test_c_api(), True)

Here is the call graph for this function:

Definition at line 369 of file test_set.py.

00369 
00370     def test_clear(self):
00371         self.s.clear()
00372         self.assertEqual(self.s, set())
00373         self.assertEqual(len(self.s), 0)

Here is the call graph for this function:

Definition at line 356 of file test_set.py.

00356 
00357     def test_constructor_identity(self):
00358         s = self.thetype(range(3))
00359         t = self.thetype(s)
00360         self.assertNotEqual(id(s), id(t))

Here is the call graph for this function:

Definition at line 331 of file test_set.py.

00331 
00332     def test_container_iterator(self):
00333         # Bug #3680: tp_traverse was not implemented for set iterator object
00334         class C(object):
00335             pass
00336         obj = C()
00337         ref = weakref.ref(obj)
00338         container = set([obj, 1])
00339         obj.x = iter(container)
00340         del obj, container
00341         gc.collect()
00342         self.assertTrue(ref() is None, "Cycle was not collected")

def test.test_set.TestJointOps.test_contains (   self) [inherited]

Definition at line 63 of file test_set.py.

00063 
00064     def test_contains(self):
00065         for c in self.letters:
00066             self.assertEqual(c in self.s, c in self.d)
00067         self.assertRaises(TypeError, self.s.__contains__, [[]])
00068         s = self.thetype([frozenset(self.letters)])
00069         self.assertIn(self.thetype(self.letters), s)

Here is the call graph for this function:

Definition at line 374 of file test_set.py.

00374 
00375     def test_copy(self):
00376         dup = self.s.copy()
00377         self.assertEqual(self.s, dup)
00378         self.assertNotEqual(id(self.s), id(dup))
00379         self.assertEqual(type(dup), self.basetype)

Here is the call graph for this function:

Definition at line 298 of file test_set.py.

00298 
00299     def test_cyclical_print(self):
00300         w = ReprWrapper()
00301         s = self.thetype([w])
00302         w.value = s
00303         fo = open(support.TESTFN, "w")
00304         try:
00305             fo.write(str(s))
00306             fo.close()
00307             fo = open(support.TESTFN, "r")
00308             self.assertEqual(fo.read(), repr(s))
00309         finally:
00310             fo.close()
00311             support.unlink(support.TESTFN)

Here is the call graph for this function:

Definition at line 288 of file test_set.py.

00288 
00289     def test_cyclical_repr(self):
00290         w = ReprWrapper()
00291         s = self.thetype([w])
00292         w.value = s
00293         if self.thetype == set:
00294             self.assertEqual(repr(s), '{set(...)}')
00295         else:
00296             name = repr(s).partition('(')[0]    # strip class name
00297             self.assertEqual(repr(s), '%s({%s(...)})' % (name, name))

Here is the call graph for this function:

def test.test_set.TestJointOps.test_deepcopy (   self) [inherited]

Definition at line 237 of file test_set.py.

00237 
00238     def test_deepcopy(self):
00239         class Tracer:
00240             def __init__(self, value):
00241                 self.value = value
00242             def __hash__(self):
00243                 return self.value
00244             def __deepcopy__(self, memo=None):
00245                 return Tracer(self.value + 1)
00246         t = Tracer(10)
00247         s = self.thetype([t])
00248         dup = copy.deepcopy(s)
00249         self.assertNotEqual(id(s), id(dup))
00250         for elem in dup:
00251             newt = elem
00252         self.assertNotEqual(id(t), id(newt))
00253         self.assertEqual(t.value + 1, newt.value)

Here is the call graph for this function:

def test.test_set.TestJointOps.test_difference (   self) [inherited]

Definition at line 145 of file test_set.py.

00145 
00146     def test_difference(self):
00147         i = self.s.difference(self.otherword)
00148         for c in self.letters:
00149             self.assertEqual(c in i, c in self.d and c not in self.otherword)
00150         self.assertEqual(self.s, self.thetype(self.word))
00151         self.assertEqual(type(i), self.basetype)
00152         self.assertRaises(PassThru, self.s.difference, check_pass_thru())
00153         self.assertRaises(TypeError, self.s.difference, [[]])
00154         for C in set, frozenset, dict.fromkeys, str, list, tuple:
00155             self.assertEqual(self.thetype('abcba').difference(C('cdc')), set('ab'))
00156             self.assertEqual(self.thetype('abcba').difference(C('efgfe')), set('abc'))
00157             self.assertEqual(self.thetype('abcba').difference(C('ccb')), set('a'))
00158             self.assertEqual(self.thetype('abcba').difference(C('ef')), set('abc'))
00159             self.assertEqual(self.thetype('abcba').difference(), set('abc'))
00160             self.assertEqual(self.thetype('abcba').difference(C('a'), C('b')), set('c'))

Here is the call graph for this function:

Definition at line 491 of file test_set.py.

00491 
00492     def test_difference_update(self):
00493         retval = self.s.difference_update(self.otherword)
00494         self.assertEqual(retval, None)
00495         for c in (self.word + self.otherword):
00496             if c in self.word and c not in self.otherword:
00497                 self.assertIn(c, self.s)
00498             else:
00499                 self.assertNotIn(c, self.s)
00500         self.assertRaises(PassThru, self.s.difference_update, check_pass_thru())
00501         self.assertRaises(TypeError, self.s.difference_update, [[]])
00502         self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]])
00503         for p, q in (('cdc', 'ab'), ('efgfe', 'abc'), ('ccb', 'a'), ('ef', 'abc')):
00504             for C in set, frozenset, dict.fromkeys, str, list, tuple:
00505                 s = self.thetype('abcba')
00506                 self.assertEqual(s.difference_update(C(p)), None)
00507                 self.assertEqual(s, set(q))
00508 
00509                 s = self.thetype('abcdefghih')
00510                 s.difference_update()
00511                 self.assertEqual(s, self.thetype('abcdefghih'))
00512 
00513                 s = self.thetype('abcdefghih')
00514                 s.difference_update(C('aba'))
00515                 self.assertEqual(s, self.thetype('cdefghih'))
00516 
00517                 s = self.thetype('abcdefghih')
00518                 s.difference_update(C('cdc'), C('aba'))
00519                 self.assertEqual(s, self.thetype('efghih'))

Here is the call graph for this function:

Definition at line 421 of file test_set.py.

00421 
00422     def test_discard(self):
00423         self.s.discard('a')
00424         self.assertNotIn('a', self.s)
00425         self.s.discard('Q')
00426         self.assertRaises(TypeError, self.s.discard, [])
00427         s = self.thetype([frozenset(self.word)])
00428         self.assertIn(self.thetype(self.word), s)
00429         s.discard(self.thetype(self.word))
00430         self.assertNotIn(self.thetype(self.word), s)
00431         s.discard(self.thetype(self.word))

Here is the call graph for this function:

Definition at line 312 of file test_set.py.

00312 
00313     def test_do_not_rehash_dict_keys(self):
00314         n = 10
00315         d = dict.fromkeys(map(HashCountingInt, range(n)))
00316         self.assertEqual(sum(elem.hash_count for elem in d), n)
00317         s = self.thetype(d)
00318         self.assertEqual(sum(elem.hash_count for elem in d), n)
00319         s.difference(d)
00320         self.assertEqual(sum(elem.hash_count for elem in d), n)
00321         if hasattr(s, 'symmetric_difference_update'):
00322             s.symmetric_difference_update(d)
00323         self.assertEqual(sum(elem.hash_count for elem in d), n)
00324         d2 = dict.fromkeys(set(d))
00325         self.assertEqual(sum(elem.hash_count for elem in d), n)
00326         d3 = dict.fromkeys(frozenset(d))
00327         self.assertEqual(sum(elem.hash_count for elem in d), n)
00328         d3 = dict.fromkeys(frozenset(d), 123)
00329         self.assertEqual(sum(elem.hash_count for elem in d), n)
00330         self.assertEqual(d3, dict.fromkeys(d, 123))

Here is the call graph for this function:

def test.test_set.TestJointOps.test_equality (   self) [inherited]

Definition at line 197 of file test_set.py.

00197 
00198     def test_equality(self):
00199         self.assertEqual(self.s, set(self.word))
00200         self.assertEqual(self.s, frozenset(self.word))
00201         self.assertEqual(self.s == self.word, False)
00202         self.assertNotEqual(self.s, set(self.otherword))
00203         self.assertNotEqual(self.s, frozenset(self.otherword))
00204         self.assertEqual(self.s != self.word, True)

Here is the call graph for this function:

def test.test_set.TestJointOps.test_gc (   self) [inherited]

Definition at line 254 of file test_set.py.

00254 
00255     def test_gc(self):
00256         # Create a nest of cycles to exercise overall ref count check
00257         class A:
00258             pass
00259         s = set(A() for i in range(1000))
00260         for elem in s:
00261             elem.cycle = s
00262             elem.sub = elem
00263             elem.set = set([elem])

Definition at line 366 of file test_set.py.

00366 
00367     def test_hash(self):
00368         self.assertRaises(TypeError, hash, self.s)

Here is the call graph for this function:

Definition at line 483 of file test_set.py.

00483 
00484     def test_iand(self):
00485         self.s &= set(self.otherword)
00486         for c in (self.word + self.otherword):
00487             if c in self.otherword and c in self.word:
00488                 self.assertIn(c, self.s)
00489             else:
00490                 self.assertNotIn(c, self.s)

Here is the call graph for this function:

Definition at line 347 of file test_set.py.

00347 
00348     def test_init(self):
00349         s = self.thetype()
00350         s.__init__(self.word)
00351         self.assertEqual(s, set(self.word))
00352         s.__init__(self.otherword)
00353         self.assertEqual(s, set(self.otherword))
00354         self.assertRaises(TypeError, s.__init__, s, 2);
00355         self.assertRaises(TypeError, s.__init__, 1);

Here is the call graph for this function:

Definition at line 552 of file test_set.py.

00552 
00553     def test_inplace_on_self(self):
00554         t = self.s.copy()
00555         t |= t
00556         self.assertEqual(t, self.s)
00557         t &= t
00558         self.assertEqual(t, self.s)
00559         t -= t
00560         self.assertEqual(t, self.thetype())
00561         t = self.s.copy()
00562         t ^= t
00563         self.assertEqual(t, self.thetype())

Here is the call graph for this function:

Definition at line 100 of file test_set.py.

00100 
00101     def test_intersection(self):
00102         i = self.s.intersection(self.otherword)
00103         for c in self.letters:
00104             self.assertEqual(c in i, c in self.d and c in self.otherword)
00105         self.assertEqual(self.s, self.thetype(self.word))
00106         self.assertEqual(type(i), self.basetype)
00107         self.assertRaises(PassThru, self.s.intersection, check_pass_thru())
00108         for C in set, frozenset, dict.fromkeys, str, list, tuple:
00109             self.assertEqual(self.thetype('abcba').intersection(C('cdc')), set('cc'))
00110             self.assertEqual(self.thetype('abcba').intersection(C('efgfe')), set(''))
00111             self.assertEqual(self.thetype('abcba').intersection(C('ccb')), set('bc'))
00112             self.assertEqual(self.thetype('abcba').intersection(C('ef')), set(''))
00113             self.assertEqual(self.thetype('abcba').intersection(C('cbcf'), C('bag')), set('b'))
00114         s = self.thetype('abcba')
00115         z = s.intersection()
00116         if self.thetype == frozenset():
00117             self.assertEqual(id(s), id(z))
00118         else:
00119             self.assertNotEqual(id(s), id(z))

Here is the call graph for this function:

Definition at line 462 of file test_set.py.

00462 
00463     def test_intersection_update(self):
00464         retval = self.s.intersection_update(self.otherword)
00465         self.assertEqual(retval, None)
00466         for c in (self.word + self.otherword):
00467             if c in self.otherword and c in self.word:
00468                 self.assertIn(c, self.s)
00469             else:
00470                 self.assertNotIn(c, self.s)
00471         self.assertRaises(PassThru, self.s.intersection_update, check_pass_thru())
00472         self.assertRaises(TypeError, self.s.intersection_update, [[]])
00473         for p, q in (('cdc', 'c'), ('efgfe', ''), ('ccb', 'bc'), ('ef', '')):
00474             for C in set, frozenset, dict.fromkeys, str, list, tuple:
00475                 s = self.thetype('abcba')
00476                 self.assertEqual(s.intersection_update(C(p)), None)
00477                 self.assertEqual(s, set(q))
00478                 ss = 'abcba'
00479                 s = self.thetype(ss)
00480                 t = 'cbc'
00481                 self.assertEqual(s.intersection_update(C(p), C(t)), None)
00482                 self.assertEqual(s, set('abcba')&set(p)&set(t))

Here is the call graph for this function:

Definition at line 457 of file test_set.py.

00457 
00458     def test_ior(self):
00459         self.s |= set(self.otherword)
00460         for c in (self.word + self.otherword):
00461             self.assertIn(c, self.s)

Here is the call graph for this function:

def test.test_set.TestJointOps.test_isdisjoint (   self) [inherited]

Definition at line 120 of file test_set.py.

00120 
00121     def test_isdisjoint(self):
00122         def f(s1, s2):
00123             'Pure python equivalent of isdisjoint()'
00124             return not set(s1).intersection(s2)
00125         for larg in '', 'a', 'ab', 'abc', 'ababac', 'cdc', 'cc', 'efgfe', 'ccb', 'ef':
00126             s1 = self.thetype(larg)
00127             for rarg in '', 'a', 'ab', 'abc', 'ababac', 'cdc', 'cc', 'efgfe', 'ccb', 'ef':
00128                 for C in set, frozenset, dict.fromkeys, str, list, tuple:
00129                     s2 = C(rarg)
00130                     actual = s1.isdisjoint(s2)
00131                     expected = f(s1, s2)
00132                     self.assertEqual(actual, expected)
00133                     self.assertTrue(actual is True or actual is False)

Here is the call graph for this function:

Definition at line 520 of file test_set.py.

00520 
00521     def test_isub(self):
00522         self.s -= set(self.otherword)
00523         for c in (self.word + self.otherword):
00524             if c in self.word and c not in self.otherword:
00525                 self.assertIn(c, self.s)
00526             else:
00527                 self.assertNotIn(c, self.s)

Here is the call graph for this function:

Definition at line 544 of file test_set.py.

00544 
00545     def test_ixor(self):
00546         self.s ^= set(self.otherword)
00547         for c in (self.word + self.otherword):
00548             if (c in self.word) ^ (c in self.otherword):
00549                 self.assertIn(c, self.s)
00550             else:
00551                 self.assertNotIn(c, self.s)

Here is the call graph for this function:

def test.test_set.TestJointOps.test_len (   self) [inherited]

Definition at line 60 of file test_set.py.

00060 
00061     def test_len(self):
00062         self.assertEqual(len(self.s), len(self.d))

Here is the call graph for this function:

def test.test_set.TestJointOps.test_new_or_init (   self) [inherited]

Definition at line 49 of file test_set.py.

00049 
00050     def test_new_or_init(self):
00051         self.assertRaises(TypeError, self.thetype, [], 2)
00052         self.assertRaises(TypeError, set().__init__, a=1)

Here is the call graph for this function:

def test.test_set.TestJointOps.test_or (   self) [inherited]

Definition at line 89 of file test_set.py.

00089 
00090     def test_or(self):
00091         i = self.s.union(self.otherword)
00092         self.assertEqual(self.s | set(self.otherword), i)
00093         self.assertEqual(self.s | frozenset(self.otherword), i)
00094         try:
00095             self.s | self.otherword
00096         except TypeError:
00097             pass
00098         else:
00099             self.fail("s|t did not screen-out general iterables")

Here is the call graph for this function:

def test.test_set.TestJointOps.test_pickling (   self) [inherited]

Definition at line 226 of file test_set.py.

00226 
00227     def test_pickling(self):
00228         for i in range(pickle.HIGHEST_PROTOCOL + 1):
00229             p = pickle.dumps(self.s, i)
00230             dup = pickle.loads(p)
00231             self.assertEqual(self.s, dup, "%s != %s" % (self.s, dup))
00232             if type(self.s) not in (set, frozenset):
00233                 self.s.x = 10
00234                 p = pickle.dumps(self.s)
00235                 dup = pickle.loads(p)
00236                 self.assertEqual(self.s.x, dup.x)

Here is the call graph for this function:

Definition at line 432 of file test_set.py.

00432 
00433     def test_pop(self):
00434         for i in range(len(self.s)):
00435             elem = self.s.pop()
00436             self.assertNotIn(elem, self.s)
00437         self.assertRaises(KeyError, self.s.pop)

Here is the call graph for this function:

Definition at line 388 of file test_set.py.

00388 
00389     def test_remove(self):
00390         self.s.remove('a')
00391         self.assertNotIn('a', self.s)
00392         self.assertRaises(KeyError, self.s.remove, 'Q')
00393         self.assertRaises(TypeError, self.s.remove, [])
00394         s = self.thetype([frozenset(self.word)])
00395         self.assertIn(self.thetype(self.word), s)
00396         s.remove(self.thetype(self.word))
00397         self.assertNotIn(self.thetype(self.word), s)
00398         self.assertRaises(KeyError, self.s.remove, self.thetype(self.word))

Here is the call graph for this function:

Definition at line 410 of file test_set.py.

00410 
00411     def test_remove_keyerror_set(self):
00412         key = self.thetype([3, 4])
00413         try:
00414             self.s.remove(key)
00415         except KeyError as e:
00416             self.assertTrue(e.args[0] is key,
00417                          "KeyError should be {0}, not {1}".format(key,
00418                                                                   e.args[0]))
00419         else:
00420             self.fail()

Here is the call graph for this function:

Definition at line 399 of file test_set.py.

00399 
00400     def test_remove_keyerror_unpacking(self):
00401         # bug:  www.python.org/sf/1576657
00402         for v1 in ['Q', (1,)]:
00403             try:
00404                 self.s.remove(v1)
00405             except KeyError as e:
00406                 v2 = e.args[0]
00407                 self.assertEqual(v1, v2)
00408             else:
00409                 self.fail()

Here is the call graph for this function:

Definition at line 571 of file test_set.py.

00571 
00572     def test_rich_compare(self):
00573         class TestRichSetCompare:
00574             def __gt__(self, some_set):
00575                 self.gt_called = True
00576                 return False
00577             def __lt__(self, some_set):
00578                 self.lt_called = True
00579                 return False
00580             def __ge__(self, some_set):
00581                 self.ge_called = True
00582                 return False
00583             def __le__(self, some_set):
00584                 self.le_called = True
00585                 return False
00586 
00587         # This first tries the builtin rich set comparison, which doesn't know
00588         # how to handle the custom object. Upon returning NotImplemented, the
00589         # corresponding comparison on the right object is invoked.
00590         myset = {1, 2, 3}
00591 
00592         myobj = TestRichSetCompare()
00593         myset < myobj
00594         self.assertTrue(myobj.gt_called)
00595 
00596         myobj = TestRichSetCompare()
00597         myset > myobj
00598         self.assertTrue(myobj.lt_called)
00599 
00600         myobj = TestRichSetCompare()
00601         myset <= myobj
00602         self.assertTrue(myobj.ge_called)
00603 
00604         myobj = TestRichSetCompare()
00605         myset >= myobj
00606         self.assertTrue(myobj.le_called)

Definition at line 361 of file test_set.py.

00361 
00362     def test_set_literal(self):
00363         s = set([1,2,3])
00364         t = {1,2,3}
00365         self.assertEqual(s, t)

Here is the call graph for this function:

Definition at line 205 of file test_set.py.

00205 
00206     def test_setOfFrozensets(self):
00207         t = map(frozenset, ['abcdef', 'bcd', 'bdcb', 'fed', 'fedccba'])
00208         s = self.thetype(t)
00209         self.assertEqual(len(s), 3)

Here is the call graph for this function:

def test.test_set.TestJointOps.test_sub (   self) [inherited]

Definition at line 161 of file test_set.py.

00161 
00162     def test_sub(self):
00163         i = self.s.difference(self.otherword)
00164         self.assertEqual(self.s - set(self.otherword), i)
00165         self.assertEqual(self.s - frozenset(self.otherword), i)
00166         try:
00167             self.s - self.otherword
00168         except TypeError:
00169             pass
00170         else:
00171             self.fail("s-t did not screen-out general iterables")

Here is the call graph for this function:

Definition at line 210 of file test_set.py.

00210 
00211     def test_sub_and_super(self):
00212         p, q, r = map(self.thetype, ['ab', 'abcde', 'def'])
00213         self.assertTrue(p < q)
00214         self.assertTrue(p <= q)
00215         self.assertTrue(q <= q)
00216         self.assertTrue(q > p)
00217         self.assertTrue(q >= p)
00218         self.assertFalse(q < r)
00219         self.assertFalse(q <= r)
00220         self.assertFalse(q > r)
00221         self.assertFalse(q >= r)
00222         self.assertTrue(set('a').issubset('abc'))
00223         self.assertTrue(set('abc').issuperset('a'))
00224         self.assertFalse(set('a').issubset('cbs'))
00225         self.assertFalse(set('cbs').issuperset('a'))

Here is the call graph for this function:

Definition at line 264 of file test_set.py.

00264 
00265     def test_subclass_with_custom_hash(self):
00266         # Bug #1257731
00267         class H(self.thetype):
00268             def __hash__(self):
00269                 return int(id(self) & 0x7fffffff)
00270         s=H()
00271         f=set()
00272         f.add(s)
00273         self.assertIn(s, f)
00274         f.remove(s)
00275         f.add(s)
00276         f.discard(s)

Here is the call graph for this function:

Definition at line 172 of file test_set.py.

00172 
00173     def test_symmetric_difference(self):
00174         i = self.s.symmetric_difference(self.otherword)
00175         for c in self.letters:
00176             self.assertEqual(c in i, (c in self.d) ^ (c in self.otherword))
00177         self.assertEqual(self.s, self.thetype(self.word))
00178         self.assertEqual(type(i), self.basetype)
00179         self.assertRaises(PassThru, self.s.symmetric_difference, check_pass_thru())
00180         self.assertRaises(TypeError, self.s.symmetric_difference, [[]])
00181         for C in set, frozenset, dict.fromkeys, str, list, tuple:
00182             self.assertEqual(self.thetype('abcba').symmetric_difference(C('cdc')), set('abd'))
00183             self.assertEqual(self.thetype('abcba').symmetric_difference(C('efgfe')), set('abcefg'))
00184             self.assertEqual(self.thetype('abcba').symmetric_difference(C('ccb')), set('a'))
00185             self.assertEqual(self.thetype('abcba').symmetric_difference(C('ef')), set('abcef'))

Here is the call graph for this function:

Definition at line 528 of file test_set.py.

00528 
00529     def test_symmetric_difference_update(self):
00530         retval = self.s.symmetric_difference_update(self.otherword)
00531         self.assertEqual(retval, None)
00532         for c in (self.word + self.otherword):
00533             if (c in self.word) ^ (c in self.otherword):
00534                 self.assertIn(c, self.s)
00535             else:
00536                 self.assertNotIn(c, self.s)
00537         self.assertRaises(PassThru, self.s.symmetric_difference_update, check_pass_thru())
00538         self.assertRaises(TypeError, self.s.symmetric_difference_update, [[]])
00539         for p, q in (('cdc', 'abd'), ('efgfe', 'abcefg'), ('ccb', 'a'), ('ef', 'abcef')):
00540             for C in set, frozenset, dict.fromkeys, str, list, tuple:
00541                 s = self.thetype('abcba')
00542                 self.assertEqual(s.symmetric_difference_update(C(p)), None)
00543                 self.assertEqual(s, set(q))

Here is the call graph for this function:

def test.test_set.TestJointOps.test_union (   self) [inherited]

Definition at line 70 of file test_set.py.

00070 
00071     def test_union(self):
00072         u = self.s.union(self.otherword)
00073         for c in self.letters:
00074             self.assertEqual(c in u, c in self.d or c in self.otherword)
00075         self.assertEqual(self.s, self.thetype(self.word))
00076         self.assertEqual(type(u), self.basetype)
00077         self.assertRaises(PassThru, self.s.union, check_pass_thru())
00078         self.assertRaises(TypeError, self.s.union, [[]])
00079         for C in set, frozenset, dict.fromkeys, str, list, tuple:
00080             self.assertEqual(self.thetype('abcba').union(C('cdc')), set('abcd'))
00081             self.assertEqual(self.thetype('abcba').union(C('efgfe')), set('abcefg'))
00082             self.assertEqual(self.thetype('abcba').union(C('ccb')), set('abc'))
00083             self.assertEqual(self.thetype('abcba').union(C('ef')), set('abcef'))
00084             self.assertEqual(self.thetype('abcba').union(C('ef'), C('fg')), set('abcefg'))
00085 
00086         # Issue #6573
00087         x = self.thetype()
00088         self.assertEqual(x.union(set([1]), x, set([2])), self.thetype([1, 2]))

Here is the call graph for this function:

Definition at line 53 of file test_set.py.

00053 
00054     def test_uniquification(self):
00055         actual = sorted(self.s)
00056         expected = sorted(self.d)
00057         self.assertEqual(actual, expected)
00058         self.assertRaises(PassThru, self.thetype, check_pass_thru())
00059         self.assertRaises(TypeError, self.thetype, [[]])

Here is the call graph for this function:

Definition at line 438 of file test_set.py.

00438 
00439     def test_update(self):
00440         retval = self.s.update(self.otherword)
00441         self.assertEqual(retval, None)
00442         for c in (self.word + self.otherword):
00443             self.assertIn(c, self.s)
00444         self.assertRaises(PassThru, self.s.update, check_pass_thru())
00445         self.assertRaises(TypeError, self.s.update, [[]])
00446         for p, q in (('cdc', 'abcd'), ('efgfe', 'abcefg'), ('ccb', 'abc'), ('ef', 'abcef')):
00447             for C in set, frozenset, dict.fromkeys, str, list, tuple:
00448                 s = self.thetype('abcba')
00449                 self.assertEqual(s.update(C(p)), None)
00450                 self.assertEqual(s, set(q))
00451         for p in ('cdc', 'efgfe', 'ccb', 'ef', 'abcda'):
00452             q = 'ahi'
00453             for C in set, frozenset, dict.fromkeys, str, list, tuple:
00454                 s = self.thetype('abcba')
00455                 self.assertEqual(s.update(C(p), C(q)), None)
00456                 self.assertEqual(s, set(s) | set(p) | set(q))

Here is the call graph for this function:

Definition at line 564 of file test_set.py.

00564 
00565     def test_weakref(self):
00566         s = self.thetype('gallahad')
00567         p = weakref.proxy(s)
00568         self.assertEqual(str(p), str(s))
00569         s = None
00570         self.assertRaises(ReferenceError, str, p)

Here is the call graph for this function:

def test.test_set.TestJointOps.test_xor (   self) [inherited]

Definition at line 186 of file test_set.py.

00186 
00187     def test_xor(self):
00188         i = self.s.symmetric_difference(self.otherword)
00189         self.assertEqual(self.s ^ set(self.otherword), i)
00190         self.assertEqual(self.s ^ frozenset(self.otherword), i)
00191         try:
00192             self.s ^ self.otherword
00193         except TypeError:
00194             pass
00195         else:
00196             self.fail("s^t did not screen-out general iterables")

Here is the call graph for this function:


Member Data Documentation

Reimplemented in test.test_set.TestSetSubclass.

Definition at line 345 of file test_set.py.

Definition at line 47 of file test_set.py.

Definition at line 580 of file test_set.py.

Definition at line 574 of file test_set.py.

Definition at line 583 of file test_set.py.

Definition at line 45 of file test_set.py.

Definition at line 577 of file test_set.py.

Definition at line 44 of file test_set.py.

Definition at line 46 of file test_set.py.

Reimplemented from test.test_set.TestJointOps.

Reimplemented in test.test_set.TestSetSubclass.

Definition at line 344 of file test_set.py.

Definition at line 240 of file test_set.py.

Definition at line 43 of file test_set.py.


The documentation for this class was generated from the following file: