<s> from test import test_support <EOL> test_support . requires ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> try : <EOL> import zlib <EOL> except ImportError : <EOL> zlib = None <EOL> import zipfile , os , unittest <EOL> import time <EOL> import sys <EOL> from tempfile import TemporaryFile <EOL> from test . test_support import TESTFN , run_unittest <EOL> TESTFN2 = TESTFN + "<STR_LIT:2>" <EOL> _PRINT_WORKING_MSG_INTERVAL = <NUM_LIT:5> * <NUM_LIT> <EOL> class TestsWithSourceFile ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> line_gen = ( "<STR_LIT>" % i for i in xrange ( <NUM_LIT> ) ) <EOL> self . data = '<STR_LIT:\n>' . join ( line_gen ) <EOL> fp = open ( TESTFN , "<STR_LIT:wb>" ) <EOL> fp . write ( self . data ) <EOL> fp . close ( ) <EOL> def zipTest ( self , f , compression ) : <EOL> zipfp = zipfile . ZipFile ( f , "<STR_LIT:w>" , compression , allowZip64 = True ) <EOL> filecount = <NUM_LIT:6> * <NUM_LIT> ** <NUM_LIT:3> // len ( self . data ) <EOL> next_time = time . time ( ) + _PRINT_WORKING_MSG_INTERVAL <EOL> for num in range ( filecount ) : <EOL> zipfp . writestr ( "<STR_LIT>" % num , self . data ) <EOL> if next_time <= time . time ( ) : <EOL> next_time = time . time ( ) + _PRINT_WORKING_MSG_INTERVAL <EOL> print >> sys . __stdout__ , ( <EOL> '<STR_LIT>' % <EOL> ( num , filecount ) ) <EOL> sys . __stdout__ . flush ( ) <EOL> zipfp . close ( ) <EOL> zipfp = zipfile . ZipFile ( f , "<STR_LIT:r>" , compression ) <EOL> for num in range ( filecount ) : <EOL> self . assertEqual ( zipfp . read ( "<STR_LIT>" % num ) , self . data ) <EOL> if next_time <= time . time ( ) : <EOL> next_time = time . time ( ) + _PRINT_WORKING_MSG_INTERVAL <EOL> print >> sys . __stdout__ , ( <EOL> '<STR_LIT>' % <EOL> ( num , filecount ) ) <EOL> sys . __stdout__ . flush ( ) <EOL> zipfp . close ( ) <EOL> def testStored ( self ) : <EOL> for f in TemporaryFile ( ) , TESTFN2 : <EOL> self . zipTest ( f , zipfile . ZIP_STORED ) <EOL> if zlib : <EOL> def testDeflated ( self ) : <EOL> for f in TemporaryFile ( ) , TESTFN2 : <EOL> self . zipTest ( f , zipfile . ZIP_DEFLATED ) <EOL> def tearDown ( self ) : <EOL> for fname in TESTFN , TESTFN2 : <EOL> if os . path . exists ( fname ) : <EOL> os . remove ( fname ) <EOL> class OtherTests ( unittest . TestCase ) : <EOL> def testMoreThan64kFiles ( self ) : <EOL> zipf = zipfile . ZipFile ( TESTFN , mode = "<STR_LIT:w>" ) <EOL> zipf . debug = <NUM_LIT:100> <EOL> numfiles = ( <NUM_LIT:1> << <NUM_LIT:16> ) * <NUM_LIT:3> / <NUM_LIT:2> <EOL> for i in xrange ( numfiles ) : <EOL> zipf . writestr ( "<STR_LIT>" % i , "<STR_LIT>" % ( i ** <NUM_LIT:3> % <NUM_LIT> ) ) <EOL> self . assertEqual ( len ( zipf . namelist ( ) ) , numfiles ) <EOL> zipf . close ( ) <EOL> zipf2 = zipfile . ZipFile ( TESTFN , mode = "<STR_LIT:r>" ) <EOL> self . assertEqual ( len ( zipf2 . namelist ( ) ) , numfiles ) <EOL> for i in xrange ( numfiles ) : <EOL> self . assertEqual ( zipf2 . read ( "<STR_LIT>" % i ) , "<STR_LIT>" % ( i ** <NUM_LIT:3> % <NUM_LIT> ) ) <EOL> zipf . close ( ) <EOL> def tearDown ( self ) : <EOL> test_support . unlink ( TESTFN ) <EOL> test_support . unlink ( TESTFN2 ) <EOL> def test_main ( ) : <EOL> run_unittest ( TestsWithSourceFile , OtherTests ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
