<s> """<STR_LIT>""" <EOL> import sys <EOL> import functools <EOL> import itertools <EOL> sys . path . append ( '<STR_LIT:.>' ) <EOL> sys . path . append ( '<STR_LIT:..>' ) <EOL> import IPy <EOL> import unittest <EOL> import random <EOL> if sys . version_info >= ( <NUM_LIT:3> , ) : <EOL> xrange = range <EOL> def iterate_27 ( n ) : <EOL> def wrap ( func ) : <EOL> func . iterations = n <EOL> return func <EOL> return wrap <EOL> def load_tests ( loader , tests , pattern ) : <EOL> def expand ( tests ) : <EOL> if isinstance ( tests , unittest . TestCase ) : <EOL> method_name = tests . _testMethodName <EOL> meth = getattr ( tests , method_name ) <EOL> if hasattr ( meth , '<STR_LIT>' ) : <EOL> tests = unittest . TestSuite ( type ( tests ) ( method_name ) for i in xrange ( meth . iterations ) ) <EOL> else : <EOL> tests = unittest . TestSuite ( expand ( t ) for t in tests ) <EOL> return tests <EOL> return expand ( tests ) <EOL> def iterate_old ( n ) : <EOL> def wrap ( func ) : <EOL> @ functools . wraps ( func ) <EOL> def replacement ( * args ) : <EOL> for i in xrange ( n ) : <EOL> func ( * args ) <EOL> return replacement <EOL> return wrap <EOL> if sys . version_info >= ( <NUM_LIT:2> , <NUM_LIT:7> ) : <EOL> iterate = iterate_27 <EOL> else : <EOL> iterate = iterate_old <EOL> def random_ipv4_prefix ( ) : <EOL> prefixlen = random . randrange ( <NUM_LIT:32> ) <EOL> int_ip = random . randrange ( IPy . MAX_IPV4_ADDRESS ) <EOL> int_ip &= <NUM_LIT> << ( <NUM_LIT:32> - prefixlen ) <EOL> return IPy . IP ( '<STR_LIT:.>' . join ( map ( str , ( int_ip >> <NUM_LIT> , <EOL> ( int_ip >> <NUM_LIT:16> ) & <NUM_LIT> , <EOL> ( int_ip >> <NUM_LIT:8> ) & <NUM_LIT> , <EOL> int_ip & <NUM_LIT> ) ) ) <EOL> + '<STR_LIT>' % prefixlen ) <EOL> class ParseAndBack ( unittest . TestCase ) : <EOL> @ iterate ( <NUM_LIT> ) <EOL> def testRandomValuesv4 ( self ) : <EOL> question = random . randrange ( <NUM_LIT> ) <EOL> self . assertEqual ( IPy . parseAddress ( IPy . intToIp ( question , <NUM_LIT:4> ) ) , ( question , <NUM_LIT:4> ) , hex ( question ) ) <EOL> @ iterate ( <NUM_LIT> ) <EOL> def testRandomValuesv6 ( self ) : <EOL> question = random . randrange ( <NUM_LIT> ) <EOL> self . assertEqual ( IPy . parseAddress ( IPy . intToIp ( question , <NUM_LIT:6> ) ) , ( question , <NUM_LIT:6> ) , hex ( question ) ) <EOL> class TestIPSet ( unittest . TestCase ) : <EOL> @ iterate ( <NUM_LIT:1000> ) <EOL> def testRandomContains ( self ) : <EOL> prefixes = [ random_ipv4_prefix ( ) for i in xrange ( random . randrange ( <NUM_LIT:50> ) ) ] <EOL> question = random_ipv4_prefix ( ) <EOL> answer = any ( question in pfx for pfx in prefixes ) <EOL> ipset = IPy . IPSet ( prefixes ) <EOL> self . assertEqual ( question in ipset , answer , <EOL> "<STR_LIT>" % ( question , ipset , answer , prefixes ) ) <EOL> @ iterate ( <NUM_LIT:1000> ) <EOL> def testRandomDisjoint ( self ) : <EOL> prefixes1 = [ random_ipv4_prefix ( ) for i in xrange ( random . randrange ( <NUM_LIT:50> ) ) ] <EOL> prefixes2 = [ random_ipv4_prefix ( ) for i in xrange ( random . randrange ( <NUM_LIT:50> ) ) ] <EOL> disjoint = True <EOL> for p1 , p2 in itertools . product ( prefixes1 , prefixes2 ) : <EOL> if p1 in p2 or p2 in p1 : <EOL> disjoint = False <EOL> break <EOL> ipset1 = IPy . IPSet ( prefixes1 ) <EOL> ipset2 = IPy . IPSet ( prefixes2 ) <EOL> self . assertEqual ( ipset1 . isdisjoint ( ipset2 ) , disjoint , <EOL> "<STR_LIT>" % ( ipset1 , ipset2 , disjoint ) ) <EOL> self . assertEqual ( ipset2 . isdisjoint ( ipset1 ) , disjoint , <EOL> "<STR_LIT>" % ( ipset2 , ipset1 , disjoint ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
