<s> from guppy . heapy . test import support <EOL> import sys , unittest <EOL> class TestCase ( support . TestCase ) : <EOL> def setUp ( self ) : <EOL> support . TestCase . setUp ( self ) <EOL> self . Path = self . heapy . Path <EOL> def chkrel ( self , src , dst , relstr = None , clas = None ) : <EOL> rel = self . relation ( src , dst ) <EOL> if clas is not None : <EOL> self . assert_ ( isinstance ( rel , clas ) ) <EOL> if relstr is None : <EOL> print rel <EOL> else : <EOL> sr = str ( rel ) <EOL> if sr . startswith ( '<STR_LIT:<>' ) and not relstr . startswith ( '<STR_LIT:<>' ) : <EOL> self . assert_ ( sr . endswith ( '<STR_LIT:>>' ) ) <EOL> sr = sr [ <NUM_LIT:1> : - <NUM_LIT:1> ] . split ( '<STR_LIT:U+002C>' ) <EOL> self . assert_ ( relstr in sr ) <EOL> else : <EOL> self . aseq ( sr , relstr ) <EOL> def chkrelattr ( self , src , * attrs ) : <EOL> for attr in attrs : <EOL> self . chkrel ( src , getattr ( src , attr ) , '<STR_LIT>' + attr ) <EOL> def chkpath ( self , src , dst , expect = None ) : <EOL> rel = self . shpaths ( dst , src ) <EOL> if expect is None : <EOL> print rel <EOL> else : <EOL> li = rel . aslist ( ) <EOL> if len ( li ) == <NUM_LIT:1> : li = li [ <NUM_LIT:0> ] <EOL> self . aseq ( str ( li ) , str ( expect ) , - <NUM_LIT:1> ) <EOL> def relation ( self , src , dst ) : <EOL> return self . Path . relation ( src , dst ) <EOL> def shpaths ( self , dst , src = None , * args , ** kwds ) : <EOL> dst = self . iso ( dst ) <EOL> if src is not None : <EOL> src = self . iso ( src ) <EOL> return dst . get_shpaths ( src , * args , ** kwds ) <EOL> class RelationTestCase ( TestCase ) : <EOL> def test_list_relation ( self ) : <EOL> v1 = '<STR_LIT>' <EOL> v2 = '<STR_LIT>' <EOL> v3 = range ( <NUM_LIT:100> , <NUM_LIT:200> ) <EOL> x = [ v1 , v2 , v3 ] <EOL> def test_cell_relation ( self ) : <EOL> cellvalue = [ ] <EOL> def f ( ) : <EOL> return cellvalue <EOL> self . chkrel ( f . func_closure [ <NUM_LIT:0> ] , cellvalue , '<STR_LIT>' ) <EOL> def test_class_relation ( self ) : <EOL> class T : <EOL> tvar = [ ] <EOL> class U : <EOL> uvar = [ ] <EOL> class V ( U , T ) : <EOL> vvar = [ ] <EOL> self . chkrelattr ( V , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . chkpath ( V , V . uvar , "<STR_LIT>" ) <EOL> self . chkpath ( V , V . tvar , "<STR_LIT>" ) <EOL> self . chkpath ( V , V . vvar , "<STR_LIT>" ) <EOL> def test_code_relation ( self ) : <EOL> def f ( ) : <EOL> a = <NUM_LIT:3> <EOL> return self , a <EOL> co = f . func_code <EOL> self . chkpath ( co , <NUM_LIT:3> , '<STR_LIT>' ) <EOL> self . chkrelattr ( co , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> def test_dict_relation ( self ) : <EOL> k1 = '<STR_LIT>' <EOL> k2 = '<STR_LIT>' <EOL> v1 = '<STR_LIT>' <EOL> v2 = '<STR_LIT>' <EOL> k3 = tuple ( range ( <NUM_LIT:100> ) ) <EOL> v3 = tuple ( range ( <NUM_LIT:100> , <NUM_LIT:200> ) ) <EOL> x = { k1 : v1 , k2 : v2 , k3 : v3 } <EOL> self . chkrel ( x , v1 , "<STR_LIT>" ) <EOL> self . chkrel ( x , v2 , "<STR_LIT>" ) <EOL> self . chkrel ( x , v3 , "<STR_LIT>" ) <EOL> ks = [ str ( self . relation ( x , k1 ) ) , <EOL> str ( self . relation ( x , k2 ) ) , <EOL> str ( self . relation ( x , k3 ) ) ] <EOL> ks . sort ( ) <EOL> self . aseq ( ks , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_dictproxy_relation ( self ) : <EOL> v1 = '<STR_LIT>' <EOL> class T ( object ) : <EOL> k1 = v1 <EOL> x = T . __dict__ <EOL> self . chkpath ( x , v1 , "<STR_LIT>" ) <EOL> self . chkrel ( x , v1 , "<STR_LIT>" ) <EOL> def test_frame_relation ( self ) : <EOL> try : <EOL> <NUM_LIT:1> / <NUM_LIT:0> <EOL> except : <EOL> type , value , traceback = sys . exc_info ( ) <EOL> f = traceback . tb_frame <EOL> f . f_trace = lambda : None <EOL> f . f_exc_type = [ ] <EOL> f . f_exc_value = [ ] <EOL> f . f_exc_traceback = [ ] <EOL> self . chkrelattr ( f , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> a = [ ] <EOL> self . chkrel ( f , a , "<STR_LIT>" , clas = self . Path . R_LOCAL_VAR ) <EOL> x = [ ] <EOL> z = [ ] <EOL> def func ( x , y = <NUM_LIT:3> ) : <EOL> try : <EOL> <NUM_LIT:1> / <NUM_LIT:0> <EOL> except : <EOL> type , value , traceback = sys . exc_info ( ) <EOL> frame = traceback . tb_frame <EOL> return self , frame , z <EOL> _ , frame , __ = func ( <NUM_LIT:0> ) <EOL> del _ , __ <EOL> self . chkrel ( frame , self , "<STR_LIT>" , clas = self . Path . R_CELL ) <EOL> self . chkrel ( f , x , "<STR_LIT>" , clas = self . Path . R_LOCAL_VAR ) <EOL> self . chkrel ( f , z , "<STR_LIT>" , clas = self . Path . R_CELL ) <EOL> self . chkrel ( f , self , "<STR_LIT>" ) <EOL> def test_function_relation ( self ) : <EOL> def f ( x , y = <NUM_LIT:3> ) : <EOL> return self <EOL> f . a = [ ] <EOL> self . chkrelattr ( f , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:a>' ) <EOL> def test_instance_relation ( self ) : <EOL> class T : <EOL> tvar = [ ] <EOL> t = T ( ) <EOL> self . chkrelattr ( t , '<STR_LIT>' , '<STR_LIT>' ) <EOL> t . a = [ ] <EOL> self . chkrelattr ( t , '<STR_LIT:a>' ) <EOL> self . chkpath ( t , t . tvar , "<STR_LIT>" ) <EOL> class U : <EOL> uvar = [ ] <EOL> class V ( U , T ) : <EOL> vvar = [ ] <EOL> v = V ( ) <EOL> self . chkpath ( v , v . uvar , "<STR_LIT>" ) <EOL> self . chkpath ( v , v . tvar , "<STR_LIT>" ) <EOL> self . chkpath ( v , v . vvar , "<STR_LIT>" ) <EOL> def test_instancemethod_relation ( self ) : <EOL> class T : <EOL> def f ( x ) : <EOL> pass <EOL> self . chkrelattr ( T . f , '<STR_LIT>' , '<STR_LIT>' ) <EOL> t = T ( ) <EOL> self . chkrelattr ( t . f , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_list_relation ( self ) : <EOL> v1 = '<STR_LIT>' <EOL> v2 = '<STR_LIT>' <EOL> v3 = range ( <NUM_LIT:100> , <NUM_LIT:200> ) <EOL> x = [ v1 , v2 , v3 ] <EOL> self . chkrel ( x , v1 , '<STR_LIT>' ) <EOL> self . chkrel ( x , v2 , '<STR_LIT>' ) <EOL> self . chkrel ( x , v3 , '<STR_LIT>' ) <EOL> def test_meth_relation ( self ) : <EOL> x = [ ] <EOL> self . chkrel ( x . append , x , '<STR_LIT>' ) <EOL> def test_module_relation ( self ) : <EOL> self . chkrelattr ( unittest , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_nodegraph_relation ( self ) : <EOL> a = <NUM_LIT:0> <EOL> b = <NUM_LIT:1> <EOL> rl = [ a , b ] <EOL> rg = self . heapy . heapyc . NodeGraph ( [ ( a , rl ) , ( b , rl ) ] ) <EOL> self . chkrel ( rg , a , '<STR_LIT>' ) <EOL> self . chkrel ( rg , b , '<STR_LIT>' ) <EOL> self . chkrel ( rg , rl , '<STR_LIT>' ) <EOL> self . chkpath ( rg , a , '<STR_LIT>' ) <EOL> self . chkpath ( rg , rl , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_nodeset_relation ( self ) : <EOL> from guppy . sets import immnodeset , mutnodeset <EOL> if <NUM_LIT:0> : <EOL> x = [ <NUM_LIT:0> , <NUM_LIT:1> , '<STR_LIT:a>' , '<STR_LIT:b>' ] <EOL> x . sort ( lambda a , b : cmp ( id ( a ) , id ( b ) ) ) <EOL> else : <EOL> x = [ '<STR_LIT:a>' ] <EOL> for s in ( immnodeset ( x ) , mutnodeset ( x ) ) : <EOL> for i in range ( len ( x ) ) : <EOL> self . chkrel ( s , x [ i ] , '<STR_LIT>' % i ) <EOL> def test_object_relation ( self ) : <EOL> class T ( object ) : <EOL> __slots__ = '<STR_LIT:a>' , '<STR_LIT:b>' <EOL> t = T ( ) <EOL> a = [ ] <EOL> t . a = a <EOL> b = [ ] <EOL> t . b = b <EOL> self . chkrel ( t , T , '<STR_LIT>' ) <EOL> self . chkrelattr ( t , '<STR_LIT:a>' , '<STR_LIT:b>' ) <EOL> self . failUnlessRaises ( AttributeError , lambda : t . __dict__ ) <EOL> class U ( T ) : <EOL> pass <EOL> u = U ( ) <EOL> u . a = a <EOL> self . chkpath ( u , T , "<STR_LIT>" ) <EOL> self . chkrel ( u , a , '<STR_LIT>' ) <EOL> c = [ ] <EOL> u . c = c <EOL> self . chkrel ( u , c , '<STR_LIT>' ) <EOL> self . chkrel ( u , u . __dict__ , '<STR_LIT>' ) <EOL> class V ( U ) : <EOL> pass <EOL> v = V ( ) <EOL> v . c = c <EOL> self . chkrelattr ( v , '<STR_LIT>' ) <EOL> class W ( V ) : <EOL> __slots__ = '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:b>' <EOL> pass <EOL> w = W ( ) <EOL> w . a = a <EOL> w . b = b <EOL> w . c = c <EOL> w . d = [ ] <EOL> w . e = [ ] <EOL> self . chkrelattr ( w , '<STR_LIT>' , '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:e>' ) <EOL> self . chkpath ( w , w . a , '<STR_LIT>' ) <EOL> self . chkpath ( w , w . b , '<STR_LIT>' ) <EOL> self . chkpath ( w , w . c , '<STR_LIT>' ) <EOL> self . chkpath ( w , w . d , '<STR_LIT>' ) <EOL> self . chkpath ( w , w . e , "<STR_LIT>" ) <EOL> class R ( object ) : <EOL> rvar = [ ] <EOL> class S ( R , T ) : <EOL> svar = [ ] <EOL> s = S ( ) <EOL> s . a = a <EOL> s . b = b <EOL> s . c = c <EOL> self . chkrelattr ( s , '<STR_LIT>' , '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ) <EOL> self . chkpath ( s , s . a , '<STR_LIT>' ) <EOL> self . chkpath ( s , s . b , '<STR_LIT>' ) <EOL> self . chkpath ( s , s . c , "<STR_LIT>" ) <EOL> self . chkpath ( s , s . svar , "<STR_LIT>" ) <EOL> self . chkpath ( s , s . rvar , [ "<STR_LIT>" , <EOL> "<STR_LIT>" ] ) <EOL> self . chkpath ( s , s . __slots__ , "<STR_LIT>" ) <EOL> def test_traceback_relation ( self ) : <EOL> try : <EOL> def g ( ) : <EOL> <NUM_LIT:1> / <NUM_LIT:0> <EOL> g ( ) <EOL> except : <EOL> type , value , traceback = sys . exc_info ( ) <EOL> self . chkrelattr ( traceback , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def test_tuple_relation ( self ) : <EOL> v1 = '<STR_LIT>' <EOL> v2 = '<STR_LIT>' <EOL> v3 = range ( <NUM_LIT:100> , <NUM_LIT:200> ) <EOL> x = ( v1 , v2 , v3 ) <EOL> self . chkrel ( x , v1 , '<STR_LIT>' ) <EOL> self . chkrel ( x , v2 , '<STR_LIT>' ) <EOL> self . chkrel ( x , v3 , '<STR_LIT>' ) <EOL> def test_type_relation ( self ) : <EOL> name = '<STR_LIT:T>' <EOL> base = object <EOL> bases = ( base , ) <EOL> dict = { '<STR_LIT>' : ( '<STR_LIT:a>' , '<STR_LIT:b>' ) } <EOL> T = type ( name , bases , dict ) <EOL> self . chkpath ( T , T . a , "<STR_LIT>" ) <EOL> self . chkpath ( T , T . __slots__ , "<STR_LIT>" ) <EOL> self . chkrelattr ( T , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> class RootTestCase ( TestCase ) : <EOL> def test_1 ( self ) : <EOL> import sys , __builtin__ <EOL> root = self . View . root <EOL> rel = str ( self . relation ( root , sys . modules ) ) <EOL> self . assert_ ( eval ( rel % '<STR_LIT:root>' ) is sys . modules ) <EOL> self . aseq ( rel , '<STR_LIT>' ) <EOL> rel = str ( self . relation ( root , sys . __dict__ ) ) <EOL> self . assert_ ( eval ( rel % '<STR_LIT:root>' ) is sys . __dict__ ) <EOL> self . aseq ( rel , '<STR_LIT>' ) <EOL> rel = str ( self . relation ( root , __builtin__ . __dict__ ) ) <EOL> self . assert_ ( eval ( rel % '<STR_LIT:root>' ) is __builtin__ . __dict__ ) <EOL> self . aseq ( rel , '<STR_LIT>' ) <EOL> if sys . version >= "<STR_LIT>" : <EOL> for name in "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" : <EOL> attr = "<STR_LIT>" % name <EOL> rel = str ( self . relation ( root , getattr ( root , attr ) ) ) <EOL> self . aseq ( rel , '<STR_LIT>' % attr ) <EOL> try : <EOL> <NUM_LIT:1> / <NUM_LIT:0> <EOL> except : <EOL> exc_type , exc_value , exc_traceback = sys . exc_info ( ) <EOL> for name in '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' : <EOL> rel = str ( self . relation ( root , eval ( name ) ) ) <EOL> self . asis ( eval ( rel % '<STR_LIT:root>' ) , eval ( name ) ) <EOL> level = <NUM_LIT:0> <EOL> frame = exc_traceback . tb_frame <EOL> while frame . f_back : <EOL> frame = frame . f_back <EOL> level += <NUM_LIT:1> <EOL> rel = str ( self . relation ( root , frame ) ) <EOL> self . assert_ ( rel . endswith ( '<STR_LIT>' ) ) <EOL> rel = str ( self . relation ( root , exc_traceback . tb_frame ) ) <EOL> import re <EOL> self . asis ( eval ( rel % '<STR_LIT:root>' ) , exc_traceback . tb_frame ) <EOL> self . assert_ ( rel . endswith ( '<STR_LIT>' % level ) ) <EOL> def test_thread ( self ) : <EOL> try : <EOL> import thread <EOL> except ImportError : <EOL> print '<STR_LIT>' <EOL> return <EOL> root = self . View . root <EOL> def task ( self ) : <EOL> try : <EOL> <NUM_LIT:1> / <NUM_LIT:0> <EOL> except : <EOL> exc_type , exc_value , exc_traceback = sys . exc_info ( ) <EOL> self . exc_traceback = exc_traceback <EOL> self . sync = <NUM_LIT:1> <EOL> while self . sync : <EOL> pass <EOL> self . sync = <NUM_LIT:1> <EOL> self . sync = <NUM_LIT:0> <EOL> thread . start_new_thread ( task , ( self , ) ) <EOL> while not self . sync : <EOL> pass <EOL> exc_traceback = self . exc_traceback <EOL> rel = str ( self . relation ( root , exc_traceback ) ) <EOL> self . asis ( eval ( rel % '<STR_LIT:root>' ) , exc_traceback ) <EOL> self . sync = <NUM_LIT:0> <EOL> while not self . sync : <EOL> pass <EOL> def task ( self ) : <EOL> self . test_1 ( ) <EOL> self . sync = <NUM_LIT:1> <EOL> self . sync = <NUM_LIT:0> <EOL> thread . start_new_thread ( task , ( self , ) ) <EOL> while not self . sync : <EOL> pass <EOL> def _test_secondary_interpreter ( self ) : <EOL> try : <EOL> import thread <EOL> except ImportError : <EOL> print '<STR_LIT>' <EOL> return <EOL> import_remote = """<STR_LIT>""" <EOL> self . sync = <NUM_LIT:0> <EOL> thid = self . heapy . heapyc . interpreter ( import_remote , { '<STR_LIT>' : self } ) <EOL> root = self . View . root <EOL> import sys <EOL> sysdict = sys . __dict__ <EOL> rel = str ( self . relation ( root , sysdict ) ) <EOL> self . aseq ( rel , '<STR_LIT>' ) <EOL> while not self . sync : <EOL> pass <EOL> rel = str ( self . relation ( root , self . sysdict ) ) <EOL> self . aseq ( rel , '<STR_LIT>' ) <EOL> self . sync = <NUM_LIT:0> <EOL> def test_rootframe ( self ) : <EOL> pass <EOL> class PathTestCase ( TestCase ) : <EOL> def makegraph ( self , width , length ) : <EOL> dst = [ ] <EOL> ls = [ ] <EOL> for i in range ( width ) : <EOL> ls . append ( [ dst ] ) <EOL> ls = [ dst ] * width <EOL> for i in range ( length - <NUM_LIT:1> ) : <EOL> xs = [ ] <EOL> for j in range ( width ) : <EOL> ys = [ ] <EOL> xs . append ( ys ) <EOL> for k in range ( width ) : <EOL> ys . append ( ls [ k ] ) <EOL> ls = xs <EOL> src = ls <EOL> return src , dst <EOL> def chkgraph ( self , width , length , expect = None ) : <EOL> src , dst = self . makegraph ( width , length ) <EOL> self . chkpath ( src , dst , expect ) <EOL> def test_path ( self ) : <EOL> dst = '<STR_LIT>' <EOL> self . chkpath ( [ dst ] , dst , '<STR_LIT>' ) <EOL> self . chkpath ( [ [ ] , dst ] , dst , '<STR_LIT>' ) <EOL> self . chkpath ( [ dst , dst ] , dst , "<STR_LIT>" ) <EOL> self . chkpath ( [ [ dst , <NUM_LIT:0> ] , dst , [ dst , <NUM_LIT:2> ] ] , dst , "<STR_LIT>" ) <EOL> self . chkpath ( [ [ dst , <NUM_LIT:0> ] , [ dst , <NUM_LIT:2> ] ] , dst , "<STR_LIT>" ) <EOL> src , dst = self . makegraph ( <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> self . chkgraph ( <NUM_LIT:1> , <NUM_LIT:1> , '<STR_LIT>' ) <EOL> self . chkgraph ( <NUM_LIT:1> , <NUM_LIT:2> , '<STR_LIT>' ) <EOL> self . chkgraph ( <NUM_LIT:2> , <NUM_LIT:1> , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . chkgraph ( <NUM_LIT:3> , <NUM_LIT:2> , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def test_numpaths ( self ) : <EOL> for ( width , length ) in [ ( <NUM_LIT:2> , <NUM_LIT:1> ) , ( <NUM_LIT:7> , <NUM_LIT:3> ) , ( <NUM_LIT:3> , <NUM_LIT:7> ) , ( <NUM_LIT:10> , <NUM_LIT:20> ) ] : <EOL> src , dst = self . makegraph ( width , length ) <EOL> p = self . shpaths ( dst , src ) <EOL> self . aseq ( p . numpaths , width ** length ) <EOL> def test_iter ( self ) : <EOL> src , dst = self . makegraph ( <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> p = self . shpaths ( dst , src ) <EOL> it = iter ( p ) <EOL> ss = [ ] <EOL> for i in it : <EOL> ss . append ( str ( i ) ) <EOL> ss . sort ( ) <EOL> self . aseq ( ss , [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> width = <NUM_LIT:11> <EOL> length = <NUM_LIT> <EOL> numpaths = <NUM_LIT:20> <EOL> src , dst = self . makegraph ( width , length ) <EOL> p = self . shpaths ( dst , src ) <EOL> it = iter ( p ) <EOL> for i in range ( numpaths ) : <EOL> path = it . next ( ) <EOL> sp = str ( path ) <EOL> div , mod = divmod ( i , width ) <EOL> self . aseq ( sp , '<STR_LIT:%s>' + '<STR_LIT>' * ( length - <NUM_LIT:2> ) + '<STR_LIT>' % ( div , mod ) ) <EOL> osrc = src <EOL> src , dst = self . makegraph ( width , length ) <EOL> src [ <NUM_LIT:0> ] = osrc <EOL> p = self . shpaths ( dst , src ) <EOL> it = iter ( p ) <EOL> for i in range ( numpaths ) : <EOL> path = it . next ( ) <EOL> sp = str ( path ) <EOL> div , mod = divmod ( i , width ) <EOL> self . aseq ( sp , '<STR_LIT>' + '<STR_LIT>' * ( length - <NUM_LIT:3> ) + '<STR_LIT>' % ( div , mod ) ) <EOL> numfromend = width / <NUM_LIT:2> <EOL> for it in [ p . iter ( - numfromend ) , p . iter ( p . numpaths - numfromend ) ] : <EOL> for i , path in enumerate ( it ) : <EOL> sp = str ( path ) <EOL> self . aseq ( sp , '<STR_LIT:%s>' + ( '<STR_LIT>' % ( width - <NUM_LIT:1> ) ) * ( length - <NUM_LIT:1> ) + '<STR_LIT>' % ( width - numfromend + i ) ) <EOL> start = <NUM_LIT:5> <EOL> stop = <NUM_LIT> <EOL> i = start <EOL> for path in p . iter ( start , stop ) : <EOL> sp = str ( path ) <EOL> div , mod = divmod ( i , width ) <EOL> self . aseq ( sp , '<STR_LIT>' + '<STR_LIT>' * ( length - <NUM_LIT:3> ) + '<STR_LIT>' % ( div , mod ) ) <EOL> self . aseq ( path . index , i ) <EOL> i += <NUM_LIT:1> <EOL> self . aseq ( i , stop ) <EOL> def test_str ( self ) : <EOL> width = <NUM_LIT:11> <EOL> length = <NUM_LIT:4> <EOL> src , dst = self . makegraph ( width , length ) <EOL> p = self . shpaths ( dst , src ) <EOL> p . maxpaths = <NUM_LIT:1> <EOL> self . aseq ( str ( p ) , "<STR_LIT>" ) <EOL> p . maxpaths = <NUM_LIT:2> <EOL> self . aseq ( str ( p ) , "<STR_LIT>" ) <EOL> def test_printing ( self ) : <EOL> from StringIO import StringIO <EOL> output = StringIO ( ) <EOL> self . Path . output = output <EOL> width = <NUM_LIT:11> <EOL> length = <NUM_LIT:4> <EOL> src , dst = self . makegraph ( width , length ) <EOL> p = self . shpaths ( dst , src ) <EOL> p . maxpaths = <NUM_LIT:2> <EOL> p . pp ( ) <EOL> p . more ( ) <EOL> self . aseq ( output . getvalue ( ) , """<STR_LIT>""" ) <EOL> def test_subscript ( self ) : <EOL> width = <NUM_LIT:3> <EOL> length = <NUM_LIT> <EOL> src , dst = self . makegraph ( width , length ) <EOL> p = self . shpaths ( dst , src ) <EOL> np = width ** length <EOL> self . aseq ( np , p . numpaths ) <EOL> self . aseq ( str ( p [ <NUM_LIT:0> ] ) , '<STR_LIT:%s>' + '<STR_LIT>' * length ) <EOL> self . aseq ( str ( p [ - np ] ) , '<STR_LIT:%s>' + '<STR_LIT>' * length ) <EOL> self . aseq ( str ( p [ width - <NUM_LIT:1> ] ) , '<STR_LIT:%s>' + '<STR_LIT>' * ( length - <NUM_LIT:1> ) + '<STR_LIT>' % ( width - <NUM_LIT:1> ) ) <EOL> self . aseq ( str ( p [ width ] ) , '<STR_LIT:%s>' + '<STR_LIT>' * ( length - <NUM_LIT:2> ) + '<STR_LIT>' ) <EOL> self . aseq ( str ( p [ width + <NUM_LIT:1> ] ) , '<STR_LIT:%s>' + '<STR_LIT>' * ( length - <NUM_LIT:2> ) + '<STR_LIT>' ) <EOL> self . aseq ( str ( p [ np - <NUM_LIT:1> ] ) , '<STR_LIT:%s>' + ( '<STR_LIT>' % ( width - <NUM_LIT:1> ) ) * length ) <EOL> self . aseq ( str ( p [ - <NUM_LIT:1> ] ) , '<STR_LIT:%s>' + ( '<STR_LIT>' % ( width - <NUM_LIT:1> ) ) * length ) <EOL> self . failUnlessRaises ( IndexError , lambda : p [ np ] ) <EOL> self . failUnlessRaises ( IndexError , lambda : p [ - np - <NUM_LIT:1> ] ) <EOL> class MultiTestCase ( TestCase ) : <EOL> def test_pp ( self ) : <EOL> self . Path . output = self . Path . _root . StringIO . StringIO ( ) <EOL> iso = self . iso <EOL> dst = [ [ ] , [ ] ] <EOL> src = iso ( dst [ : ] * <NUM_LIT:2> ) <EOL> dst = [ iso ( x ) for x in dst ] <EOL> p = self . Path . shpgraph ( dst , src ) <EOL> p . pp ( ) <EOL> p = self . Path . shpgraph ( dst , src , srcname = '<STR_LIT:A>' , dstname = '<STR_LIT:B>' ) <EOL> p . pp ( ) <EOL> self . aseq ( self . Path . output . getvalue ( ) , """<STR_LIT>""" ) <EOL> class AvoidTestCase ( TestCase ) : <EOL> def test_1 ( self ) : <EOL> src = [ '<STR_LIT:src>' ] <EOL> a = src <EOL> for i in range ( <NUM_LIT:3> ) : <EOL> b = [ '<STR_LIT>' % i ] <EOL> c = [ '<STR_LIT>' % i , b ] <EOL> a . append ( b ) <EOL> a . append ( c ) <EOL> a = b <EOL> dst = a <EOL> p = self . shpaths ( dst , src ) <EOL> for avoid , result in [ <EOL> ( [ ] , '<STR_LIT>' ) , <EOL> ( [ <NUM_LIT:0> ] , '<STR_LIT>' ) , <EOL> ( [ <NUM_LIT:1> ] , '<STR_LIT>' ) , <EOL> ( [ <NUM_LIT:2> ] , '<STR_LIT>' ) , <EOL> ( [ <NUM_LIT:0> , <NUM_LIT:1> ] , '<STR_LIT>' ) , <EOL> ( [ <NUM_LIT:1> , <NUM_LIT:2> ] , '<STR_LIT>' ) , <EOL> ( [ <NUM_LIT:0> , <NUM_LIT:2> ] , '<STR_LIT>' ) , <EOL> ( [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] , '<STR_LIT>' ) , <EOL> ( [ <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:0> ] , '<STR_LIT>' ) , <EOL> ] : <EOL> result = result % '<STR_LIT>' <EOL> q = self . shpaths ( dst , src , avoid_edges = p . edges_at ( * avoid ) ) <EOL> self . aseq ( str ( q ) , result ) <EOL> q = p . copy_but_avoid_edges_at_levels ( * avoid ) <EOL> self . aseq ( str ( q ) , result ) <EOL> q = p . avoided ( * avoid ) <EOL> self . aseq ( str ( q ) , result ) <EOL> q = p . avoided ( <NUM_LIT:0> ) . avoided ( <NUM_LIT:2> ) <EOL> self . aseq ( str ( q ) , '<STR_LIT>' ) <EOL> class NewTestCase ( TestCase ) : <EOL> def test_1 ( self ) : <EOL> import sys <EOL> o = self . python . StringIO . StringIO ( ) <EOL> iso = self . iso <EOL> x = iso ( sys . __dict__ ) <EOL> print >> o , x . shpaths <EOL> print >> o , x . shpaths . avoided ( <NUM_LIT:0> ) <EOL> print >> o , repr ( x . shpaths ) <EOL> print >> o , repr ( x . shpaths ) <EOL> x = [ ] <EOL> y = [ [ [ x ] ] ] <EOL> sp = iso ( x ) . get_shpaths ( iso ( y ) ) <EOL> print >> o , sp <EOL> y . append ( sp ) <EOL> print >> o , iso ( x ) . get_shpaths ( iso ( y ) ) <EOL> x = [ ] <EOL> y = [ x ] <EOL> z = [ y ] <EOL> print >> o , iso ( x , y ) . get_shpaths ( iso ( z ) ) <EOL> if <NUM_LIT:0> : <EOL> clock = self . python . time . clock <EOL> import gc <EOL> gc . collect ( ) <EOL> t = clock ( ) <EOL> x = str ( iso ( x , y ) . get_shpaths ( iso ( z ) ) ) <EOL> fast = clock ( ) - t <EOL> gc . collect ( ) <EOL> t = clock ( ) <EOL> x = str ( ( iso ( ) | list ) . get_shpaths ( iso ( z ) ) ) <EOL> slow = clock ( ) - t <EOL> self . assert_ ( slow < <NUM_LIT:5> * fast ) <EOL> class C : <EOL> pass <EOL> class O ( C , object ) : <EOL> __slots__ = '<STR_LIT:x>' , <EOL> ob = O ( ) <EOL> ob . x = x <EOL> print >> o , iso ( x ) . get_shpaths ( iso ( ob ) ) <EOL> summary_str = self . heapy . UniSet . summary_str <EOL> str_address = lambda x : '<STR_LIT>' <EOL> str_address . _idpart_header = getattr ( summary_str . str_address , '<STR_LIT>' , None ) <EOL> str_address . _idpart_sortrender = getattr ( summary_str . str_address , '<STR_LIT>' , None ) <EOL> summary_str . str_address = str_address <EOL> S = iso ( ) <EOL> shp = iso ( x ) . get_shpaths ( iso ( y , z ) ) <EOL> print >> o , shp <EOL> print >> o , repr ( shp ) <EOL> for p in shp : <EOL> S = S ^ p . src <EOL> self . aseq ( S , iso ( y ) ) <EOL> shp = iso ( x ) . get_shpaths ( iso ( ob , y , z ) ) <EOL> print >> o , str ( shp ) <EOL> print >> o , repr ( shp ) <EOL> S = iso ( ) <EOL> for i , p in enumerate ( shp ) : <EOL> S = S ^ p . src <EOL> self . aseq ( p . src , shp [ i ] . src ) <EOL> self . aseq ( S , iso ( ob , y ) ) <EOL> it = iter ( shp ) <EOL> a = list ( it ) <EOL> it . isatend = <NUM_LIT:0> <EOL> b = list ( it ) <EOL> self . aseq ( str ( a ) , str ( b ) ) <EOL> self . aseq ( o . getvalue ( ) , """<STR_LIT>""" . replace ( '<STR_LIT:__main__>' , self . __module__ ) ) <EOL> def test_2 ( self ) : <EOL> o = self . python . StringIO . StringIO ( ) <EOL> iso = self . iso <EOL> dst = [ ] <EOL> src = [ dst ] * <NUM_LIT:20> <EOL> print >> o , repr ( iso ( dst ) . get_shpaths ( iso ( src ) ) ) <EOL> print >> o , repr ( iso ( dst ) . get_shpaths ( iso ( src ) ) . more ) <EOL> p = iso ( dst ) . get_shpaths ( iso ( src ) ) <EOL> print >> o , repr ( p . more ) <EOL> self . aseq ( o . getvalue ( ) , """<STR_LIT>""" ) <EOL> def test_empty ( self ) : <EOL> iso = self . iso <EOL> dst = [ ] <EOL> self . assert_ ( len ( list ( iso ( dst ) . get_shpaths ( iso ( ) ) ) ) == <NUM_LIT:0> ) <EOL> def test_3 ( self ) : <EOL> iso = self . iso <EOL> dst = [ ] <EOL> shp = iso ( dst ) . shpaths <EOL> del dst <EOL> self . assert_ ( '<STR_LIT>' not in str ( shp . avoided ( <NUM_LIT:0> ) ) ) <EOL> dst = [ ] <EOL> src = [ dst ] <EOL> shp = iso ( dst ) . get_shpaths ( iso ( src ) ) <EOL> src [ <NUM_LIT:0> ] = shp <EOL> dst = iso ( dst ) <EOL> src = iso ( src ) <EOL> self . assert_ ( dst . get_shpaths ( src ) . numpaths == <NUM_LIT:0> ) <EOL> dst = [ ] <EOL> src = [ dst ] <EOL> dst = iso ( dst ) <EOL> src = iso ( src ) <EOL> self . aseq ( dst . get_shpaths ( src ) . sets , ( src , dst ) ) <EOL> class C : <EOL> pass <EOL> c = C ( ) <EOL> cd = iso ( c . __dict__ ) <EOL> p = cd . shpaths <EOL> repr ( p ) <EOL> del c <EOL> q = cd . shpaths <EOL> self . aseq ( repr ( q ) . strip ( ) , "<STR_LIT>" ) <EOL> del p , q <EOL> dst = [ ] <EOL> src = [ [ [ [ dst ] ] ] ] <EOL> d = iso ( dst ) <EOL> s = iso ( src ) <EOL> p = d . get_shpaths ( s ) <EOL> self . aseq ( str ( p ) , "<STR_LIT>" ) <EOL> src . append ( p ) <EOL> p . _XX_ = dst <EOL> self . aseq ( str ( d . get_shpaths ( s ) ) , "<STR_LIT>" ) <EOL> self . aseq ( str ( p . more ) , '<STR_LIT>' ) <EOL> self . asis ( p . more . top . top , p ) <EOL> def run_test ( case , debug = <NUM_LIT:0> ) : <EOL> support . run_unittest ( case , debug ) <EOL> def test_main ( debug = <NUM_LIT:0> ) : <EOL> if <NUM_LIT:1> : <EOL> run_test ( NewTestCase , debug ) <EOL> if <NUM_LIT:1> : <EOL> run_test ( RelationTestCase , debug ) <EOL> run_test ( RootTestCase , debug ) <EOL> if <NUM_LIT:1> : <EOL> run_test ( PathTestCase , debug ) <EOL> if <NUM_LIT:1> : <EOL> run_test ( MultiTestCase , debug ) <EOL> run_test ( AvoidTestCase , debug ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
