<s> """<STR_LIT>""" <EOL> import sys <EOL> import os <EOL> import shutil <EOL> import unittest <EOL> from test . test_support import run_unittest , check_py3k_warnings <EOL> from repr import repr as r <EOL> from repr import Repr <EOL> def nestedTuple ( nesting ) : <EOL> t = ( ) <EOL> for i in range ( nesting ) : <EOL> t = ( t , ) <EOL> return t <EOL> class ReprTests ( unittest . TestCase ) : <EOL> def test_string ( self ) : <EOL> eq = self . assertEqual <EOL> eq ( r ( "<STR_LIT:abc>" ) , "<STR_LIT>" ) <EOL> eq ( r ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> s = "<STR_LIT:a>" * <NUM_LIT:30> + "<STR_LIT:b>" * <NUM_LIT:30> <EOL> expected = repr ( s ) [ : <NUM_LIT> ] + "<STR_LIT>" + repr ( s ) [ - <NUM_LIT> : ] <EOL> eq ( r ( s ) , expected ) <EOL> eq ( r ( "<STR_LIT>" ) , repr ( "<STR_LIT>" ) ) <EOL> s = "<STR_LIT>" * <NUM_LIT:30> + "<STR_LIT:'>" * <NUM_LIT:100> <EOL> expected = repr ( s ) [ : <NUM_LIT> ] + "<STR_LIT>" + repr ( s ) [ - <NUM_LIT> : ] <EOL> eq ( r ( s ) , expected ) <EOL> def test_tuple ( self ) : <EOL> eq = self . assertEqual <EOL> eq ( r ( ( <NUM_LIT:1> , ) ) , "<STR_LIT>" ) <EOL> t3 = ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> eq ( r ( t3 ) , "<STR_LIT>" ) <EOL> r2 = Repr ( ) <EOL> r2 . maxtuple = <NUM_LIT:2> <EOL> expected = repr ( t3 ) [ : - <NUM_LIT:2> ] + "<STR_LIT>" <EOL> eq ( r2 . repr ( t3 ) , expected ) <EOL> def test_container ( self ) : <EOL> from array import array <EOL> from collections import deque <EOL> eq = self . assertEqual <EOL> eq ( r ( ( ) ) , "<STR_LIT>" ) <EOL> eq ( r ( ( <NUM_LIT:1> , ) ) , "<STR_LIT>" ) <EOL> eq ( r ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) , "<STR_LIT>" ) <EOL> eq ( r ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ) ) , "<STR_LIT>" ) <EOL> eq ( r ( ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ) ) , "<STR_LIT>" ) <EOL> eq ( r ( [ ] ) , "<STR_LIT>" ) <EOL> eq ( r ( [ <NUM_LIT:1> ] ) , "<STR_LIT>" ) <EOL> eq ( r ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) , "<STR_LIT>" ) <EOL> eq ( r ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) , "<STR_LIT>" ) <EOL> eq ( r ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] ) , "<STR_LIT>" ) <EOL> eq ( r ( set ( [ ] ) ) , "<STR_LIT>" ) <EOL> eq ( r ( set ( [ <NUM_LIT:1> ] ) ) , "<STR_LIT>" ) <EOL> eq ( r ( set ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) ) , "<STR_LIT>" ) <EOL> eq ( r ( set ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) ) , "<STR_LIT>" ) <EOL> eq ( r ( set ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] ) ) , "<STR_LIT>" ) <EOL> eq ( r ( frozenset ( [ ] ) ) , "<STR_LIT>" ) <EOL> eq ( r ( frozenset ( [ <NUM_LIT:1> ] ) ) , "<STR_LIT>" ) <EOL> eq ( r ( frozenset ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) ) , "<STR_LIT>" ) <EOL> eq ( r ( frozenset ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) ) , "<STR_LIT>" ) <EOL> eq ( r ( frozenset ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] ) ) , "<STR_LIT>" ) <EOL> eq ( r ( deque ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] ) ) , "<STR_LIT>" ) <EOL> eq ( r ( { } ) , "<STR_LIT:{}>" ) <EOL> d = { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : <NUM_LIT:4> } <EOL> eq ( r ( d ) , "<STR_LIT>" ) <EOL> d [ '<STR_LIT>' ] = <NUM_LIT:1> <EOL> eq ( r ( d ) , "<STR_LIT>" ) <EOL> eq ( r ( array ( '<STR_LIT:i>' ) ) , "<STR_LIT>" ) <EOL> eq ( r ( array ( '<STR_LIT:i>' , [ <NUM_LIT:1> ] ) ) , "<STR_LIT>" ) <EOL> eq ( r ( array ( '<STR_LIT:i>' , [ <NUM_LIT:1> , <NUM_LIT:2> ] ) ) , "<STR_LIT>" ) <EOL> eq ( r ( array ( '<STR_LIT:i>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) ) , "<STR_LIT>" ) <EOL> eq ( r ( array ( '<STR_LIT:i>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] ) ) , "<STR_LIT>" ) <EOL> eq ( r ( array ( '<STR_LIT:i>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ) ) , "<STR_LIT>" ) <EOL> eq ( r ( array ( '<STR_LIT:i>' , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) ) , <EOL> "<STR_LIT>" ) <EOL> def test_numbers ( self ) : <EOL> eq = self . assertEqual <EOL> eq ( r ( <NUM_LIT> ) , repr ( <NUM_LIT> ) ) <EOL> eq ( r ( <NUM_LIT> L ) , repr ( <NUM_LIT> L ) ) <EOL> eq ( r ( <NUM_LIT:1.0> / <NUM_LIT:3> ) , repr ( <NUM_LIT:1.0> / <NUM_LIT:3> ) ) <EOL> n = <NUM_LIT:10> L ** <NUM_LIT:100> <EOL> expected = repr ( n ) [ : <NUM_LIT> ] + "<STR_LIT>" + repr ( n ) [ - <NUM_LIT> : ] <EOL> eq ( r ( n ) , expected ) <EOL> def test_instance ( self ) : <EOL> eq = self . assertEqual <EOL> i1 = ClassWithRepr ( "<STR_LIT:a>" ) <EOL> eq ( r ( i1 ) , repr ( i1 ) ) <EOL> i2 = ClassWithRepr ( "<STR_LIT:x>" * <NUM_LIT:1000> ) <EOL> expected = repr ( i2 ) [ : <NUM_LIT> ] + "<STR_LIT>" + repr ( i2 ) [ - <NUM_LIT> : ] <EOL> eq ( r ( i2 ) , expected ) <EOL> i3 = ClassWithFailingRepr ( ) <EOL> eq ( r ( i3 ) , ( "<STR_LIT>" % id ( i3 ) ) ) <EOL> s = r ( ClassWithFailingRepr ) <EOL> self . assertTrue ( s . startswith ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( s . endswith ( "<STR_LIT:>>" ) ) <EOL> self . assertTrue ( s . find ( "<STR_LIT>" ) == <NUM_LIT:8> ) <EOL> def test_file ( self ) : <EOL> fp = open ( unittest . __file__ ) <EOL> self . assertTrue ( repr ( fp ) . startswith ( <EOL> "<STR_LIT>" % unittest . __file__ ) ) <EOL> fp . close ( ) <EOL> self . assertTrue ( repr ( fp ) . startswith ( <EOL> "<STR_LIT>" % unittest . __file__ ) ) <EOL> def test_lambda ( self ) : <EOL> self . assertTrue ( repr ( lambda x : x ) . startswith ( <EOL> "<STR_LIT>" ) ) <EOL> def test_builtin_function ( self ) : <EOL> eq = self . assertEqual <EOL> eq ( repr ( hash ) , '<STR_LIT>' ) <EOL> self . assertTrue ( repr ( '<STR_LIT>' . split ) . startswith ( <EOL> '<STR_LIT>' ) ) <EOL> def test_xrange ( self ) : <EOL> eq = self . assertEqual <EOL> eq ( repr ( xrange ( <NUM_LIT:1> ) ) , '<STR_LIT>' ) <EOL> eq ( repr ( xrange ( <NUM_LIT:1> , <NUM_LIT:2> ) ) , '<STR_LIT>' ) <EOL> eq ( repr ( xrange ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) ) , '<STR_LIT>' ) <EOL> def test_nesting ( self ) : <EOL> eq = self . assertEqual <EOL> eq ( r ( [ [ [ [ [ [ [ ] ] ] ] ] ] ] ) , "<STR_LIT>" ) <EOL> eq ( r ( [ [ [ [ [ [ [ [ ] ] ] ] ] ] ] ] ) , "<STR_LIT>" ) <EOL> eq ( r ( nestedTuple ( <NUM_LIT:6> ) ) , "<STR_LIT>" ) <EOL> eq ( r ( nestedTuple ( <NUM_LIT:7> ) ) , "<STR_LIT>" ) <EOL> eq ( r ( { nestedTuple ( <NUM_LIT:5> ) : nestedTuple ( <NUM_LIT:5> ) } ) , <EOL> "<STR_LIT>" ) <EOL> eq ( r ( { nestedTuple ( <NUM_LIT:6> ) : nestedTuple ( <NUM_LIT:6> ) } ) , <EOL> "<STR_LIT>" ) <EOL> eq ( r ( [ [ [ [ [ [ { } ] ] ] ] ] ] ) , "<STR_LIT>" ) <EOL> eq ( r ( [ [ [ [ [ [ [ { } ] ] ] ] ] ] ] ) , "<STR_LIT>" ) <EOL> def test_buffer ( self ) : <EOL> with check_py3k_warnings ( ) : <EOL> x = buffer ( '<STR_LIT:foo>' ) <EOL> self . assertTrue ( repr ( x ) . startswith ( '<STR_LIT>' ) ) <EOL> def test_cell ( self ) : <EOL> pass <EOL> def test_descriptors ( self ) : <EOL> eq = self . assertEqual <EOL> eq ( repr ( dict . items ) , "<STR_LIT>" ) <EOL> class C : <EOL> def foo ( cls ) : pass <EOL> x = staticmethod ( C . foo ) <EOL> self . assertTrue ( repr ( x ) . startswith ( '<STR_LIT>' ) ) <EOL> x = classmethod ( C . foo ) <EOL> self . assertTrue ( repr ( x ) . startswith ( '<STR_LIT>' ) ) <EOL> def test_unsortable ( self ) : <EOL> x = set ( [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ) <EOL> y = frozenset ( x ) <EOL> z = { <NUM_LIT> : <NUM_LIT:1> , <NUM_LIT> : <NUM_LIT:2> } <EOL> r ( x ) <EOL> r ( y ) <EOL> r ( z ) <EOL> def touch ( path , text = '<STR_LIT>' ) : <EOL> fp = open ( path , '<STR_LIT:w>' ) <EOL> fp . write ( text ) <EOL> fp . close ( ) <EOL> class LongReprTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> longname = '<STR_LIT>' <EOL> self . pkgname = os . path . join ( longname ) <EOL> self . subpkgname = os . path . join ( longname , longname ) <EOL> shutil . rmtree ( self . pkgname , ignore_errors = True ) <EOL> os . mkdir ( self . pkgname ) <EOL> touch ( os . path . join ( self . pkgname , '<STR_LIT>' + os . extsep + '<STR_LIT>' ) ) <EOL> shutil . rmtree ( self . subpkgname , ignore_errors = True ) <EOL> os . mkdir ( self . subpkgname ) <EOL> touch ( os . path . join ( self . subpkgname , '<STR_LIT>' + os . extsep + '<STR_LIT>' ) ) <EOL> self . here = os . getcwd ( ) <EOL> sys . path . insert ( <NUM_LIT:0> , self . here ) <EOL> def tearDown ( self ) : <EOL> actions = [ ] <EOL> for dirpath , dirnames , filenames in os . walk ( self . pkgname ) : <EOL> for name in dirnames + filenames : <EOL> actions . append ( os . path . join ( dirpath , name ) ) <EOL> actions . append ( self . pkgname ) <EOL> actions . sort ( ) <EOL> actions . reverse ( ) <EOL> for p in actions : <EOL> if os . path . isdir ( p ) : <EOL> os . rmdir ( p ) <EOL> else : <EOL> os . remove ( p ) <EOL> del sys . path [ <NUM_LIT:0> ] <EOL> def test_module ( self ) : <EOL> eq = self . assertEqual <EOL> touch ( os . path . join ( self . subpkgname , self . pkgname + os . extsep + '<STR_LIT>' ) ) <EOL> from areallylongpackageandmodulenametotestreprtruncation . areallylongpackageandmodulenametotestreprtruncation import areallylongpackageandmodulenametotestreprtruncation <EOL> eq ( repr ( areallylongpackageandmodulenametotestreprtruncation ) , <EOL> "<STR_LIT>" % ( areallylongpackageandmodulenametotestreprtruncation . __name__ , areallylongpackageandmodulenametotestreprtruncation . __file__ ) ) <EOL> def test_type ( self ) : <EOL> eq = self . assertEqual <EOL> touch ( os . path . join ( self . subpkgname , '<STR_LIT:foo>' + os . extsep + '<STR_LIT>' ) , '''<STR_LIT>''' ) <EOL> from areallylongpackageandmodulenametotestreprtruncation . areallylongpackageandmodulenametotestreprtruncation import foo <EOL> eq ( repr ( foo . foo ) , <EOL> "<STR_LIT>" % foo . __name__ ) <EOL> def test_object ( self ) : <EOL> pass <EOL> def test_class ( self ) : <EOL> touch ( os . path . join ( self . subpkgname , '<STR_LIT:bar>' + os . extsep + '<STR_LIT>' ) , '''<STR_LIT>''' ) <EOL> from areallylongpackageandmodulenametotestreprtruncation . areallylongpackageandmodulenametotestreprtruncation import bar <EOL> self . assertTrue ( repr ( bar . bar ) . startswith ( <EOL> "<STR_LIT>" % bar . __name__ ) ) <EOL> def test_instance ( self ) : <EOL> touch ( os . path . join ( self . subpkgname , '<STR_LIT>' + os . extsep + '<STR_LIT>' ) , '''<STR_LIT>''' ) <EOL> from areallylongpackageandmodulenametotestreprtruncation . areallylongpackageandmodulenametotestreprtruncation import baz <EOL> ibaz = baz . baz ( ) <EOL> self . assertTrue ( repr ( ibaz ) . startswith ( <EOL> "<STR_LIT>" % baz . __name__ ) ) <EOL> def test_method ( self ) : <EOL> eq = self . assertEqual <EOL> touch ( os . path . join ( self . subpkgname , '<STR_LIT>' + os . extsep + '<STR_LIT>' ) , '''<STR_LIT>''' ) <EOL> from areallylongpackageandmodulenametotestreprtruncation . areallylongpackageandmodulenametotestreprtruncation import qux <EOL> eq ( repr ( qux . aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa . amethod ) , <EOL> '<STR_LIT>' ) <EOL> iqux = qux . aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ( ) <EOL> self . assertTrue ( repr ( iqux . amethod ) . startswith ( <EOL> '<STR_LIT>' % ( qux . __name__ , ) ) ) <EOL> def test_builtin_function ( self ) : <EOL> pass <EOL> class ClassWithRepr : <EOL> def __init__ ( self , s ) : <EOL> self . s = s <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % self . s <EOL> class ClassWithFailingRepr : <EOL> def __repr__ ( self ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def test_main ( ) : <EOL> from test import test_support <EOL> if test_support . is_jython : <EOL> del ReprTests . test_buffer <EOL> run_unittest ( ReprTests ) <EOL> run_unittest ( LongReprTest ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
