<s> """<STR_LIT>""" <EOL> import unittest <EOL> from test import test_support <EOL> import sys , os , uu , cStringIO <EOL> import uu <EOL> from StringIO import StringIO <EOL> plaintext = "<STR_LIT>" <EOL> encodedtext = """<STR_LIT>""" <EOL> encodedtextwrapped = "<STR_LIT>" + encodedtext . replace ( "<STR_LIT:%>" , "<STR_LIT>" ) + "<STR_LIT>" <EOL> class UUTest ( unittest . TestCase ) : <EOL> def test_encode ( self ) : <EOL> inp = cStringIO . StringIO ( plaintext ) <EOL> out = cStringIO . StringIO ( ) <EOL> uu . encode ( inp , out , "<STR_LIT>" ) <EOL> self . assertEqual ( out . getvalue ( ) , encodedtextwrapped % ( <NUM_LIT:0> <NUM_LIT> , "<STR_LIT>" ) ) <EOL> inp = cStringIO . StringIO ( plaintext ) <EOL> out = cStringIO . StringIO ( ) <EOL> uu . encode ( inp , out , "<STR_LIT>" , <NUM_LIT:0> <NUM_LIT> ) <EOL> self . assertEqual ( out . getvalue ( ) , encodedtextwrapped % ( <NUM_LIT:0> <NUM_LIT> , "<STR_LIT>" ) ) <EOL> def test_decode ( self ) : <EOL> inp = cStringIO . StringIO ( encodedtextwrapped % ( <NUM_LIT:0> <NUM_LIT> , "<STR_LIT>" ) ) <EOL> out = cStringIO . StringIO ( ) <EOL> uu . decode ( inp , out ) <EOL> self . assertEqual ( out . getvalue ( ) , plaintext ) <EOL> inp = cStringIO . StringIO ( <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> encodedtextwrapped % ( <NUM_LIT:0> <NUM_LIT> , "<STR_LIT>" ) <EOL> ) <EOL> out = cStringIO . StringIO ( ) <EOL> uu . decode ( inp , out ) <EOL> self . assertEqual ( out . getvalue ( ) , plaintext ) <EOL> def test_truncatedinput ( self ) : <EOL> inp = cStringIO . StringIO ( "<STR_LIT>" + encodedtext ) <EOL> out = cStringIO . StringIO ( ) <EOL> try : <EOL> uu . decode ( inp , out ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except uu . Error , e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> def test_missingbegin ( self ) : <EOL> inp = cStringIO . StringIO ( "<STR_LIT>" ) <EOL> out = cStringIO . StringIO ( ) <EOL> try : <EOL> uu . decode ( inp , out ) <EOL> self . fail ( "<STR_LIT>" ) <EOL> except uu . Error , e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> class UUStdIOTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . stdin = sys . stdin <EOL> self . stdout = sys . stdout <EOL> def tearDown ( self ) : <EOL> sys . stdin = self . stdin <EOL> sys . stdout = self . stdout <EOL> def test_encode ( self ) : <EOL> sys . stdin = cStringIO . StringIO ( plaintext ) <EOL> sys . stdout = cStringIO . StringIO ( ) <EOL> uu . encode ( "<STR_LIT:->" , "<STR_LIT:->" , "<STR_LIT>" , <NUM_LIT:0> <NUM_LIT> ) <EOL> self . assertEqual ( <EOL> sys . stdout . getvalue ( ) , <EOL> encodedtextwrapped % ( <NUM_LIT:0> <NUM_LIT> , "<STR_LIT>" ) <EOL> ) <EOL> def test_decode ( self ) : <EOL> sys . stdin = cStringIO . StringIO ( encodedtextwrapped % ( <NUM_LIT:0> <NUM_LIT> , "<STR_LIT>" ) ) <EOL> sys . stdout = cStringIO . StringIO ( ) <EOL> uu . decode ( "<STR_LIT:->" , "<STR_LIT:->" ) <EOL> self . assertEqual ( sys . stdout . getvalue ( ) , plaintext ) <EOL> class UUFileTest ( unittest . TestCase ) : <EOL> def _kill ( self , f ) : <EOL> try : <EOL> f . close ( ) <EOL> except ( SystemExit , KeyboardInterrupt ) : <EOL> raise <EOL> except : <EOL> pass <EOL> try : <EOL> os . unlink ( f . name ) <EOL> except ( SystemExit , KeyboardInterrupt ) : <EOL> raise <EOL> except : <EOL> pass <EOL> def setUp ( self ) : <EOL> self . tmpin = test_support . TESTFN + "<STR_LIT:i>" <EOL> self . tmpout = test_support . TESTFN + "<STR_LIT:o>" <EOL> def tearDown ( self ) : <EOL> del self . tmpin <EOL> del self . tmpout <EOL> def test_encode ( self ) : <EOL> try : <EOL> fin = open ( self . tmpin , '<STR_LIT:wb>' ) <EOL> fin . write ( plaintext ) <EOL> fin . close ( ) <EOL> fin = open ( self . tmpin , '<STR_LIT:rb>' ) <EOL> fout = open ( self . tmpout , '<STR_LIT:w>' ) <EOL> uu . encode ( fin , fout , self . tmpin , mode = <NUM_LIT:0> <NUM_LIT> ) <EOL> fin . close ( ) <EOL> fout . close ( ) <EOL> fout = open ( self . tmpout , '<STR_LIT:r>' ) <EOL> s = fout . read ( ) <EOL> fout . close ( ) <EOL> self . assertEqual ( s , encodedtextwrapped % ( <NUM_LIT:0> <NUM_LIT> , self . tmpin ) ) <EOL> uu . encode ( self . tmpin , self . tmpout , mode = <NUM_LIT:0> <NUM_LIT> ) <EOL> fout = open ( self . tmpout , '<STR_LIT:r>' ) <EOL> s = fout . read ( ) <EOL> fout . close ( ) <EOL> self . assertEqual ( s , encodedtextwrapped % ( <NUM_LIT:0> <NUM_LIT> , self . tmpin ) ) <EOL> finally : <EOL> self . _kill ( fin ) <EOL> self . _kill ( fout ) <EOL> def test_decode ( self ) : <EOL> try : <EOL> f = open ( self . tmpin , '<STR_LIT:wb>' ) <EOL> f . write ( encodedtextwrapped % ( <NUM_LIT:0> <NUM_LIT> , self . tmpout ) ) <EOL> f . close ( ) <EOL> f = open ( self . tmpin , '<STR_LIT:rb>' ) <EOL> uu . decode ( f ) <EOL> f . close ( ) <EOL> f = open ( self . tmpout , '<STR_LIT:r>' ) <EOL> s = f . read ( ) <EOL> f . close ( ) <EOL> self . assertEqual ( s , plaintext ) <EOL> finally : <EOL> self . _kill ( f ) <EOL> def test_decodetwice ( self ) : <EOL> try : <EOL> f = cStringIO . StringIO ( encodedtextwrapped % ( <NUM_LIT:0> <NUM_LIT> , self . tmpout ) ) <EOL> f = open ( self . tmpin , '<STR_LIT:rb>' ) <EOL> uu . decode ( f ) <EOL> f . close ( ) <EOL> f = open ( self . tmpin , '<STR_LIT:rb>' ) <EOL> self . assertRaises ( uu . Error , uu . decode , f ) <EOL> f . close ( ) <EOL> finally : <EOL> self . _kill ( f ) <EOL> def test_main ( ) : <EOL> test_support . run_unittest ( UUTest , UUStdIOTest , UUFileTest ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
