Back to index

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

List of all members.

Public Member Functions

def test_init
def test_singleton_empty_frozenset
def test_constructor_identity
def test_hash
def test_copy
def test_frozen_as_dictkey
def test_hash_caching
def test_hash_effectiveness
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

 word
 otherword
 letters
 s
 d
 value

Static Public Attributes

 thetype = frozenset
 basetype = frozenset

Detailed Description

Definition at line 629 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:

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:

Reimplemented in test.test_set.TestFrozenSetSubclass.

Definition at line 647 of file test_set.py.

00647 
00648     def test_constructor_identity(self):
00649         s = self.thetype(range(3))
00650         t = self.thetype(s)
00651         self.assertEqual(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:

Reimplemented in test.test_set.TestFrozenSetSubclass.

Definition at line 665 of file test_set.py.

00665 
00666     def test_copy(self):
00667         dup = self.s.copy()
00668         self.assertEqual(id(self.s), id(dup))

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 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:

Definition at line 669 of file test_set.py.

00669 
00670     def test_frozen_as_dictkey(self):
00671         seq = list(range(10)) + list('abcdefg') + ['apple']
00672         key1 = self.thetype(seq)
00673         key2 = self.thetype(reversed(seq))
00674         self.assertEqual(key1, key2)
00675         self.assertNotEqual(id(key1), id(key2))
00676         d = {}
00677         d[key1] = 42
00678         self.assertEqual(d[key2], 42)

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 652 of file test_set.py.

00652 
00653     def test_hash(self):
00654         self.assertEqual(hash(self.thetype('abcdeb')),
00655                          hash(self.thetype('ebecda')))
00656 
00657         # make sure that all permutations give the same hash value
00658         n = 100
00659         seq = [randrange(n) for i in range(n)]
00660         results = set()
00661         for i in range(200):
00662             shuffle(seq)
00663             results.add(hash(self.thetype(seq)))
00664         self.assertEqual(len(results), 1)

Here is the call graph for this function:

Definition at line 679 of file test_set.py.

00679 
00680     def test_hash_caching(self):
00681         f = self.thetype('abcdcda')
00682         self.assertEqual(hash(f), hash(f))

Here is the call graph for this function:

Definition at line 683 of file test_set.py.

00683 
00684     def test_hash_effectiveness(self):
00685         n = 13
00686         hashvalues = set()
00687         addhashvalue = hashvalues.add
00688         elemmasks = [(i+1, 1<<i) for i in range(n)]
00689         for i in range(2**n):
00690             addhashvalue(hash(frozenset([e for e, m in elemmasks if m&i])))
00691         self.assertEqual(len(hashvalues), 2**n)

Here is the call graph for this function:

Definition at line 633 of file test_set.py.

00633 
00634     def test_init(self):
00635         s = self.thetype(self.word)
00636         s.__init__(self.otherword)
00637         self.assertEqual(s, set(self.word))

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:

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:

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 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:

Reimplemented in test.test_set.TestFrozenSetSubclass.

Definition at line 638 of file test_set.py.

00638 
00639     def test_singleton_empty_frozenset(self):
00640         f = frozenset()
00641         efs = [frozenset(), frozenset([]), frozenset(()), frozenset(''),
00642                frozenset(), frozenset([]), frozenset(()), frozenset(''),
00643                frozenset(range(0)), frozenset(frozenset()),
00644                frozenset(f), f]
00645         # All of the empty frozensets should have just one id()
00646         self.assertEqual(len(set(map(id, efs))), 1)

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:

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:

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.TestFrozenSetSubclass.

Definition at line 631 of file test_set.py.

Definition at line 47 of file test_set.py.

Definition at line 45 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.TestFrozenSetSubclass.

Definition at line 630 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: