<s> import unittest <EOL> from test import test_support <EOL> import gc <EOL> import weakref <EOL> import operator <EOL> import copy <EOL> import pickle <EOL> from random import randrange , shuffle <EOL> import sys <EOL> import collections <EOL> class PassThru ( Exception ) : <EOL> pass <EOL> def check_pass_thru ( ) : <EOL> raise PassThru <EOL> yield <NUM_LIT:1> <EOL> class BadCmp : <EOL> def __hash__ ( self ) : <EOL> return <NUM_LIT:1> <EOL> def __cmp__ ( self , other ) : <EOL> raise RuntimeError <EOL> class ReprWrapper : <EOL> '<STR_LIT>' <EOL> def __repr__ ( self ) : <EOL> return repr ( self . value ) <EOL> class HashCountingInt ( int ) : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , * args ) : <EOL> self . hash_count = <NUM_LIT:0> <EOL> def __hash__ ( self ) : <EOL> self . hash_count += <NUM_LIT:1> <EOL> return int . __hash__ ( self ) <EOL> class TestJointOps ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . word = word = '<STR_LIT>' <EOL> self . otherword = '<STR_LIT>' <EOL> self . letters = '<STR_LIT>' <EOL> self . s = self . thetype ( word ) <EOL> self . d = dict . fromkeys ( word ) <EOL> def test_new_or_init ( self ) : <EOL> self . assertRaises ( TypeError , self . thetype , [ ] , <NUM_LIT:2> ) <EOL> self . assertRaises ( TypeError , set ( ) . __init__ , a = <NUM_LIT:1> ) <EOL> def test_uniquification ( self ) : <EOL> actual = sorted ( self . s ) <EOL> expected = sorted ( self . d ) <EOL> self . assertEqual ( actual , expected ) <EOL> self . assertRaises ( PassThru , self . thetype , check_pass_thru ( ) ) <EOL> self . assertRaises ( TypeError , self . thetype , [ [ ] ] ) <EOL> def test_len ( self ) : <EOL> self . assertEqual ( len ( self . s ) , len ( self . d ) ) <EOL> def test_contains ( self ) : <EOL> for c in self . letters : <EOL> self . assertEqual ( c in self . s , c in self . d ) <EOL> self . assertRaises ( TypeError , self . s . __contains__ , [ [ ] ] ) <EOL> s = self . thetype ( [ frozenset ( self . letters ) ] ) <EOL> self . assertIn ( self . thetype ( self . letters ) , s ) <EOL> def test_union ( self ) : <EOL> u = self . s . union ( self . otherword ) <EOL> for c in self . letters : <EOL> self . assertEqual ( c in u , c in self . d or c in self . otherword ) <EOL> self . assertEqual ( self . s , self . thetype ( self . word ) ) <EOL> self . assertEqual ( type ( u ) , self . thetype ) <EOL> self . assertRaises ( PassThru , self . s . union , check_pass_thru ( ) ) <EOL> self . assertRaises ( TypeError , self . s . union , [ [ ] ] ) <EOL> for C in set , frozenset , dict . fromkeys , str , unicode , list , tuple : <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . union ( C ( '<STR_LIT>' ) ) , set ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . union ( C ( '<STR_LIT>' ) ) , set ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . union ( C ( '<STR_LIT>' ) ) , set ( '<STR_LIT:abc>' ) ) <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . union ( C ( '<STR_LIT>' ) ) , set ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . union ( C ( '<STR_LIT>' ) , C ( '<STR_LIT>' ) ) , set ( '<STR_LIT>' ) ) <EOL> x = self . thetype ( ) <EOL> self . assertEqual ( x . union ( set ( [ <NUM_LIT:1> ] ) , x , set ( [ <NUM_LIT:2> ] ) ) , self . thetype ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) ) <EOL> def test_or ( self ) : <EOL> i = self . s . union ( self . otherword ) <EOL> self . assertEqual ( self . s | set ( self . otherword ) , i ) <EOL> self . assertEqual ( self . s | frozenset ( self . otherword ) , i ) <EOL> try : <EOL> self . s | self . otherword <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_intersection ( self ) : <EOL> i = self . s . intersection ( self . otherword ) <EOL> for c in self . letters : <EOL> self . assertEqual ( c in i , c in self . d and c in self . otherword ) <EOL> self . assertEqual ( self . s , self . thetype ( self . word ) ) <EOL> self . assertEqual ( type ( i ) , self . thetype ) <EOL> self . assertRaises ( PassThru , self . s . intersection , check_pass_thru ( ) ) <EOL> for C in set , frozenset , dict . fromkeys , str , unicode , list , tuple : <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . intersection ( C ( '<STR_LIT>' ) ) , set ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . intersection ( C ( '<STR_LIT>' ) ) , set ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . intersection ( C ( '<STR_LIT>' ) ) , set ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . intersection ( C ( '<STR_LIT>' ) ) , set ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . intersection ( C ( '<STR_LIT>' ) , C ( '<STR_LIT>' ) ) , set ( '<STR_LIT:b>' ) ) <EOL> s = self . thetype ( '<STR_LIT>' ) <EOL> z = s . intersection ( ) <EOL> if self . thetype == frozenset ( ) : <EOL> self . assertEqual ( id ( s ) , id ( z ) ) <EOL> else : <EOL> self . assertNotEqual ( id ( s ) , id ( z ) ) <EOL> def test_isdisjoint ( self ) : <EOL> def f ( s1 , s2 ) : <EOL> '<STR_LIT>' <EOL> return not set ( s1 ) . intersection ( s2 ) <EOL> for larg in '<STR_LIT>' , '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT:abc>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' : <EOL> s1 = self . thetype ( larg ) <EOL> for rarg in '<STR_LIT>' , '<STR_LIT:a>' , '<STR_LIT>' , '<STR_LIT:abc>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' : <EOL> for C in set , frozenset , dict . fromkeys , str , unicode , list , tuple : <EOL> s2 = C ( rarg ) <EOL> actual = s1 . isdisjoint ( s2 ) <EOL> expected = f ( s1 , s2 ) <EOL> self . assertEqual ( actual , expected ) <EOL> self . assertTrue ( actual is True or actual is False ) <EOL> def test_and ( self ) : <EOL> i = self . s . intersection ( self . otherword ) <EOL> self . assertEqual ( self . s & set ( self . otherword ) , i ) <EOL> self . assertEqual ( self . s & frozenset ( self . otherword ) , i ) <EOL> try : <EOL> self . s & self . otherword <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_difference ( self ) : <EOL> i = self . s . difference ( self . otherword ) <EOL> for c in self . letters : <EOL> self . assertEqual ( c in i , c in self . d and c not in self . otherword ) <EOL> self . assertEqual ( self . s , self . thetype ( self . word ) ) <EOL> self . assertEqual ( type ( i ) , self . thetype ) <EOL> self . assertRaises ( PassThru , self . s . difference , check_pass_thru ( ) ) <EOL> self . assertRaises ( TypeError , self . s . difference , [ [ ] ] ) <EOL> for C in set , frozenset , dict . fromkeys , str , unicode , list , tuple : <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . difference ( C ( '<STR_LIT>' ) ) , set ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . difference ( C ( '<STR_LIT>' ) ) , set ( '<STR_LIT:abc>' ) ) <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . difference ( C ( '<STR_LIT>' ) ) , set ( '<STR_LIT:a>' ) ) <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . difference ( C ( '<STR_LIT>' ) ) , set ( '<STR_LIT:abc>' ) ) <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . difference ( ) , set ( '<STR_LIT:abc>' ) ) <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . difference ( C ( '<STR_LIT:a>' ) , C ( '<STR_LIT:b>' ) ) , set ( '<STR_LIT:c>' ) ) <EOL> def test_sub ( self ) : <EOL> i = self . s . difference ( self . otherword ) <EOL> self . assertEqual ( self . s - set ( self . otherword ) , i ) <EOL> self . assertEqual ( self . s - frozenset ( self . otherword ) , i ) <EOL> try : <EOL> self . s - self . otherword <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_symmetric_difference ( self ) : <EOL> i = self . s . symmetric_difference ( self . otherword ) <EOL> for c in self . letters : <EOL> self . assertEqual ( c in i , ( c in self . d ) ^ ( c in self . otherword ) ) <EOL> self . assertEqual ( self . s , self . thetype ( self . word ) ) <EOL> self . assertEqual ( type ( i ) , self . thetype ) <EOL> self . assertRaises ( PassThru , self . s . symmetric_difference , check_pass_thru ( ) ) <EOL> self . assertRaises ( TypeError , self . s . symmetric_difference , [ [ ] ] ) <EOL> for C in set , frozenset , dict . fromkeys , str , unicode , list , tuple : <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . symmetric_difference ( C ( '<STR_LIT>' ) ) , set ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . symmetric_difference ( C ( '<STR_LIT>' ) ) , set ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . symmetric_difference ( C ( '<STR_LIT>' ) ) , set ( '<STR_LIT:a>' ) ) <EOL> self . assertEqual ( self . thetype ( '<STR_LIT>' ) . symmetric_difference ( C ( '<STR_LIT>' ) ) , set ( '<STR_LIT>' ) ) <EOL> def test_xor ( self ) : <EOL> i = self . s . symmetric_difference ( self . otherword ) <EOL> self . assertEqual ( self . s ^ set ( self . otherword ) , i ) <EOL> self . assertEqual ( self . s ^ frozenset ( self . otherword ) , i ) <EOL> try : <EOL> self . s ^ self . otherword <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_equality ( self ) : <EOL> self . assertEqual ( self . s , set ( self . word ) ) <EOL> self . assertEqual ( self . s , frozenset ( self . word ) ) <EOL> self . assertEqual ( self . s == self . word , False ) <EOL> self . assertNotEqual ( self . s , set ( self . otherword ) ) <EOL> self . assertNotEqual ( self . s , frozenset ( self . otherword ) ) <EOL> self . assertEqual ( self . s != self . word , True ) <EOL> def test_setOfFrozensets ( self ) : <EOL> t = map ( frozenset , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> s = self . thetype ( t ) <EOL> self . assertEqual ( len ( s ) , <NUM_LIT:3> ) <EOL> def test_compare ( self ) : <EOL> self . assertRaises ( TypeError , self . s . __cmp__ , self . s ) <EOL> def test_sub_and_super ( self ) : <EOL> p , q , r = map ( self . thetype , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertTrue ( p < q ) <EOL> self . assertTrue ( p <= q ) <EOL> self . assertTrue ( q <= q ) <EOL> self . assertTrue ( q > p ) <EOL> self . assertTrue ( q >= p ) <EOL> self . assertFalse ( q < r ) <EOL> self . assertFalse ( q <= r ) <EOL> self . assertFalse ( q > r ) <EOL> self . assertFalse ( q >= r ) <EOL> self . assertTrue ( set ( '<STR_LIT:a>' ) . issubset ( '<STR_LIT:abc>' ) ) <EOL> self . assertTrue ( set ( '<STR_LIT:abc>' ) . issuperset ( '<STR_LIT:a>' ) ) <EOL> self . assertFalse ( set ( '<STR_LIT:a>' ) . issubset ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( set ( '<STR_LIT>' ) . issuperset ( '<STR_LIT:a>' ) ) <EOL> def test_pickling ( self ) : <EOL> for i in range ( pickle . HIGHEST_PROTOCOL + <NUM_LIT:1> ) : <EOL> p = pickle . dumps ( self . s , i ) <EOL> dup = pickle . loads ( p ) <EOL> self . assertEqual ( self . s , dup , "<STR_LIT>" % ( self . s , dup ) ) <EOL> if type ( self . s ) not in ( set , frozenset ) : <EOL> self . s . x = <NUM_LIT:10> <EOL> p = pickle . dumps ( self . s , i ) <EOL> dup = pickle . loads ( p ) <EOL> self . assertEqual ( self . s . x , dup . x ) <EOL> def test_deepcopy ( self ) : <EOL> class Tracer : <EOL> def __init__ ( self , value ) : <EOL> self . value = value <EOL> def __hash__ ( self ) : <EOL> return self . value <EOL> def __deepcopy__ ( self , memo = None ) : <EOL> return Tracer ( self . value + <NUM_LIT:1> ) <EOL> t = Tracer ( <NUM_LIT:10> ) <EOL> s = self . thetype ( [ t ] ) <EOL> dup = copy . deepcopy ( s ) <EOL> self . assertNotEqual ( id ( s ) , id ( dup ) ) <EOL> for elem in dup : <EOL> newt = elem <EOL> self . assertNotEqual ( id ( t ) , id ( newt ) ) <EOL> self . assertEqual ( t . value + <NUM_LIT:1> , newt . value ) <EOL> def test_gc ( self ) : <EOL> class A : <EOL> pass <EOL> s = set ( A ( ) for i in xrange ( <NUM_LIT:1000> ) ) <EOL> for elem in s : <EOL> elem . cycle = s <EOL> elem . sub = elem <EOL> elem . set = set ( [ elem ] ) <EOL> def test_subclass_with_custom_hash ( self ) : <EOL> class H ( self . thetype ) : <EOL> def __hash__ ( self ) : <EOL> return int ( id ( self ) & <NUM_LIT> ) <EOL> s = H ( ) <EOL> f = set ( ) <EOL> f . add ( s ) <EOL> self . assertIn ( s , f ) <EOL> f . remove ( s ) <EOL> f . add ( s ) <EOL> f . discard ( s ) <EOL> def test_badcmp ( self ) : <EOL> s = self . thetype ( [ BadCmp ( ) ] ) <EOL> self . assertRaises ( RuntimeError , self . thetype , [ BadCmp ( ) , BadCmp ( ) ] ) <EOL> self . assertRaises ( RuntimeError , s . __contains__ , BadCmp ( ) ) <EOL> if hasattr ( s , '<STR_LIT>' ) : <EOL> self . assertRaises ( RuntimeError , s . add , BadCmp ( ) ) <EOL> self . assertRaises ( RuntimeError , s . discard , BadCmp ( ) ) <EOL> self . assertRaises ( RuntimeError , s . remove , BadCmp ( ) ) <EOL> def test_cyclical_repr ( self ) : <EOL> w = ReprWrapper ( ) <EOL> s = self . thetype ( [ w ] ) <EOL> w . value = s <EOL> name = repr ( s ) . partition ( '<STR_LIT:(>' ) [ <NUM_LIT:0> ] <EOL> self . assertEqual ( repr ( s ) , '<STR_LIT>' % ( name , name ) ) <EOL> def test_cyclical_print ( self ) : <EOL> w = ReprWrapper ( ) <EOL> s = self . thetype ( [ w ] ) <EOL> w . value = s <EOL> fo = open ( test_support . TESTFN , "<STR_LIT:wb>" ) <EOL> try : <EOL> print >> fo , s , <EOL> fo . close ( ) <EOL> fo = open ( test_support . TESTFN , "<STR_LIT:rb>" ) <EOL> self . assertEqual ( fo . read ( ) , repr ( s ) ) <EOL> finally : <EOL> fo . close ( ) <EOL> test_support . unlink ( test_support . TESTFN ) <EOL> def test_do_not_rehash_dict_keys ( self ) : <EOL> n = <NUM_LIT:10> <EOL> d = dict . fromkeys ( map ( HashCountingInt , xrange ( n ) ) ) <EOL> self . assertEqual ( sum ( elem . hash_count for elem in d ) , n ) <EOL> s = self . thetype ( d ) <EOL> self . assertEqual ( sum ( elem . hash_count for elem in d ) , n ) <EOL> s . difference ( d ) <EOL> self . assertEqual ( sum ( elem . hash_count for elem in d ) , n ) <EOL> if hasattr ( s , '<STR_LIT>' ) : <EOL> s . symmetric_difference_update ( d ) <EOL> self . assertEqual ( sum ( elem . hash_count for elem in d ) , n ) <EOL> d2 = dict . fromkeys ( set ( d ) ) <EOL> self . assertEqual ( sum ( elem . hash_count for elem in d ) , n ) <EOL> d3 = dict . fromkeys ( frozenset ( d ) ) <EOL> self . assertEqual ( sum ( elem . hash_count for elem in d ) , n ) <EOL> d3 = dict . fromkeys ( frozenset ( d ) , <NUM_LIT> ) <EOL> self . assertEqual ( sum ( elem . hash_count for elem in d ) , n ) <EOL> self . assertEqual ( d3 , dict . fromkeys ( d , <NUM_LIT> ) ) <EOL> def test_container_iterator ( self ) : <EOL> class C ( object ) : <EOL> pass <EOL> obj = C ( ) <EOL> ref = weakref . ref ( obj ) <EOL> container = set ( [ obj , <NUM_LIT:1> ] ) <EOL> obj . x = iter ( container ) <EOL> del obj , container <EOL> gc . collect ( ) <EOL> class TestSet ( TestJointOps ) : <EOL> thetype = set <EOL> def test_init ( self ) : <EOL> s = self . thetype ( ) <EOL> s . __init__ ( self . word ) <EOL> self . assertEqual ( s , set ( self . word ) ) <EOL> s . __init__ ( self . otherword ) <EOL> self . assertEqual ( s , set ( self . otherword ) ) <EOL> self . assertRaises ( TypeError , s . __init__ , s , <NUM_LIT:2> ) ; <EOL> self . assertRaises ( TypeError , s . __init__ , <NUM_LIT:1> ) ; <EOL> def test_constructor_identity ( self ) : <EOL> s = self . thetype ( range ( <NUM_LIT:3> ) ) <EOL> t = self . thetype ( s ) <EOL> self . assertNotEqual ( id ( s ) , id ( t ) ) <EOL> def test_hash ( self ) : <EOL> self . assertRaises ( TypeError , hash , self . s ) <EOL> def test_clear ( self ) : <EOL> self . s . clear ( ) <EOL> self . assertEqual ( self . s , set ( ) ) <EOL> self . assertEqual ( len ( self . s ) , <NUM_LIT:0> ) <EOL> def test_copy ( self ) : <EOL> dup = self . s . copy ( ) <EOL> self . assertEqual ( self . s , dup ) <EOL> self . assertNotEqual ( id ( self . s ) , id ( dup ) ) <EOL> def test_add ( self ) : <EOL> self . s . add ( '<STR_LIT>' ) <EOL> self . assertIn ( '<STR_LIT>' , self . s ) <EOL> dup = self . s . copy ( ) <EOL> self . s . add ( '<STR_LIT>' ) <EOL> self . assertEqual ( self . s , dup ) <EOL> self . assertRaises ( TypeError , self . s . add , [ ] ) <EOL> def test_remove ( self ) : <EOL> self . s . remove ( '<STR_LIT:a>' ) <EOL> self . assertNotIn ( '<STR_LIT:a>' , self . s ) <EOL> self . assertRaises ( KeyError , self . s . remove , '<STR_LIT>' ) <EOL> self . assertRaises ( TypeError , self . s . remove , [ ] ) <EOL> s = self . thetype ( [ frozenset ( self . word ) ] ) <EOL> self . assertIn ( self . thetype ( self . word ) , s ) <EOL> s . remove ( self . thetype ( self . word ) ) <EOL> self . assertNotIn ( self . thetype ( self . word ) , s ) <EOL> self . assertRaises ( KeyError , self . s . remove , self . thetype ( self . word ) ) <EOL> def test_remove_keyerror_unpacking ( self ) : <EOL> for v1 in [ '<STR_LIT>' , ( <NUM_LIT:1> , ) ] : <EOL> try : <EOL> self . s . remove ( v1 ) <EOL> except KeyError , e : <EOL> v2 = e . args [ <NUM_LIT:0> ] <EOL> self . assertEqual ( v1 , v2 ) <EOL> else : <EOL> self . fail ( ) <EOL> def test_remove_keyerror_set ( self ) : <EOL> key = self . thetype ( [ <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> try : <EOL> self . s . remove ( key ) <EOL> except KeyError as e : <EOL> self . assertTrue ( e . args [ <NUM_LIT:0> ] is key , <EOL> "<STR_LIT>" . format ( key , <EOL> e . args [ <NUM_LIT:0> ] ) ) <EOL> else : <EOL> self . fail ( ) <EOL> def test_discard ( self ) : <EOL> self . s . discard ( '<STR_LIT:a>' ) <EOL> self . assertNotIn ( '<STR_LIT:a>' , self . s ) <EOL> self . s . discard ( '<STR_LIT>' ) <EOL> self . assertRaises ( TypeError , self . s . discard , [ ] ) <EOL> s = self . thetype ( [ frozenset ( self . word ) ] ) <EOL> self . assertIn ( self . thetype ( self . word ) , s ) <EOL> s . discard ( self . thetype ( self . word ) ) <EOL> self . assertNotIn ( self . thetype ( self . word ) , s ) <EOL> s . discard ( self . thetype ( self . word ) ) <EOL> def test_pop ( self ) : <EOL> for i in xrange ( len ( self . s ) ) : <EOL> elem = self . s . pop ( ) <EOL> self . assertNotIn ( elem , self . s ) <EOL> self . assertRaises ( KeyError , self . s . pop ) <EOL> def test_update ( self ) : <EOL> retval = self . s . update ( self . otherword ) <EOL> self . assertEqual ( retval , None ) <EOL> for c in ( self . word + self . otherword ) : <EOL> self . assertIn ( c , self . s ) <EOL> self . assertRaises ( PassThru , self . s . update , check_pass_thru ( ) ) <EOL> self . assertRaises ( TypeError , self . s . update , [ [ ] ] ) <EOL> for p , q in ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT:abc>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> for C in set , frozenset , dict . fromkeys , str , unicode , list , tuple : <EOL> s = self . thetype ( '<STR_LIT>' ) <EOL> self . assertEqual ( s . update ( C ( p ) ) , None ) <EOL> self . assertEqual ( s , set ( q ) ) <EOL> for p in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> q = '<STR_LIT>' <EOL> for C in set , frozenset , dict . fromkeys , str , unicode , list , tuple : <EOL> s = self . thetype ( '<STR_LIT>' ) <EOL> self . assertEqual ( s . update ( C ( p ) , C ( q ) ) , None ) <EOL> self . assertEqual ( s , set ( s ) | set ( p ) | set ( q ) ) <EOL> def test_ior ( self ) : <EOL> self . s |= set ( self . otherword ) <EOL> for c in ( self . word + self . otherword ) : <EOL> self . assertIn ( c , self . s ) <EOL> def test_intersection_update ( self ) : <EOL> retval = self . s . intersection_update ( self . otherword ) <EOL> self . assertEqual ( retval , None ) <EOL> for c in ( self . word + self . otherword ) : <EOL> if c in self . otherword and c in self . word : <EOL> self . assertIn ( c , self . s ) <EOL> else : <EOL> self . assertNotIn ( c , self . s ) <EOL> self . assertRaises ( PassThru , self . s . intersection_update , check_pass_thru ( ) ) <EOL> self . assertRaises ( TypeError , self . s . intersection_update , [ [ ] ] ) <EOL> for p , q in ( ( '<STR_LIT>' , '<STR_LIT:c>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> for C in set , frozenset , dict . fromkeys , str , unicode , list , tuple : <EOL> s = self . thetype ( '<STR_LIT>' ) <EOL> self . assertEqual ( s . intersection_update ( C ( p ) ) , None ) <EOL> self . assertEqual ( s , set ( q ) ) <EOL> ss = '<STR_LIT>' <EOL> s = self . thetype ( ss ) <EOL> t = '<STR_LIT>' <EOL> self . assertEqual ( s . intersection_update ( C ( p ) , C ( t ) ) , None ) <EOL> self . assertEqual ( s , set ( '<STR_LIT>' ) & set ( p ) & set ( t ) ) <EOL> def test_iand ( self ) : <EOL> self . s &= set ( self . otherword ) <EOL> for c in ( self . word + self . otherword ) : <EOL> if c in self . otherword and c in self . word : <EOL> self . assertIn ( c , self . s ) <EOL> else : <EOL> self . assertNotIn ( c , self . s ) <EOL> def test_difference_update ( self ) : <EOL> retval = self . s . difference_update ( self . otherword ) <EOL> self . assertEqual ( retval , None ) <EOL> for c in ( self . word + self . otherword ) : <EOL> if c in self . word and c not in self . otherword : <EOL> self . assertIn ( c , self . s ) <EOL> else : <EOL> self . assertNotIn ( c , self . s ) <EOL> self . assertRaises ( PassThru , self . s . difference_update , check_pass_thru ( ) ) <EOL> self . assertRaises ( TypeError , self . s . difference_update , [ [ ] ] ) <EOL> self . assertRaises ( TypeError , self . s . symmetric_difference_update , [ [ ] ] ) <EOL> for p , q in ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT:abc>' ) , ( '<STR_LIT>' , '<STR_LIT:a>' ) , ( '<STR_LIT>' , '<STR_LIT:abc>' ) ) : <EOL> for C in set , frozenset , dict . fromkeys , str , unicode , list , tuple : <EOL> s = self . thetype ( '<STR_LIT>' ) <EOL> self . assertEqual ( s . difference_update ( C ( p ) ) , None ) <EOL> self . assertEqual ( s , set ( q ) ) <EOL> s = self . thetype ( '<STR_LIT>' ) <EOL> s . difference_update ( ) <EOL> self . assertEqual ( s , self . thetype ( '<STR_LIT>' ) ) <EOL> s = self . thetype ( '<STR_LIT>' ) <EOL> s . difference_update ( C ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( s , self . thetype ( '<STR_LIT>' ) ) <EOL> s = self . thetype ( '<STR_LIT>' ) <EOL> s . difference_update ( C ( '<STR_LIT>' ) , C ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( s , self . thetype ( '<STR_LIT>' ) ) <EOL> def test_isub ( self ) : <EOL> self . s -= set ( self . otherword ) <EOL> for c in ( self . word + self . otherword ) : <EOL> if c in self . word and c not in self . otherword : <EOL> self . assertIn ( c , self . s ) <EOL> else : <EOL> self . assertNotIn ( c , self . s ) <EOL> def test_symmetric_difference_update ( self ) : <EOL> retval = self . s . symmetric_difference_update ( self . otherword ) <EOL> self . assertEqual ( retval , None ) <EOL> for c in ( self . word + self . otherword ) : <EOL> if ( c in self . word ) ^ ( c in self . otherword ) : <EOL> self . assertIn ( c , self . s ) <EOL> else : <EOL> self . assertNotIn ( c , self . s ) <EOL> self . assertRaises ( PassThru , self . s . symmetric_difference_update , check_pass_thru ( ) ) <EOL> self . assertRaises ( TypeError , self . s . symmetric_difference_update , [ [ ] ] ) <EOL> for p , q in ( ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT:a>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) : <EOL> for C in set , frozenset , dict . fromkeys , str , unicode , list , tuple : <EOL> s = self . thetype ( '<STR_LIT>' ) <EOL> self . assertEqual ( s . symmetric_difference_update ( C ( p ) ) , None ) <EOL> self . assertEqual ( s , set ( q ) ) <EOL> def test_ixor ( self ) : <EOL> self . s ^= set ( self . otherword ) <EOL> for c in ( self . word + self . otherword ) : <EOL> if ( c in self . word ) ^ ( c in self . otherword ) : <EOL> self . assertIn ( c , self . s ) <EOL> else : <EOL> self . assertNotIn ( c , self . s ) <EOL> def test_inplace_on_self ( self ) : <EOL> t = self . s . copy ( ) <EOL> t |= t <EOL> self . assertEqual ( t , self . s ) <EOL> t &= t <EOL> self . assertEqual ( t , self . s ) <EOL> t -= t <EOL> self . assertEqual ( t , self . thetype ( ) ) <EOL> t = self . s . copy ( ) <EOL> t ^= t <EOL> self . assertEqual ( t , self . thetype ( ) ) <EOL> def test_weakref ( self ) : <EOL> s = self . thetype ( '<STR_LIT>' ) <EOL> p = weakref . proxy ( s ) <EOL> self . assertEqual ( str ( p ) , str ( s ) ) <EOL> s = None <EOL> @ unittest . skipUnless ( hasattr ( set , "<STR_LIT>" ) , <EOL> '<STR_LIT>' ) <EOL> def test_c_api ( self ) : <EOL> self . assertEqual ( set ( ) . test_c_api ( ) , True ) <EOL> class SetSubclass ( set ) : <EOL> pass <EOL> class TestSetSubclass ( TestSet ) : <EOL> thetype = SetSubclass <EOL> class SetSubclassWithKeywordArgs ( set ) : <EOL> def __init__ ( self , iterable = [ ] , newarg = None ) : <EOL> set . __init__ ( self , iterable ) <EOL> class TestSetSubclassWithKeywordArgs ( TestSet ) : <EOL> def test_keywords_in_subclass ( self ) : <EOL> '<STR_LIT>' <EOL> SetSubclassWithKeywordArgs ( newarg = <NUM_LIT:1> ) <EOL> class TestFrozenSet ( TestJointOps ) : <EOL> thetype = frozenset <EOL> def test_init ( self ) : <EOL> s = self . thetype ( self . word ) <EOL> s . __init__ ( self . otherword ) <EOL> self . assertEqual ( s , set ( self . word ) ) <EOL> def test_singleton_empty_frozenset ( self ) : <EOL> f = frozenset ( ) <EOL> efs = [ frozenset ( ) , frozenset ( [ ] ) , frozenset ( ( ) ) , frozenset ( '<STR_LIT>' ) , <EOL> frozenset ( ) , frozenset ( [ ] ) , frozenset ( ( ) ) , frozenset ( '<STR_LIT>' ) , <EOL> frozenset ( xrange ( <NUM_LIT:0> ) ) , frozenset ( frozenset ( ) ) , <EOL> frozenset ( f ) , f ] <EOL> self . assertEqual ( len ( set ( map ( id , efs ) ) ) , <NUM_LIT:1> ) <EOL> def test_constructor_identity ( self ) : <EOL> s = self . thetype ( range ( <NUM_LIT:3> ) ) <EOL> t = self . thetype ( s ) <EOL> self . assertEqual ( id ( s ) , id ( t ) ) <EOL> def test_hash ( self ) : <EOL> self . assertEqual ( hash ( self . thetype ( '<STR_LIT>' ) ) , <EOL> hash ( self . thetype ( '<STR_LIT>' ) ) ) <EOL> n = <NUM_LIT:100> <EOL> seq = [ randrange ( n ) for i in xrange ( n ) ] <EOL> results = set ( ) <EOL> for i in xrange ( <NUM_LIT:200> ) : <EOL> shuffle ( seq ) <EOL> results . add ( hash ( self . thetype ( seq ) ) ) <EOL> self . assertEqual ( len ( results ) , <NUM_LIT:1> ) <EOL> def test_copy ( self ) : <EOL> dup = self . s . copy ( ) <EOL> self . assertEqual ( id ( self . s ) , id ( dup ) ) <EOL> def test_frozen_as_dictkey ( self ) : <EOL> seq = range ( <NUM_LIT:10> ) + list ( '<STR_LIT>' ) + [ '<STR_LIT>' ] <EOL> key1 = self . thetype ( seq ) <EOL> key2 = self . thetype ( reversed ( seq ) ) <EOL> self . assertEqual ( key1 , key2 ) <EOL> self . assertNotEqual ( id ( key1 ) , id ( key2 ) ) <EOL> d = { } <EOL> d [ key1 ] = <NUM_LIT> <EOL> self . assertEqual ( d [ key2 ] , <NUM_LIT> ) <EOL> def test_hash_caching ( self ) : <EOL> f = self . thetype ( '<STR_LIT>' ) <EOL> self . assertEqual ( hash ( f ) , hash ( f ) ) <EOL> def test_hash_effectiveness ( self ) : <EOL> n = <NUM_LIT> <EOL> hashvalues = set ( ) <EOL> addhashvalue = hashvalues . add <EOL> elemmasks = [ ( i + <NUM_LIT:1> , <NUM_LIT:1> << i ) for i in range ( n ) ] <EOL> for i in xrange ( <NUM_LIT:2> ** n ) : <EOL> addhashvalue ( hash ( frozenset ( [ e for e , m in elemmasks if m & i ] ) ) ) <EOL> self . assertEqual ( len ( hashvalues ) , <NUM_LIT:2> ** n ) <EOL> class FrozenSetSubclass ( frozenset ) : <EOL> pass <EOL> class TestFrozenSetSubclass ( TestFrozenSet ) : <EOL> thetype = FrozenSetSubclass <EOL> def test_constructor_identity ( self ) : <EOL> s = self . thetype ( range ( <NUM_LIT:3> ) ) <EOL> t = self . thetype ( s ) <EOL> self . assertNotEqual ( id ( s ) , id ( t ) ) <EOL> def test_copy ( self ) : <EOL> dup = self . s . copy ( ) <EOL> self . assertNotEqual ( id ( self . s ) , id ( dup ) ) <EOL> def test_nested_empty_constructor ( self ) : <EOL> s = self . thetype ( ) <EOL> t = self . thetype ( s ) <EOL> self . assertEqual ( s , t ) <EOL> def test_singleton_empty_frozenset ( self ) : <EOL> Frozenset = self . thetype <EOL> f = frozenset ( ) <EOL> F = Frozenset ( ) <EOL> efs = [ Frozenset ( ) , Frozenset ( [ ] ) , Frozenset ( ( ) ) , Frozenset ( '<STR_LIT>' ) , <EOL> Frozenset ( ) , Frozenset ( [ ] ) , Frozenset ( ( ) ) , Frozenset ( '<STR_LIT>' ) , <EOL> Frozenset ( xrange ( <NUM_LIT:0> ) ) , Frozenset ( Frozenset ( ) ) , <EOL> Frozenset ( frozenset ( ) ) , f , F , Frozenset ( f ) , Frozenset ( F ) ] <EOL> self . assertEqual ( len ( set ( map ( id , efs ) ) ) , len ( efs ) ) <EOL> empty_set = set ( ) <EOL> class TestBasicOps ( unittest . TestCase ) : <EOL> def test_repr ( self ) : <EOL> if self . repr is not None : <EOL> self . assertEqual ( repr ( self . set ) , self . repr ) <EOL> def check_repr_against_values ( self ) : <EOL> text = repr ( self . set ) <EOL> self . assertTrue ( text . startswith ( '<STR_LIT:{>' ) ) <EOL> self . assertTrue ( text . endswith ( '<STR_LIT:}>' ) ) <EOL> result = text [ <NUM_LIT:1> : - <NUM_LIT:1> ] . split ( '<STR_LIT:U+002CU+0020>' ) <EOL> result . sort ( ) <EOL> sorted_repr_values = [ repr ( value ) for value in self . values ] <EOL> sorted_repr_values . sort ( ) <EOL> self . assertEqual ( result , sorted_repr_values ) <EOL> def test_print ( self ) : <EOL> fo = open ( test_support . TESTFN , "<STR_LIT:wb>" ) <EOL> try : <EOL> print >> fo , self . set , <EOL> fo . close ( ) <EOL> fo = open ( test_support . TESTFN , "<STR_LIT:rb>" ) <EOL> self . assertEqual ( fo . read ( ) , repr ( self . set ) ) <EOL> finally : <EOL> fo . close ( ) <EOL> test_support . unlink ( test_support . TESTFN ) <EOL> def test_length ( self ) : <EOL> self . assertEqual ( len ( self . set ) , self . length ) <EOL> def test_self_equality ( self ) : <EOL> self . assertEqual ( self . set , self . set ) <EOL> def test_equivalent_equality ( self ) : <EOL> self . assertEqual ( self . set , self . dup ) <EOL> def test_copy ( self ) : <EOL> self . assertEqual ( self . set . copy ( ) , self . dup ) <EOL> def test_self_union ( self ) : <EOL> result = self . set | self . set <EOL> self . assertEqual ( result , self . dup ) <EOL> def test_empty_union ( self ) : <EOL> result = self . set | empty_set <EOL> self . assertEqual ( result , self . dup ) <EOL> def test_union_empty ( self ) : <EOL> result = empty_set | self . set <EOL> self . assertEqual ( result , self . dup ) <EOL> def test_self_intersection ( self ) : <EOL> result = self . set & self . set <EOL> self . assertEqual ( result , self . dup ) <EOL> def test_empty_intersection ( self ) : <EOL> result = self . set & empty_set <EOL> self . assertEqual ( result , empty_set ) <EOL> def test_intersection_empty ( self ) : <EOL> result = empty_set & self . set <EOL> self . assertEqual ( result , empty_set ) <EOL> def test_self_isdisjoint ( self ) : <EOL> result = self . set . isdisjoint ( self . set ) <EOL> self . assertEqual ( result , not self . set ) <EOL> def test_empty_isdisjoint ( self ) : <EOL> result = self . set . isdisjoint ( empty_set ) <EOL> self . assertEqual ( result , True ) <EOL> def test_isdisjoint_empty ( self ) : <EOL> result = empty_set . isdisjoint ( self . set ) <EOL> self . assertEqual ( result , True ) <EOL> def test_self_symmetric_difference ( self ) : <EOL> result = self . set ^ self . set <EOL> self . assertEqual ( result , empty_set ) <EOL> def test_empty_symmetric_difference ( self ) : <EOL> result = self . set ^ empty_set <EOL> self . assertEqual ( result , self . set ) <EOL> def test_self_difference ( self ) : <EOL> result = self . set - self . set <EOL> self . assertEqual ( result , empty_set ) <EOL> def test_empty_difference ( self ) : <EOL> result = self . set - empty_set <EOL> self . assertEqual ( result , self . dup ) <EOL> def test_empty_difference_rev ( self ) : <EOL> result = empty_set - self . set <EOL> self . assertEqual ( result , empty_set ) <EOL> def test_iteration ( self ) : <EOL> for v in self . set : <EOL> self . assertIn ( v , self . values ) <EOL> setiter = iter ( self . set ) <EOL> self . assertEqual ( setiter . __length_hint__ ( ) , len ( self . set ) ) <EOL> def test_pickling ( self ) : <EOL> for proto in range ( pickle . HIGHEST_PROTOCOL + <NUM_LIT:1> ) : <EOL> p = pickle . dumps ( self . set , proto ) <EOL> copy = pickle . loads ( p ) <EOL> self . assertEqual ( self . set , copy , <EOL> "<STR_LIT>" % ( self . set , copy ) ) <EOL> class TestBasicOpsEmpty ( TestBasicOps ) : <EOL> def setUp ( self ) : <EOL> self . case = "<STR_LIT>" <EOL> self . values = [ ] <EOL> self . set = set ( self . values ) <EOL> self . dup = set ( self . values ) <EOL> self . length = <NUM_LIT:0> <EOL> self . repr = "<STR_LIT>" <EOL> class TestBasicOpsSingleton ( TestBasicOps ) : <EOL> def setUp ( self ) : <EOL> self . case = "<STR_LIT>" <EOL> self . values = [ <NUM_LIT:3> ] <EOL> self . set = set ( self . values ) <EOL> self . dup = set ( self . values ) <EOL> self . length = <NUM_LIT:1> <EOL> self . repr = "<STR_LIT>" <EOL> def test_in ( self ) : <EOL> self . assertIn ( <NUM_LIT:3> , self . set ) <EOL> def test_not_in ( self ) : <EOL> self . assertNotIn ( <NUM_LIT:2> , self . set ) <EOL> class TestBasicOpsTuple ( TestBasicOps ) : <EOL> def setUp ( self ) : <EOL> self . case = "<STR_LIT>" <EOL> self . values = [ ( <NUM_LIT:0> , "<STR_LIT>" ) ] <EOL> self . set = set ( self . values ) <EOL> self . dup = set ( self . values ) <EOL> self . length = <NUM_LIT:1> <EOL> self . repr = "<STR_LIT>" <EOL> def test_in ( self ) : <EOL> self . assertIn ( ( <NUM_LIT:0> , "<STR_LIT>" ) , self . set ) <EOL> def test_not_in ( self ) : <EOL> self . assertNotIn ( <NUM_LIT:9> , self . set ) <EOL> class TestBasicOpsTriple ( TestBasicOps ) : <EOL> def setUp ( self ) : <EOL> self . case = "<STR_LIT>" <EOL> self . values = [ <NUM_LIT:0> , "<STR_LIT>" , operator . add ] <EOL> self . set = set ( self . values ) <EOL> self . dup = set ( self . values ) <EOL> self . length = <NUM_LIT:3> <EOL> self . repr = None <EOL> class TestBasicOpsString ( TestBasicOps ) : <EOL> def setUp ( self ) : <EOL> self . case = "<STR_LIT>" <EOL> self . values = [ "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" ] <EOL> self . set = set ( self . values ) <EOL> self . dup = set ( self . values ) <EOL> self . length = <NUM_LIT:3> <EOL> def test_repr ( self ) : <EOL> self . check_repr_against_values ( ) <EOL> class TestBasicOpsUnicode ( TestBasicOps ) : <EOL> def setUp ( self ) : <EOL> self . case = "<STR_LIT>" <EOL> self . values = [ u"<STR_LIT:a>" , u"<STR_LIT:b>" , u"<STR_LIT:c>" ] <EOL> self . set = set ( self . values ) <EOL> self . dup = set ( self . values ) <EOL> self . length = <NUM_LIT:3> <EOL> def test_repr ( self ) : <EOL> self . check_repr_against_values ( ) <EOL> class TestBasicOpsMixedStringUnicode ( TestBasicOps ) : <EOL> def setUp ( self ) : <EOL> self . case = "<STR_LIT>" <EOL> self . values = [ "<STR_LIT:a>" , "<STR_LIT:b>" , u"<STR_LIT:a>" , u"<STR_LIT:b>" ] <EOL> self . set = set ( self . values ) <EOL> self . dup = set ( self . values ) <EOL> self . length = <NUM_LIT:4> <EOL> def test_repr ( self ) : <EOL> with test_support . check_warnings ( ) : <EOL> self . check_repr_against_values ( ) <EOL> def baditer ( ) : <EOL> raise TypeError <EOL> yield True <EOL> def gooditer ( ) : <EOL> yield True <EOL> class TestExceptionPropagation ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def test_instanceWithException ( self ) : <EOL> self . assertRaises ( TypeError , set , baditer ( ) ) <EOL> def test_instancesWithoutException ( self ) : <EOL> set ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> set ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> set ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> } ) <EOL> set ( xrange ( <NUM_LIT:3> ) ) <EOL> set ( '<STR_LIT:abc>' ) <EOL> set ( gooditer ( ) ) <EOL> def test_changingSizeWhileIterating ( self ) : <EOL> s = set ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> try : <EOL> for i in s : <EOL> s . update ( [ <NUM_LIT:4> ] ) <EOL> except RuntimeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> class TestSetOfSets ( unittest . TestCase ) : <EOL> def test_constructor ( self ) : <EOL> inner = frozenset ( [ <NUM_LIT:1> ] ) <EOL> outer = set ( [ inner ] ) <EOL> element = outer . pop ( ) <EOL> self . assertEqual ( type ( element ) , frozenset ) <EOL> outer . add ( inner ) <EOL> outer . remove ( inner ) <EOL> self . assertEqual ( outer , set ( ) ) <EOL> outer . discard ( inner ) <EOL> class TestBinaryOps ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . set = set ( ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> ) ) <EOL> def test_eq ( self ) : <EOL> self . assertEqual ( self . set , set ( { <NUM_LIT:2> : <NUM_LIT:1> , <NUM_LIT:4> : <NUM_LIT:3> , <NUM_LIT:6> : <NUM_LIT:5> } ) ) <EOL> def test_union_subset ( self ) : <EOL> result = self . set | set ( [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( result , set ( ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> ) ) ) <EOL> def test_union_superset ( self ) : <EOL> result = self . set | set ( [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] ) <EOL> self . assertEqual ( result , set ( [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] ) ) <EOL> def test_union_overlap ( self ) : <EOL> result = self . set | set ( [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ) <EOL> self . assertEqual ( result , set ( [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) ) <EOL> def test_union_non_overlap ( self ) : <EOL> result = self . set | set ( [ <NUM_LIT:8> ] ) <EOL> self . assertEqual ( result , set ( [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] ) ) <EOL> def test_intersection_subset ( self ) : <EOL> result = self . set & set ( ( <NUM_LIT:2> , <NUM_LIT:4> ) ) <EOL> self . assertEqual ( result , set ( ( <NUM_LIT:2> , <NUM_LIT:4> ) ) ) <EOL> def test_intersection_superset ( self ) : <EOL> result = self . set & set ( [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] ) <EOL> self . assertEqual ( result , set ( [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> ] ) ) <EOL> def test_intersection_overlap ( self ) : <EOL> result = self . set & set ( [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ) <EOL> self . assertEqual ( result , set ( [ <NUM_LIT:4> ] ) ) <EOL> def test_intersection_non_overlap ( self ) : <EOL> result = self . set & set ( [ <NUM_LIT:8> ] ) <EOL> self . assertEqual ( result , empty_set ) <EOL> def test_isdisjoint_subset ( self ) : <EOL> result = self . set . isdisjoint ( set ( ( <NUM_LIT:2> , <NUM_LIT:4> ) ) ) <EOL> self . assertEqual ( result , False ) <EOL> def test_isdisjoint_superset ( self ) : <EOL> result = self . set . isdisjoint ( set ( [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] ) ) <EOL> self . assertEqual ( result , False ) <EOL> def test_isdisjoint_overlap ( self ) : <EOL> result = self . set . isdisjoint ( set ( [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ) ) <EOL> self . assertEqual ( result , False ) <EOL> def test_isdisjoint_non_overlap ( self ) : <EOL> result = self . set . isdisjoint ( set ( [ <NUM_LIT:8> ] ) ) <EOL> self . assertEqual ( result , True ) <EOL> def test_sym_difference_subset ( self ) : <EOL> result = self . set ^ set ( ( <NUM_LIT:2> , <NUM_LIT:4> ) ) <EOL> self . assertEqual ( result , set ( [ <NUM_LIT:6> ] ) ) <EOL> def test_sym_difference_superset ( self ) : <EOL> result = self . set ^ set ( ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ) ) <EOL> self . assertEqual ( result , set ( [ <NUM_LIT:8> ] ) ) <EOL> def test_sym_difference_overlap ( self ) : <EOL> result = self . set ^ set ( ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ) ) <EOL> self . assertEqual ( result , set ( [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:6> ] ) ) <EOL> def test_sym_difference_non_overlap ( self ) : <EOL> result = self . set ^ set ( [ <NUM_LIT:8> ] ) <EOL> self . assertEqual ( result , set ( [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] ) ) <EOL> def test_cmp ( self ) : <EOL> a , b = set ( '<STR_LIT:a>' ) , set ( '<STR_LIT:b>' ) <EOL> self . assertRaises ( TypeError , cmp , a , b ) <EOL> self . assertEqual ( cmp ( a , a ) , <NUM_LIT:0> ) <EOL> class TestUpdateOps ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . set = set ( ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> ) ) <EOL> def test_union_subset ( self ) : <EOL> self . set |= set ( [ <NUM_LIT:2> ] ) <EOL> self . assertEqual ( self . set , set ( ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> ) ) ) <EOL> def test_union_superset ( self ) : <EOL> self . set |= set ( [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] ) <EOL> self . assertEqual ( self . set , set ( [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] ) ) <EOL> def test_union_overlap ( self ) : <EOL> self . set |= set ( [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ) <EOL> self . assertEqual ( self . set , set ( [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) ) <EOL> def test_union_non_overlap ( self ) : <EOL> self . set |= set ( [ <NUM_LIT:8> ] ) <EOL> self . assertEqual ( self . set , set ( [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] ) ) <EOL> def test_union_method_call ( self ) : <EOL> self . set . update ( set ( [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ) ) <EOL> self . assertEqual ( self . set , set ( [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) ) <EOL> def test_intersection_subset ( self ) : <EOL> self . set &= set ( ( <NUM_LIT:2> , <NUM_LIT:4> ) ) <EOL> self . assertEqual ( self . set , set ( ( <NUM_LIT:2> , <NUM_LIT:4> ) ) ) <EOL> def test_intersection_superset ( self ) : <EOL> self . set &= set ( [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] ) <EOL> self . assertEqual ( self . set , set ( [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> ] ) ) <EOL> def test_intersection_overlap ( self ) : <EOL> self . set &= set ( [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ) <EOL> self . assertEqual ( self . set , set ( [ <NUM_LIT:4> ] ) ) <EOL> def test_intersection_non_overlap ( self ) : <EOL> self . set &= set ( [ <NUM_LIT:8> ] ) <EOL> self . assertEqual ( self . set , empty_set ) <EOL> def test_intersection_method_call ( self ) : <EOL> self . set . intersection_update ( set ( [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ) ) <EOL> self . assertEqual ( self . set , set ( [ <NUM_LIT:4> ] ) ) <EOL> def test_sym_difference_subset ( self ) : <EOL> self . set ^= set ( ( <NUM_LIT:2> , <NUM_LIT:4> ) ) <EOL> self . assertEqual ( self . set , set ( [ <NUM_LIT:6> ] ) ) <EOL> def test_sym_difference_superset ( self ) : <EOL> self . set ^= set ( ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ) ) <EOL> self . assertEqual ( self . set , set ( [ <NUM_LIT:8> ] ) ) <EOL> def test_sym_difference_overlap ( self ) : <EOL> self . set ^= set ( ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ) ) <EOL> self . assertEqual ( self . set , set ( [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:6> ] ) ) <EOL> def test_sym_difference_non_overlap ( self ) : <EOL> self . set ^= set ( [ <NUM_LIT:8> ] ) <EOL> self . assertEqual ( self . set , set ( [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ] ) ) <EOL> def test_sym_difference_method_call ( self ) : <EOL> self . set . symmetric_difference_update ( set ( [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ) ) <EOL> self . assertEqual ( self . set , set ( [ <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT:6> ] ) ) <EOL> def test_difference_subset ( self ) : <EOL> self . set -= set ( ( <NUM_LIT:2> , <NUM_LIT:4> ) ) <EOL> self . assertEqual ( self . set , set ( [ <NUM_LIT:6> ] ) ) <EOL> def test_difference_superset ( self ) : <EOL> self . set -= set ( ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> ) ) <EOL> self . assertEqual ( self . set , set ( [ ] ) ) <EOL> def test_difference_overlap ( self ) : <EOL> self . set -= set ( ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ) ) <EOL> self . assertEqual ( self . set , set ( [ <NUM_LIT:2> , <NUM_LIT:6> ] ) ) <EOL> def test_difference_non_overlap ( self ) : <EOL> self . set -= set ( [ <NUM_LIT:8> ] ) <EOL> self . assertEqual ( self . set , set ( [ <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> ] ) ) <EOL> def test_difference_method_call ( self ) : <EOL> self . set . difference_update ( set ( [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ) ) <EOL> self . assertEqual ( self . set , set ( [ <NUM_LIT:2> , <NUM_LIT:6> ] ) ) <EOL> class TestMutate ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . values = [ "<STR_LIT:a>" , "<STR_LIT:b>" , "<STR_LIT:c>" ] <EOL> self . set = set ( self . values ) <EOL> def test_add_present ( self ) : <EOL> self . set . add ( "<STR_LIT:c>" ) <EOL> self . assertEqual ( self . set , set ( "<STR_LIT:abc>" ) ) <EOL> def test_add_absent ( self ) : <EOL> self . set . add ( "<STR_LIT:d>" ) <EOL> self . assertEqual ( self . set , set ( "<STR_LIT>" ) ) <EOL> def test_add_until_full ( self ) : <EOL> tmp = set ( ) <EOL> expected_len = <NUM_LIT:0> <EOL> for v in self . values : <EOL> tmp . add ( v ) <EOL> expected_len += <NUM_LIT:1> <EOL> self . assertEqual ( len ( tmp ) , expected_len ) <EOL> self . assertEqual ( tmp , self . set ) <EOL> def test_remove_present ( self ) : <EOL> self . set . remove ( "<STR_LIT:b>" ) <EOL> self . assertEqual ( self . set , set ( "<STR_LIT>" ) ) <EOL> def test_remove_absent ( self ) : <EOL> try : <EOL> self . set . remove ( "<STR_LIT:d>" ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except LookupError : <EOL> pass <EOL> def test_remove_until_empty ( self ) : <EOL> expected_len = len ( self . set ) <EOL> for v in self . values : <EOL> self . set . remove ( v ) <EOL> expected_len -= <NUM_LIT:1> <EOL> self . assertEqual ( len ( self . set ) , expected_len ) <EOL> def test_discard_present ( self ) : <EOL> self . set . discard ( "<STR_LIT:c>" ) <EOL> self . assertEqual ( self . set , set ( "<STR_LIT>" ) ) <EOL> def test_discard_absent ( self ) : <EOL> self . set . discard ( "<STR_LIT:d>" ) <EOL> self . assertEqual ( self . set , set ( "<STR_LIT:abc>" ) ) <EOL> def test_clear ( self ) : <EOL> self . set . clear ( ) <EOL> self . assertEqual ( len ( self . set ) , <NUM_LIT:0> ) <EOL> def test_pop ( self ) : <EOL> popped = { } <EOL> while self . set : <EOL> popped [ self . set . pop ( ) ] = None <EOL> self . assertEqual ( len ( popped ) , len ( self . values ) ) <EOL> for v in self . values : <EOL> self . assertIn ( v , popped ) <EOL> def test_update_empty_tuple ( self ) : <EOL> self . set . update ( ( ) ) <EOL> self . assertEqual ( self . set , set ( self . values ) ) <EOL> def test_update_unit_tuple_overlap ( self ) : <EOL> self . set . update ( ( "<STR_LIT:a>" , ) ) <EOL> self . assertEqual ( self . set , set ( self . values ) ) <EOL> def test_update_unit_tuple_non_overlap ( self ) : <EOL> self . set . update ( ( "<STR_LIT:a>" , "<STR_LIT:z>" ) ) <EOL> self . assertEqual ( self . set , set ( self . values + [ "<STR_LIT:z>" ] ) ) <EOL> class TestSubsets ( unittest . TestCase ) : <EOL> case2method = { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> reverse = { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:<>" : "<STR_LIT:>>" , <EOL> "<STR_LIT:>>" : "<STR_LIT:<>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> def test_issubset ( self ) : <EOL> x = self . left <EOL> y = self . right <EOL> for case in "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:<>" , "<STR_LIT>" , "<STR_LIT:>>" , "<STR_LIT>" : <EOL> expected = case in self . cases <EOL> result = eval ( "<STR_LIT:x>" + case + "<STR_LIT:y>" , locals ( ) ) <EOL> self . assertEqual ( result , expected ) <EOL> if case in TestSubsets . case2method : <EOL> method = getattr ( x , TestSubsets . case2method [ case ] ) <EOL> result = method ( y ) <EOL> self . assertEqual ( result , expected ) <EOL> rcase = TestSubsets . reverse [ case ] <EOL> result = eval ( "<STR_LIT:y>" + rcase + "<STR_LIT:x>" , locals ( ) ) <EOL> self . assertEqual ( result , expected ) <EOL> if rcase in TestSubsets . case2method : <EOL> method = getattr ( y , TestSubsets . case2method [ rcase ] ) <EOL> result = method ( x ) <EOL> self . assertEqual ( result , expected ) <EOL> class TestSubsetEqualEmpty ( TestSubsets ) : <EOL> left = set ( ) <EOL> right = set ( ) <EOL> name = "<STR_LIT>" <EOL> cases = "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" <EOL> class TestSubsetEqualNonEmpty ( TestSubsets ) : <EOL> left = set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> right = set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> name = "<STR_LIT>" <EOL> cases = "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" <EOL> class TestSubsetEmptyNonEmpty ( TestSubsets ) : <EOL> left = set ( ) <EOL> right = set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> name = "<STR_LIT>" <EOL> cases = "<STR_LIT>" , "<STR_LIT:<>" , "<STR_LIT>" <EOL> class TestSubsetPartial ( TestSubsets ) : <EOL> left = set ( [ <NUM_LIT:1> ] ) <EOL> right = set ( [ <NUM_LIT:1> , <NUM_LIT:2> ] ) <EOL> name = "<STR_LIT>" <EOL> cases = "<STR_LIT>" , "<STR_LIT:<>" , "<STR_LIT>" <EOL> class TestSubsetNonOverlap ( TestSubsets ) : <EOL> left = set ( [ <NUM_LIT:1> ] ) <EOL> right = set ( [ <NUM_LIT:2> ] ) <EOL> name = "<STR_LIT>" <EOL> cases = "<STR_LIT>" <EOL> class TestOnlySetsInBinaryOps ( unittest . TestCase ) : <EOL> def test_eq_ne ( self ) : <EOL> self . assertEqual ( self . other == self . set , False ) <EOL> self . assertEqual ( self . set == self . other , False ) <EOL> self . assertEqual ( self . other != self . set , True ) <EOL> self . assertEqual ( self . set != self . other , True ) <EOL> def test_update_operator ( self ) : <EOL> try : <EOL> self . set |= self . other <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_update ( self ) : <EOL> if self . otherIsIterable : <EOL> self . set . update ( self . other ) <EOL> else : <EOL> self . assertRaises ( TypeError , self . set . update , self . other ) <EOL> def test_union ( self ) : <EOL> self . assertRaises ( TypeError , lambda : self . set | self . other ) <EOL> self . assertRaises ( TypeError , lambda : self . other | self . set ) <EOL> if self . otherIsIterable : <EOL> self . set . union ( self . other ) <EOL> else : <EOL> self . assertRaises ( TypeError , self . set . union , self . other ) <EOL> def test_intersection_update_operator ( self ) : <EOL> try : <EOL> self . set &= self . other <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_intersection_update ( self ) : <EOL> if self . otherIsIterable : <EOL> self . set . intersection_update ( self . other ) <EOL> else : <EOL> self . assertRaises ( TypeError , <EOL> self . set . intersection_update , <EOL> self . other ) <EOL> def test_intersection ( self ) : <EOL> self . assertRaises ( TypeError , lambda : self . set & self . other ) <EOL> self . assertRaises ( TypeError , lambda : self . other & self . set ) <EOL> if self . otherIsIterable : <EOL> self . set . intersection ( self . other ) <EOL> else : <EOL> self . assertRaises ( TypeError , self . set . intersection , self . other ) <EOL> def test_sym_difference_update_operator ( self ) : <EOL> try : <EOL> self . set ^= self . other <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_sym_difference_update ( self ) : <EOL> if self . otherIsIterable : <EOL> self . set . symmetric_difference_update ( self . other ) <EOL> else : <EOL> self . assertRaises ( TypeError , <EOL> self . set . symmetric_difference_update , <EOL> self . other ) <EOL> def test_sym_difference ( self ) : <EOL> self . assertRaises ( TypeError , lambda : self . set ^ self . other ) <EOL> self . assertRaises ( TypeError , lambda : self . other ^ self . set ) <EOL> if self . otherIsIterable : <EOL> self . set . symmetric_difference ( self . other ) <EOL> else : <EOL> self . assertRaises ( TypeError , self . set . symmetric_difference , self . other ) <EOL> def test_difference_update_operator ( self ) : <EOL> try : <EOL> self . set -= self . other <EOL> except TypeError : <EOL> pass <EOL> else : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def test_difference_update ( self ) : <EOL> if self . otherIsIterable : <EOL> self . set . difference_update ( self . other ) <EOL> else : <EOL> self . assertRaises ( TypeError , <EOL> self . set . difference_update , <EOL> self . other ) <EOL> def test_difference ( self ) : <EOL> self . assertRaises ( TypeError , lambda : self . set - self . other ) <EOL> self . assertRaises ( TypeError , lambda : self . other - self . set ) <EOL> if self . otherIsIterable : <EOL> self . set . difference ( self . other ) <EOL> else : <EOL> self . assertRaises ( TypeError , self . set . difference , self . other ) <EOL> class TestOnlySetsNumeric ( TestOnlySetsInBinaryOps ) : <EOL> def setUp ( self ) : <EOL> self . set = set ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> self . other = <NUM_LIT> <EOL> self . otherIsIterable = False <EOL> class TestOnlySetsDict ( TestOnlySetsInBinaryOps ) : <EOL> def setUp ( self ) : <EOL> self . set = set ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> self . other = { <NUM_LIT:1> : <NUM_LIT:2> , <NUM_LIT:3> : <NUM_LIT:4> } <EOL> self . otherIsIterable = True <EOL> class TestOnlySetsTuple ( TestOnlySetsInBinaryOps ) : <EOL> def setUp ( self ) : <EOL> self . set = set ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> self . other = ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:6> ) <EOL> self . otherIsIterable = True <EOL> class TestOnlySetsString ( TestOnlySetsInBinaryOps ) : <EOL> def setUp ( self ) : <EOL> self . set = set ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> self . other = '<STR_LIT:abc>' <EOL> self . otherIsIterable = True <EOL> class TestOnlySetsGenerator ( TestOnlySetsInBinaryOps ) : <EOL> def setUp ( self ) : <EOL> def gen ( ) : <EOL> for i in xrange ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:2> ) : <EOL> yield i <EOL> self . set = set ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> self . other = gen ( ) <EOL> self . otherIsIterable = True <EOL> class TestCopying ( unittest . TestCase ) : <EOL> def test_copy ( self ) : <EOL> dup = list ( self . set . copy ( ) ) <EOL> self . assertEqual ( len ( dup ) , len ( self . set ) ) <EOL> for el in self . set : <EOL> self . assertIn ( el , dup ) <EOL> pos = dup . index ( el ) <EOL> self . assertIs ( el , dup . pop ( pos ) ) <EOL> self . assertFalse ( dup ) <EOL> def test_deep_copy ( self ) : <EOL> dup = copy . deepcopy ( self . set ) <EOL> self . assertSetEqual ( dup , self . set ) <EOL> class TestCopyingEmpty ( TestCopying ) : <EOL> def setUp ( self ) : <EOL> self . set = set ( ) <EOL> class TestCopyingSingleton ( TestCopying ) : <EOL> def setUp ( self ) : <EOL> self . set = set ( [ "<STR_LIT:hello>" ] ) <EOL> class TestCopyingTriple ( TestCopying ) : <EOL> def setUp ( self ) : <EOL> self . set = set ( [ "<STR_LIT>" , <NUM_LIT:0> , None ] ) <EOL> class TestCopyingTuple ( TestCopying ) : <EOL> def setUp ( self ) : <EOL> self . set = set ( [ ( <NUM_LIT:1> , <NUM_LIT:2> ) ] ) <EOL> class TestCopyingNested ( TestCopying ) : <EOL> def setUp ( self ) : <EOL> self . set = set ( [ ( ( <NUM_LIT:1> , <NUM_LIT:2> ) , ( <NUM_LIT:3> , <NUM_LIT:4> ) ) ] ) <EOL> class TestIdentities ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . a = set ( '<STR_LIT>' ) <EOL> self . b = set ( '<STR_LIT>' ) <EOL> def test_binopsVsSubsets ( self ) : <EOL> a , b = self . a , self . b <EOL> self . assertTrue ( a - b < a ) <EOL> self . assertTrue ( b - a < b ) <EOL> self . assertTrue ( a & b < a ) <EOL> self . assertTrue ( a & b < b ) <EOL> self . assertTrue ( a | b > a ) <EOL> self . assertTrue ( a | b > b ) <EOL> self . assertTrue ( a ^ b < a | b ) <EOL> def test_commutativity ( self ) : <EOL> a , b = self . a , self . b <EOL> self . assertEqual ( a & b , b & a ) <EOL> self . assertEqual ( a | b , b | a ) <EOL> self . assertEqual ( a ^ b , b ^ a ) <EOL> if a != b : <EOL> self . assertNotEqual ( a - b , b - a ) <EOL> def test_summations ( self ) : <EOL> a , b = self . a , self . b <EOL> self . assertEqual ( ( a - b ) | ( a & b ) | ( b - a ) , a | b ) <EOL> self . assertEqual ( ( a & b ) | ( a ^ b ) , a | b ) <EOL> self . assertEqual ( a | ( b - a ) , a | b ) <EOL> self . assertEqual ( ( a - b ) | b , a | b ) <EOL> self . assertEqual ( ( a - b ) | ( a & b ) , a ) <EOL> self . assertEqual ( ( b - a ) | ( a & b ) , b ) <EOL> self . assertEqual ( ( a - b ) | ( b - a ) , a ^ b ) <EOL> def test_exclusion ( self ) : <EOL> a , b , zero = self . a , self . b , set ( ) <EOL> self . assertEqual ( ( a - b ) & b , zero ) <EOL> self . assertEqual ( ( b - a ) & a , zero ) <EOL> self . assertEqual ( ( a & b ) & ( a ^ b ) , zero ) <EOL> def R ( seqn ) : <EOL> '<STR_LIT>' <EOL> for i in seqn : <EOL> yield i <EOL> class G : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> def __getitem__ ( self , i ) : <EOL> return self . seqn [ i ] <EOL> class I : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> self . i = <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def next ( self ) : <EOL> if self . i >= len ( self . seqn ) : raise StopIteration <EOL> v = self . seqn [ self . i ] <EOL> self . i += <NUM_LIT:1> <EOL> return v <EOL> class Ig : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> self . i = <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> for val in self . seqn : <EOL> yield val <EOL> class X : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> self . i = <NUM_LIT:0> <EOL> def next ( self ) : <EOL> if self . i >= len ( self . seqn ) : raise StopIteration <EOL> v = self . seqn [ self . i ] <EOL> self . i += <NUM_LIT:1> <EOL> return v <EOL> class N : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> self . i = <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> return self <EOL> class E : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> self . seqn = seqn <EOL> self . i = <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def next ( self ) : <EOL> <NUM_LIT:3> // <NUM_LIT:0> <EOL> class S : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , seqn ) : <EOL> pass <EOL> def __iter__ ( self ) : <EOL> return self <EOL> def next ( self ) : <EOL> raise StopIteration <EOL> from itertools import chain , imap <EOL> def L ( seqn ) : <EOL> '<STR_LIT>' <EOL> return chain ( imap ( lambda x : x , R ( Ig ( G ( seqn ) ) ) ) ) <EOL> class TestVariousIteratorArgs ( unittest . TestCase ) : <EOL> def test_constructor ( self ) : <EOL> for cons in ( set , frozenset ) : <EOL> for s in ( "<STR_LIT>" , "<STR_LIT>" , range ( <NUM_LIT:1000> ) , ( '<STR_LIT>' , <NUM_LIT> ) , xrange ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> self . assertSetEqual ( cons ( g ( s ) ) , set ( g ( s ) ) ) <EOL> self . assertRaises ( TypeError , cons , X ( s ) ) <EOL> self . assertRaises ( TypeError , cons , N ( s ) ) <EOL> self . assertRaises ( ZeroDivisionError , cons , E ( s ) ) <EOL> def test_inline_methods ( self ) : <EOL> s = set ( '<STR_LIT>' ) <EOL> for data in ( "<STR_LIT>" , "<STR_LIT>" , range ( <NUM_LIT:1000> ) , ( '<STR_LIT>' , <NUM_LIT> ) , xrange ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) , '<STR_LIT>' ) : <EOL> for meth in ( s . union , s . intersection , s . difference , s . symmetric_difference , s . isdisjoint ) : <EOL> for g in ( G , I , Ig , L , R ) : <EOL> expected = meth ( data ) <EOL> actual = meth ( g ( data ) ) <EOL> if isinstance ( expected , bool ) : <EOL> self . assertEqual ( actual , expected ) <EOL> else : <EOL> self . assertSetEqual ( actual , expected ) <EOL> self . assertRaises ( TypeError , meth , X ( s ) ) <EOL> self . assertRaises ( TypeError , meth , N ( s ) ) <EOL> self . assertRaises ( ZeroDivisionError , meth , E ( s ) ) <EOL> def test_inplace_methods ( self ) : <EOL> for data in ( "<STR_LIT>" , "<STR_LIT>" , range ( <NUM_LIT:1000> ) , ( '<STR_LIT>' , <NUM_LIT> ) , xrange ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> ) , '<STR_LIT>' ) : <EOL> for methname in ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) : <EOL> for g in ( G , I , Ig , S , L , R ) : <EOL> s = set ( '<STR_LIT>' ) <EOL> t = s . copy ( ) <EOL> getattr ( s , methname ) ( list ( g ( data ) ) ) <EOL> getattr ( t , methname ) ( g ( data ) ) <EOL> self . assertSetEqual ( s , t ) <EOL> self . assertRaises ( TypeError , getattr ( set ( '<STR_LIT>' ) , methname ) , X ( data ) ) <EOL> self . assertRaises ( TypeError , getattr ( set ( '<STR_LIT>' ) , methname ) , N ( data ) ) <EOL> self . assertRaises ( ZeroDivisionError , getattr ( set ( '<STR_LIT>' ) , methname ) , E ( data ) ) <EOL> class bad_eq : <EOL> def __eq__ ( self , other ) : <EOL> if be_bad : <EOL> set2 . clear ( ) <EOL> raise ZeroDivisionError <EOL> return self is other <EOL> def __hash__ ( self ) : <EOL> return <NUM_LIT:0> <EOL> class bad_dict_clear : <EOL> def __eq__ ( self , other ) : <EOL> if be_bad : <EOL> dict2 . clear ( ) <EOL> return self is other <EOL> def __hash__ ( self ) : <EOL> return <NUM_LIT:0> <EOL> class TestWeirdBugs ( unittest . TestCase ) : <EOL> def test_8420_set_merge ( self ) : <EOL> global be_bad , set2 , dict2 <EOL> be_bad = False <EOL> set1 = { bad_eq ( ) } <EOL> set2 = { bad_eq ( ) for i in range ( <NUM_LIT> ) } <EOL> be_bad = True <EOL> self . assertRaises ( ZeroDivisionError , set1 . update , set2 ) <EOL> be_bad = False <EOL> set1 = { bad_dict_clear ( ) } <EOL> dict2 = { bad_dict_clear ( ) : None } <EOL> be_bad = True <EOL> set1 . symmetric_difference_update ( dict2 ) <EOL> def powerset ( U ) : <EOL> """<STR_LIT>""" <EOL> U = iter ( U ) <EOL> try : <EOL> x = frozenset ( [ U . next ( ) ] ) <EOL> for S in powerset ( U ) : <EOL> yield S <EOL> yield S | x <EOL> except StopIteration : <EOL> yield frozenset ( ) <EOL> def cube ( n ) : <EOL> """<STR_LIT>""" <EOL> singletons = [ frozenset ( [ x ] ) for x in range ( n ) ] <EOL> return dict ( [ ( x , frozenset ( [ x ^ s for s in singletons ] ) ) <EOL> for x in powerset ( range ( n ) ) ] ) <EOL> def linegraph ( G ) : <EOL> """<STR_LIT>""" <EOL> L = { } <EOL> for x in G : <EOL> for y in G [ x ] : <EOL> nx = [ frozenset ( [ x , z ] ) for z in G [ x ] if z != y ] <EOL> ny = [ frozenset ( [ y , z ] ) for z in G [ y ] if z != x ] <EOL> L [ frozenset ( [ x , y ] ) ] = frozenset ( nx + ny ) <EOL> return L <EOL> def faces ( G ) : <EOL> '<STR_LIT>' <EOL> f = set ( ) <EOL> for v1 , edges in G . items ( ) : <EOL> for v2 in edges : <EOL> for v3 in G [ v2 ] : <EOL> if v1 == v3 : <EOL> continue <EOL> if v1 in G [ v3 ] : <EOL> f . add ( frozenset ( [ v1 , v2 , v3 ] ) ) <EOL> else : <EOL> for v4 in G [ v3 ] : <EOL> if v4 == v2 : <EOL> continue <EOL> if v1 in G [ v4 ] : <EOL> f . add ( frozenset ( [ v1 , v2 , v3 , v4 ] ) ) <EOL> else : <EOL> for v5 in G [ v4 ] : <EOL> if v5 == v3 or v5 == v2 : <EOL> continue <EOL> if v1 in G [ v5 ] : <EOL> f . add ( frozenset ( [ v1 , v2 , v3 , v4 , v5 ] ) ) <EOL> return f <EOL> class TestGraphs ( unittest . TestCase ) : <EOL> def test_cube ( self ) : <EOL> g = cube ( <NUM_LIT:3> ) <EOL> vertices1 = set ( g ) <EOL> self . assertEqual ( len ( vertices1 ) , <NUM_LIT:8> ) <EOL> for edge in g . values ( ) : <EOL> self . assertEqual ( len ( edge ) , <NUM_LIT:3> ) <EOL> vertices2 = set ( v for edges in g . values ( ) for v in edges ) <EOL> self . assertEqual ( vertices1 , vertices2 ) <EOL> cubefaces = faces ( g ) <EOL> self . assertEqual ( len ( cubefaces ) , <NUM_LIT:6> ) <EOL> for face in cubefaces : <EOL> self . assertEqual ( len ( face ) , <NUM_LIT:4> ) <EOL> def test_cuboctahedron ( self ) : <EOL> g = cube ( <NUM_LIT:3> ) <EOL> cuboctahedron = linegraph ( g ) <EOL> self . assertEqual ( len ( cuboctahedron ) , <NUM_LIT:12> ) <EOL> vertices = set ( cuboctahedron ) <EOL> for edges in cuboctahedron . values ( ) : <EOL> self . assertEqual ( len ( edges ) , <NUM_LIT:4> ) <EOL> othervertices = set ( edge for edges in cuboctahedron . values ( ) for edge in edges ) <EOL> self . assertEqual ( vertices , othervertices ) <EOL> cubofaces = faces ( cuboctahedron ) <EOL> facesizes = collections . defaultdict ( int ) <EOL> for face in cubofaces : <EOL> facesizes [ len ( face ) ] += <NUM_LIT:1> <EOL> self . assertEqual ( facesizes [ <NUM_LIT:3> ] , <NUM_LIT:8> ) <EOL> self . assertEqual ( facesizes [ <NUM_LIT:4> ] , <NUM_LIT:6> ) <EOL> for vertex in cuboctahedron : <EOL> edge = vertex <EOL> self . assertEqual ( len ( edge ) , <NUM_LIT:2> ) <EOL> for cubevert in edge : <EOL> self . assertIn ( cubevert , g ) <EOL> def test_main ( verbose = None ) : <EOL> test_classes = ( <EOL> TestSet , <EOL> TestSetSubclass , <EOL> TestSetSubclassWithKeywordArgs , <EOL> TestFrozenSet , <EOL> TestFrozenSetSubclass , <EOL> TestSetOfSets , <EOL> TestExceptionPropagation , <EOL> TestBasicOpsEmpty , <EOL> TestBasicOpsSingleton , <EOL> TestBasicOpsTuple , <EOL> TestBasicOpsTriple , <EOL> TestBinaryOps , <EOL> TestUpdateOps , <EOL> TestMutate , <EOL> TestSubsetEqualEmpty , <EOL> TestSubsetEqualNonEmpty , <EOL> TestSubsetEmptyNonEmpty , <EOL> TestSubsetPartial , <EOL> TestSubsetNonOverlap , <EOL> TestOnlySetsNumeric , <EOL> TestOnlySetsDict , <EOL> TestOnlySetsTuple , <EOL> TestOnlySetsString , <EOL> TestOnlySetsGenerator , <EOL> TestCopyingEmpty , <EOL> TestCopyingSingleton , <EOL> TestCopyingTriple , <EOL> TestCopyingTuple , <EOL> TestCopyingNested , <EOL> TestIdentities , <EOL> TestVariousIteratorArgs , <EOL> TestGraphs , <EOL> TestWeirdBugs , <EOL> ) <EOL> test_support . run_unittest ( * test_classes ) <EOL> if verbose and hasattr ( sys , "<STR_LIT>" ) : <EOL> import gc <EOL> counts = [ None ] * <NUM_LIT:5> <EOL> for i in xrange ( len ( counts ) ) : <EOL> test_support . run_unittest ( * test_classes ) <EOL> gc . collect ( ) <EOL> counts [ i ] = sys . gettotalrefcount ( ) <EOL> print counts <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( verbose = True ) </s>
