<s> import pprint <EOL> import test . support <EOL> import unittest <EOL> import test . test_set <EOL> import random <EOL> import collections <EOL> import itertools <EOL> class list2 ( list ) : <EOL> pass <EOL> class list3 ( list ) : <EOL> def __repr__ ( self ) : <EOL> return list . __repr__ ( self ) <EOL> class tuple2 ( tuple ) : <EOL> pass <EOL> class tuple3 ( tuple ) : <EOL> def __repr__ ( self ) : <EOL> return tuple . __repr__ ( self ) <EOL> class set2 ( set ) : <EOL> pass <EOL> class set3 ( set ) : <EOL> def __repr__ ( self ) : <EOL> return set . __repr__ ( self ) <EOL> class frozenset2 ( frozenset ) : <EOL> pass <EOL> class frozenset3 ( frozenset ) : <EOL> def __repr__ ( self ) : <EOL> return frozenset . __repr__ ( self ) <EOL> class dict2 ( dict ) : <EOL> pass <EOL> class dict3 ( dict ) : <EOL> def __repr__ ( self ) : <EOL> return dict . __repr__ ( self ) <EOL> class Unorderable : <EOL> def __repr__ ( self ) : <EOL> return str ( id ( self ) ) <EOL> class QueryTestCase ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . a = list ( range ( <NUM_LIT:100> ) ) <EOL> self . b = list ( range ( <NUM_LIT:200> ) ) <EOL> self . a [ - <NUM_LIT:12> ] = self . b <EOL> def test_basic ( self ) : <EOL> pp = pprint . PrettyPrinter ( ) <EOL> for safe in ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT> , "<STR_LIT:abc>" , [ <NUM_LIT:3> ] , ( <NUM_LIT:2> , <NUM_LIT:2> ) , { <NUM_LIT:3> : <NUM_LIT:3> } , "<STR_LIT>" , <EOL> self . a , self . b ) : <EOL> self . assertFalse ( pprint . isrecursive ( safe ) , <EOL> "<STR_LIT>" % ( safe , ) ) <EOL> self . assertTrue ( pprint . isreadable ( safe ) , <EOL> "<STR_LIT>" % ( safe , ) ) <EOL> self . assertFalse ( pp . isrecursive ( safe ) , <EOL> "<STR_LIT>" % ( safe , ) ) <EOL> self . assertTrue ( pp . isreadable ( safe ) , <EOL> "<STR_LIT>" % ( safe , ) ) <EOL> def test_knotted ( self ) : <EOL> self . b [ <NUM_LIT> ] = self . a <EOL> self . d = { } <EOL> self . d [ <NUM_LIT:0> ] = self . d [ <NUM_LIT:1> ] = self . d [ <NUM_LIT:2> ] = self . d <EOL> pp = pprint . PrettyPrinter ( ) <EOL> for icky in self . a , self . b , self . d , ( self . d , self . d ) : <EOL> self . assertTrue ( pprint . isrecursive ( icky ) , "<STR_LIT>" ) <EOL> self . assertFalse ( pprint . isreadable ( icky ) , "<STR_LIT>" ) <EOL> self . assertTrue ( pp . isrecursive ( icky ) , "<STR_LIT>" ) <EOL> self . assertFalse ( pp . isreadable ( icky ) , "<STR_LIT>" ) <EOL> self . d . clear ( ) <EOL> del self . a [ : ] <EOL> del self . b [ : ] <EOL> for safe in self . a , self . b , self . d , ( self . d , self . d ) : <EOL> self . assertFalse ( pprint . isrecursive ( safe ) , <EOL> "<STR_LIT>" % ( safe , ) ) <EOL> self . assertTrue ( pprint . isreadable ( safe ) , <EOL> "<STR_LIT>" % ( safe , ) ) <EOL> self . assertFalse ( pp . isrecursive ( safe ) , <EOL> "<STR_LIT>" % ( safe , ) ) <EOL> self . assertTrue ( pp . isreadable ( safe ) , <EOL> "<STR_LIT>" % ( safe , ) ) <EOL> def test_unreadable ( self ) : <EOL> pp = pprint . PrettyPrinter ( ) <EOL> for unreadable in type ( <NUM_LIT:3> ) , pprint , pprint . isrecursive : <EOL> self . assertFalse ( pprint . isrecursive ( unreadable ) , <EOL> "<STR_LIT>" % ( unreadable , ) ) <EOL> self . assertFalse ( pprint . isreadable ( unreadable ) , <EOL> "<STR_LIT>" % ( unreadable , ) ) <EOL> self . assertFalse ( pp . isrecursive ( unreadable ) , <EOL> "<STR_LIT>" % ( unreadable , ) ) <EOL> self . assertFalse ( pp . isreadable ( unreadable ) , <EOL> "<STR_LIT>" % ( unreadable , ) ) <EOL> def test_same_as_repr ( self ) : <EOL> for simple in ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> + <NUM_LIT> , <NUM_LIT:0.0> , "<STR_LIT>" , b"<STR_LIT>" , <EOL> ( ) , tuple2 ( ) , tuple3 ( ) , <EOL> [ ] , list2 ( ) , list3 ( ) , <EOL> set ( ) , set2 ( ) , set3 ( ) , <EOL> frozenset ( ) , frozenset2 ( ) , frozenset3 ( ) , <EOL> { } , dict2 ( ) , dict3 ( ) , <EOL> self . assertTrue , pprint , <EOL> - <NUM_LIT:6> , - <NUM_LIT:6> , - <NUM_LIT:6> - <NUM_LIT> , - <NUM_LIT> , "<STR_LIT:x>" , b"<STR_LIT:x>" , ( <NUM_LIT:3> , ) , [ <NUM_LIT:3> ] , { <NUM_LIT:3> : <NUM_LIT:6> } , <EOL> ( <NUM_LIT:1> , <NUM_LIT:2> ) , [ <NUM_LIT:3> , <NUM_LIT:4> ] , { <NUM_LIT:5> : <NUM_LIT:6> } , <EOL> tuple2 ( ( <NUM_LIT:1> , <NUM_LIT:2> ) ) , tuple3 ( ( <NUM_LIT:1> , <NUM_LIT:2> ) ) , tuple3 ( range ( <NUM_LIT:100> ) ) , <EOL> [ <NUM_LIT:3> , <NUM_LIT:4> ] , list2 ( [ <NUM_LIT:3> , <NUM_LIT:4> ] ) , list3 ( [ <NUM_LIT:3> , <NUM_LIT:4> ] ) , list3 ( range ( <NUM_LIT:100> ) ) , <EOL> set ( { <NUM_LIT:7> } ) , set2 ( { <NUM_LIT:7> } ) , set3 ( { <NUM_LIT:7> } ) , <EOL> frozenset ( { <NUM_LIT:8> } ) , frozenset2 ( { <NUM_LIT:8> } ) , frozenset3 ( { <NUM_LIT:8> } ) , <EOL> dict2 ( { <NUM_LIT:5> : <NUM_LIT:6> } ) , dict3 ( { <NUM_LIT:5> : <NUM_LIT:6> } ) , <EOL> range ( <NUM_LIT:10> , - <NUM_LIT:11> , - <NUM_LIT:1> ) <EOL> ) : <EOL> native = repr ( simple ) <EOL> self . assertEqual ( pprint . pformat ( simple ) , native ) <EOL> self . assertEqual ( pprint . pformat ( simple , width = <NUM_LIT:1> , indent = <NUM_LIT:0> ) <EOL> . replace ( '<STR_LIT:\n>' , '<STR_LIT:U+0020>' ) , native ) <EOL> self . assertEqual ( pprint . saferepr ( simple ) , native ) <EOL> def test_basic_line_wrap ( self ) : <EOL> o = { '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : <NUM_LIT> } <EOL> exp = """<STR_LIT>""" <EOL> for type in [ dict , dict2 ] : <EOL> self . assertEqual ( pprint . pformat ( type ( o ) ) , exp ) <EOL> o = range ( <NUM_LIT:100> ) <EOL> exp = '<STR_LIT>' % '<STR_LIT>' . join ( map ( str , o ) ) <EOL> for type in [ list , list2 ] : <EOL> self . assertEqual ( pprint . pformat ( type ( o ) ) , exp ) <EOL> o = tuple ( range ( <NUM_LIT:100> ) ) <EOL> exp = '<STR_LIT>' % '<STR_LIT>' . join ( map ( str , o ) ) <EOL> for type in [ tuple , tuple2 ] : <EOL> self . assertEqual ( pprint . pformat ( type ( o ) ) , exp ) <EOL> o = range ( <NUM_LIT:100> ) <EOL> exp = '<STR_LIT>' % '<STR_LIT>' . join ( map ( str , o ) ) <EOL> for type in [ list , list2 ] : <EOL> self . assertEqual ( pprint . pformat ( type ( o ) , indent = <NUM_LIT:4> ) , exp ) <EOL> def test_nested_indentations ( self ) : <EOL> o1 = list ( range ( <NUM_LIT:10> ) ) <EOL> o2 = dict ( first = <NUM_LIT:1> , second = <NUM_LIT:2> , third = <NUM_LIT:3> ) <EOL> o = [ o1 , o2 ] <EOL> expected = """<STR_LIT>""" <EOL> self . assertEqual ( pprint . pformat ( o , indent = <NUM_LIT:4> , width = <NUM_LIT> ) , expected ) <EOL> def test_sorted_dict ( self ) : <EOL> d = { '<STR_LIT:a>' : <NUM_LIT:1> , '<STR_LIT:b>' : <NUM_LIT:1> , '<STR_LIT:c>' : <NUM_LIT:1> } <EOL> self . assertEqual ( pprint . pformat ( d ) , "<STR_LIT>" ) <EOL> self . assertEqual ( pprint . pformat ( [ d , d ] ) , <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( pprint . pformat ( { "<STR_LIT>" : ( <NUM_LIT:3> , ) , <NUM_LIT:5> : [ [ ] ] , ( ) : { } } ) , <EOL> r"<STR_LIT>" ) <EOL> def test_ordered_dict ( self ) : <EOL> words = '<STR_LIT>' . split ( ) <EOL> d = collections . OrderedDict ( zip ( words , itertools . count ( ) ) ) <EOL> self . assertEqual ( pprint . pformat ( d ) , <EOL> """<STR_LIT>""" ) <EOL> def test_subclassing ( self ) : <EOL> o = { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> exp = """<STR_LIT>""" <EOL> self . assertEqual ( DottedPrettyPrinter ( ) . pformat ( o ) , exp ) <EOL> def test_set_reprs ( self ) : <EOL> self . assertEqual ( pprint . pformat ( set ( ) ) , '<STR_LIT>' ) <EOL> self . assertEqual ( pprint . pformat ( set ( range ( <NUM_LIT:3> ) ) ) , '<STR_LIT>' ) <EOL> self . assertEqual ( pprint . pformat ( set ( range ( <NUM_LIT:7> ) ) , width = <NUM_LIT:20> ) , '''<STR_LIT>''' ) <EOL> self . assertEqual ( pprint . pformat ( set2 ( range ( <NUM_LIT:7> ) ) , width = <NUM_LIT:20> ) , '''<STR_LIT>''' ) <EOL> self . assertEqual ( pprint . pformat ( set3 ( range ( <NUM_LIT:7> ) ) , width = <NUM_LIT:20> ) , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( pprint . pformat ( frozenset ( ) ) , '<STR_LIT>' ) <EOL> self . assertEqual ( pprint . pformat ( frozenset ( range ( <NUM_LIT:3> ) ) ) , <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( pprint . pformat ( frozenset ( range ( <NUM_LIT:7> ) ) , width = <NUM_LIT:20> ) , '''<STR_LIT>''' ) <EOL> self . assertEqual ( pprint . pformat ( frozenset2 ( range ( <NUM_LIT:7> ) ) , width = <NUM_LIT:20> ) , '''<STR_LIT>''' ) <EOL> self . assertEqual ( pprint . pformat ( frozenset3 ( range ( <NUM_LIT:7> ) ) , width = <NUM_LIT:20> ) , <EOL> '<STR_LIT>' ) <EOL> @ unittest . expectedFailure <EOL> @ test . support . cpython_only <EOL> def test_set_of_sets_reprs ( self ) : <EOL> cube_repr_tgt = """<STR_LIT>""" <EOL> cube = test . test_set . cube ( <NUM_LIT:3> ) <EOL> self . assertEqual ( pprint . pformat ( cube ) , cube_repr_tgt ) <EOL> cubo_repr_tgt = """<STR_LIT>""" <EOL> cubo = test . test_set . linegraph ( cube ) <EOL> self . assertEqual ( pprint . pformat ( cubo ) , cubo_repr_tgt ) <EOL> def test_depth ( self ) : <EOL> nested_tuple = ( <NUM_LIT:1> , ( <NUM_LIT:2> , ( <NUM_LIT:3> , ( <NUM_LIT:4> , ( <NUM_LIT:5> , <NUM_LIT:6> ) ) ) ) ) <EOL> nested_dict = { <NUM_LIT:1> : { <NUM_LIT:2> : { <NUM_LIT:3> : { <NUM_LIT:4> : { <NUM_LIT:5> : { <NUM_LIT:6> : <NUM_LIT:6> } } } } } } <EOL> nested_list = [ <NUM_LIT:1> , [ <NUM_LIT:2> , [ <NUM_LIT:3> , [ <NUM_LIT:4> , [ <NUM_LIT:5> , [ <NUM_LIT:6> , [ ] ] ] ] ] ] ] <EOL> self . assertEqual ( pprint . pformat ( nested_tuple ) , repr ( nested_tuple ) ) <EOL> self . assertEqual ( pprint . pformat ( nested_dict ) , repr ( nested_dict ) ) <EOL> self . assertEqual ( pprint . pformat ( nested_list ) , repr ( nested_list ) ) <EOL> lv1_tuple = '<STR_LIT>' <EOL> lv1_dict = '<STR_LIT>' <EOL> lv1_list = '<STR_LIT>' <EOL> self . assertEqual ( pprint . pformat ( nested_tuple , depth = <NUM_LIT:1> ) , lv1_tuple ) <EOL> self . assertEqual ( pprint . pformat ( nested_dict , depth = <NUM_LIT:1> ) , lv1_dict ) <EOL> self . assertEqual ( pprint . pformat ( nested_list , depth = <NUM_LIT:1> ) , lv1_list ) <EOL> def test_sort_unorderable_values ( self ) : <EOL> n = <NUM_LIT:20> <EOL> keys = [ Unorderable ( ) for i in range ( n ) ] <EOL> random . shuffle ( keys ) <EOL> skeys = sorted ( keys , key = id ) <EOL> clean = lambda s : s . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) . replace ( '<STR_LIT:\n>' , '<STR_LIT>' ) <EOL> self . assertEqual ( clean ( pprint . pformat ( set ( keys ) ) ) , <EOL> '<STR_LIT:{>' + '<STR_LIT:U+002C>' . join ( map ( repr , skeys ) ) + '<STR_LIT:}>' ) <EOL> self . assertEqual ( clean ( pprint . pformat ( frozenset ( keys ) ) ) , <EOL> '<STR_LIT>' + '<STR_LIT:U+002C>' . join ( map ( repr , skeys ) ) + '<STR_LIT>' ) <EOL> self . assertEqual ( clean ( pprint . pformat ( dict . fromkeys ( keys ) ) ) , <EOL> '<STR_LIT:{>' + '<STR_LIT:U+002C>' . join ( '<STR_LIT>' % k for k in skeys ) + '<STR_LIT:}>' ) <EOL> self . assertEqual ( pprint . pformat ( { Unorderable : <NUM_LIT:0> , <NUM_LIT:1> : <NUM_LIT:0> } ) , <EOL> '<STR_LIT>' + repr ( Unorderable ) + '<STR_LIT>' ) <EOL> keys = [ ( <NUM_LIT:1> , ) , ( None , ) ] <EOL> self . assertEqual ( pprint . pformat ( dict . fromkeys ( keys , <NUM_LIT:0> ) ) , <EOL> '<STR_LIT>' % tuple ( sorted ( keys , key = id ) ) ) <EOL> class DottedPrettyPrinter ( pprint . PrettyPrinter ) : <EOL> def format ( self , object , context , maxlevels , level ) : <EOL> if isinstance ( object , str ) : <EOL> if '<STR_LIT:U+0020>' in object : <EOL> return repr ( object ) , <NUM_LIT:1> , <NUM_LIT:0> <EOL> else : <EOL> return object , <NUM_LIT:0> , <NUM_LIT:0> <EOL> else : <EOL> return pprint . PrettyPrinter . format ( <EOL> self , object , context , maxlevels , level ) <EOL> def test_main ( ) : <EOL> test . support . run_unittest ( QueryTestCase ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
