<s> from test . test_support import TESTFN , TestFailed <EOL> import os <EOL> import random <EOL> import sys <EOL> import py_compile <EOL> try : <EOL> import RAnDoM <EOL> except ImportError : <EOL> pass <EOL> else : <EOL> raise TestFailed ( "<STR_LIT>" ) <EOL> from test import double_const <EOL> def remove_files ( name ) : <EOL> for f in ( name + os . extsep + "<STR_LIT>" , <EOL> name + os . extsep + "<STR_LIT>" , <EOL> name + os . extsep + "<STR_LIT>" , <EOL> name + os . extsep + "<STR_LIT>" , <EOL> name + "<STR_LIT>" ) : <EOL> if os . path . exists ( f ) : <EOL> os . remove ( f ) <EOL> def test_with_extension ( ext ) : <EOL> source = TESTFN + ext <EOL> pyo = TESTFN + os . extsep + "<STR_LIT>" <EOL> if sys . platform . startswith ( '<STR_LIT>' ) : <EOL> pyc = TESTFN + "<STR_LIT>" <EOL> else : <EOL> pyc = TESTFN + os . extsep + "<STR_LIT>" <EOL> f = open ( source , "<STR_LIT:w>" ) <EOL> print >> f , "<STR_LIT>" , ext , "<STR_LIT>" <EOL> a = random . randrange ( <NUM_LIT:1000> ) <EOL> b = random . randrange ( <NUM_LIT:1000> ) <EOL> print >> f , "<STR_LIT>" , a <EOL> print >> f , "<STR_LIT>" , b <EOL> f . close ( ) <EOL> try : <EOL> try : <EOL> mod = __import__ ( TESTFN ) <EOL> except ImportError , err : <EOL> raise ValueError ( "<STR_LIT>" % ( ext , err ) ) <EOL> if mod . a != a or mod . b != b : <EOL> print a , "<STR_LIT>" , mod . a <EOL> print b , "<STR_LIT>" , mod . b <EOL> raise ValueError ( "<STR_LIT>" % mod ) <EOL> finally : <EOL> os . unlink ( source ) <EOL> try : <EOL> try : <EOL> reload ( mod ) <EOL> except ImportError , err : <EOL> raise ValueError ( "<STR_LIT>" % err ) <EOL> finally : <EOL> try : <EOL> os . unlink ( pyc ) <EOL> except os . error : <EOL> pass <EOL> try : <EOL> os . unlink ( pyo ) <EOL> except os . error : <EOL> pass <EOL> del sys . modules [ TESTFN ] <EOL> sys . path . insert ( <NUM_LIT:0> , os . curdir ) <EOL> try : <EOL> test_with_extension ( os . extsep + "<STR_LIT>" ) <EOL> if sys . platform . startswith ( "<STR_LIT>" ) : <EOL> for ext in "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" : <EOL> test_with_extension ( ext ) <EOL> finally : <EOL> del sys . path [ <NUM_LIT:0> ] <EOL> import imp <EOL> x = imp . find_module ( "<STR_LIT>" ) <EOL> os = imp . load_module ( "<STR_LIT>" , * x ) <EOL> def test_module_with_large_stack ( module ) : <EOL> filename = module + os . extsep + '<STR_LIT>' <EOL> f = open ( filename , '<STR_LIT>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> for i in range ( <NUM_LIT> ) : <EOL> f . write ( '<STR_LIT>' ) <EOL> f . write ( '<STR_LIT:]>' ) <EOL> f . close ( ) <EOL> f = open ( filename , '<STR_LIT:r>' ) <EOL> py_compile . compile ( filename ) <EOL> f . close ( ) <EOL> os . unlink ( filename ) <EOL> sys . path . append ( '<STR_LIT>' ) <EOL> exec '<STR_LIT>' + module <EOL> del sys . path [ - <NUM_LIT:1> ] <EOL> for ext in '<STR_LIT>' , '<STR_LIT>' : <EOL> fname = module + os . extsep + ext <EOL> if os . path . exists ( fname ) : <EOL> os . unlink ( fname ) <EOL> test_module_with_large_stack ( '<STR_LIT>' ) <EOL> def test_failing_import_sticks ( ) : <EOL> source = TESTFN + os . extsep + "<STR_LIT>" <EOL> f = open ( source , "<STR_LIT:w>" ) <EOL> print >> f , "<STR_LIT>" <EOL> f . close ( ) <EOL> sys . path . insert ( <NUM_LIT:0> , os . curdir ) <EOL> try : <EOL> for i in <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> : <EOL> try : <EOL> mod = __import__ ( TESTFN ) <EOL> except ZeroDivisionError : <EOL> if TESTFN in sys . modules : <EOL> raise TestFailed ( "<STR_LIT>" , i ) <EOL> else : <EOL> raise TestFailed ( "<STR_LIT>" , i ) <EOL> finally : <EOL> sys . path . pop ( <NUM_LIT:0> ) <EOL> remove_files ( TESTFN ) <EOL> test_failing_import_sticks ( ) <EOL> def test_failing_reload ( ) : <EOL> source = TESTFN + os . extsep + "<STR_LIT>" <EOL> f = open ( source , "<STR_LIT:w>" ) <EOL> print >> f , "<STR_LIT>" <EOL> print >> f , "<STR_LIT>" <EOL> f . close ( ) <EOL> sys . path . insert ( <NUM_LIT:0> , os . curdir ) <EOL> try : <EOL> mod = __import__ ( TESTFN ) <EOL> if TESTFN not in sys . modules : <EOL> raise TestFailed ( "<STR_LIT>" ) <EOL> if mod . a != <NUM_LIT:1> or mod . b != <NUM_LIT:2> : <EOL> raise TestFailed ( "<STR_LIT>" ) <EOL> remove_files ( TESTFN ) <EOL> f = open ( source , "<STR_LIT:w>" ) <EOL> print >> f , "<STR_LIT>" <EOL> print >> f , "<STR_LIT>" <EOL> f . close ( ) <EOL> try : <EOL> reload ( mod ) <EOL> except ZeroDivisionError : <EOL> pass <EOL> else : <EOL> raise TestFailed ( "<STR_LIT>" ) <EOL> mod = sys . modules . get ( TESTFN ) <EOL> if mod is None : <EOL> raise TestFailed ( "<STR_LIT>" ) <EOL> if mod . a != <NUM_LIT:10> or mod . b != <NUM_LIT:2> : <EOL> raise TestFailed ( "<STR_LIT>" ) <EOL> finally : <EOL> sys . path . pop ( <NUM_LIT:0> ) <EOL> remove_files ( TESTFN ) <EOL> if TESTFN in sys . modules : <EOL> del sys . modules [ TESTFN ] <EOL> test_failing_reload ( ) <EOL> def test_import_name_binding ( ) : <EOL> import test as x <EOL> import test . test_support <EOL> assert x is test , x . __name__ <EOL> assert hasattr ( test . test_support , "<STR_LIT>" ) <EOL> import test . test_support as y <EOL> assert y is test . test_support , y . __name__ <EOL> test_import_name_binding ( ) <EOL> def test_import_initless_directory_warning ( ) : <EOL> import warnings <EOL> oldfilters = warnings . filters [ : ] <EOL> warnings . simplefilter ( '<STR_LIT:error>' , ImportWarning ) ; <EOL> try : <EOL> __import__ ( "<STR_LIT>" ) <EOL> except ImportWarning : <EOL> pass <EOL> else : <EOL> raise AssertionError <EOL> finally : <EOL> warnings . filters = oldfilters <EOL> test_import_initless_directory_warning ( ) <EOL> def test_infinite_reload ( ) : <EOL> sys . path . insert ( <NUM_LIT:0> , os . path . dirname ( __file__ ) ) <EOL> try : <EOL> import infinite_reload <EOL> finally : <EOL> sys . path . pop ( <NUM_LIT:0> ) <EOL> test_infinite_reload ( ) </s>
