<s> import pipes <EOL> import os <EOL> import string <EOL> import unittest <EOL> from test . test_support import TESTFN , run_unittest , unlink , reap_children <EOL> if os . name != '<STR_LIT>' : <EOL> raise unittest . SkipTest ( '<STR_LIT>' ) <EOL> TESTFN2 = TESTFN + "<STR_LIT:2>" <EOL> s_command = '<STR_LIT>' % ( string . ascii_lowercase , string . ascii_uppercase ) <EOL> class SimplePipeTests ( unittest . TestCase ) : <EOL> def tearDown ( self ) : <EOL> for f in ( TESTFN , TESTFN2 ) : <EOL> unlink ( f ) <EOL> def testSimplePipe1 ( self ) : <EOL> t = pipes . Template ( ) <EOL> t . append ( s_command , pipes . STDIN_STDOUT ) <EOL> f = t . open ( TESTFN , '<STR_LIT:w>' ) <EOL> f . write ( '<STR_LIT>' ) <EOL> f . close ( ) <EOL> with open ( TESTFN ) as f : <EOL> self . assertEqual ( f . read ( ) , '<STR_LIT>' ) <EOL> def testSimplePipe2 ( self ) : <EOL> with open ( TESTFN , '<STR_LIT:w>' ) as f : <EOL> f . write ( '<STR_LIT>' ) <EOL> t = pipes . Template ( ) <EOL> t . append ( s_command + '<STR_LIT>' , pipes . FILEIN_FILEOUT ) <EOL> t . copy ( TESTFN , TESTFN2 ) <EOL> with open ( TESTFN2 ) as f : <EOL> self . assertEqual ( f . read ( ) , '<STR_LIT>' ) <EOL> def testSimplePipe3 ( self ) : <EOL> with open ( TESTFN , '<STR_LIT:w>' ) as f : <EOL> f . write ( '<STR_LIT>' ) <EOL> t = pipes . Template ( ) <EOL> t . append ( s_command + '<STR_LIT>' , pipes . FILEIN_STDOUT ) <EOL> with t . open ( TESTFN , '<STR_LIT:r>' ) as f : <EOL> self . assertEqual ( f . read ( ) , '<STR_LIT>' ) <EOL> def testEmptyPipeline1 ( self ) : <EOL> d = '<STR_LIT>' <EOL> with open ( TESTFN , '<STR_LIT:w>' ) as f : <EOL> f . write ( d ) <EOL> with open ( TESTFN2 , '<STR_LIT:w>' ) as f : <EOL> f . write ( '<STR_LIT>' ) <EOL> t = pipes . Template ( ) <EOL> t . copy ( TESTFN , TESTFN2 ) <EOL> with open ( TESTFN2 ) as f : <EOL> self . assertEqual ( f . read ( ) , d ) <EOL> def testEmptyPipeline2 ( self ) : <EOL> d = '<STR_LIT>' <EOL> with open ( TESTFN , '<STR_LIT:w>' ) as f : <EOL> f . write ( d ) <EOL> t = pipes . Template ( ) <EOL> with t . open ( TESTFN , '<STR_LIT:r>' ) as f : <EOL> self . assertEqual ( f . read ( ) , d ) <EOL> def testEmptyPipeline3 ( self ) : <EOL> d = '<STR_LIT>' <EOL> t = pipes . Template ( ) <EOL> with t . open ( TESTFN , '<STR_LIT:w>' ) as f : <EOL> f . write ( d ) <EOL> with open ( TESTFN ) as f : <EOL> self . assertEqual ( f . read ( ) , d ) <EOL> def testQuoting ( self ) : <EOL> safeunquoted = string . ascii_letters + string . digits + '<STR_LIT>' <EOL> unsafe = '<STR_LIT>' <EOL> self . assertEqual ( pipes . quote ( '<STR_LIT>' ) , "<STR_LIT>" ) <EOL> self . assertEqual ( pipes . quote ( safeunquoted ) , safeunquoted ) <EOL> self . assertEqual ( pipes . quote ( '<STR_LIT>' ) , "<STR_LIT>" ) <EOL> for u in unsafe : <EOL> self . assertEqual ( pipes . quote ( '<STR_LIT>' % u ) , <EOL> "<STR_LIT>" % u ) <EOL> for u in unsafe : <EOL> self . assertEqual ( pipes . quote ( "<STR_LIT>" % u ) , <EOL> "<STR_LIT>" % u ) <EOL> def testRepr ( self ) : <EOL> t = pipes . Template ( ) <EOL> self . assertEqual ( repr ( t ) , "<STR_LIT>" ) <EOL> t . append ( '<STR_LIT>' , pipes . STDIN_STDOUT ) <EOL> self . assertEqual ( repr ( t ) , <EOL> "<STR_LIT>" ) <EOL> def testSetDebug ( self ) : <EOL> t = pipes . Template ( ) <EOL> t . debug ( False ) <EOL> self . assertEqual ( t . debugging , False ) <EOL> t . debug ( True ) <EOL> self . assertEqual ( t . debugging , True ) <EOL> def testReadOpenSink ( self ) : <EOL> t = pipes . Template ( ) <EOL> t . append ( '<STR_LIT>' , pipes . SINK ) <EOL> self . assertRaises ( ValueError , t . open , '<STR_LIT>' , '<STR_LIT:r>' ) <EOL> def testWriteOpenSource ( self ) : <EOL> t = pipes . Template ( ) <EOL> t . prepend ( '<STR_LIT>' , pipes . SOURCE ) <EOL> self . assertRaises ( ValueError , t . open , '<STR_LIT>' , '<STR_LIT:w>' ) <EOL> def testBadAppendOptions ( self ) : <EOL> t = pipes . Template ( ) <EOL> self . assertRaises ( TypeError , t . append , <NUM_LIT:7> , pipes . STDIN_STDOUT ) <EOL> self . assertRaises ( ValueError , t . append , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , t . append , '<STR_LIT>' , pipes . SOURCE ) <EOL> t = pipes . Template ( ) <EOL> t . append ( '<STR_LIT>' , pipes . SINK ) <EOL> self . assertRaises ( ValueError , t . append , '<STR_LIT>' , pipes . SINK ) <EOL> t = pipes . Template ( ) <EOL> self . assertRaises ( ValueError , t . append , '<STR_LIT>' , <EOL> pipes . FILEIN_FILEOUT ) <EOL> t = pipes . Template ( ) <EOL> self . assertRaises ( ValueError , t . append , '<STR_LIT>' , <EOL> pipes . FILEIN_STDOUT ) <EOL> t = pipes . Template ( ) <EOL> self . assertRaises ( ValueError , t . append , '<STR_LIT>' , <EOL> pipes . FILEIN_FILEOUT ) <EOL> t = pipes . Template ( ) <EOL> self . assertRaises ( ValueError , t . append , '<STR_LIT>' , <EOL> pipes . STDIN_FILEOUT ) <EOL> def testBadPrependOptions ( self ) : <EOL> t = pipes . Template ( ) <EOL> self . assertRaises ( TypeError , t . prepend , <NUM_LIT:7> , pipes . STDIN_STDOUT ) <EOL> self . assertRaises ( ValueError , t . prepend , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , t . prepend , '<STR_LIT>' , pipes . SINK ) <EOL> t = pipes . Template ( ) <EOL> t . prepend ( '<STR_LIT>' , pipes . SOURCE ) <EOL> self . assertRaises ( ValueError , t . prepend , '<STR_LIT>' , pipes . SOURCE ) <EOL> t = pipes . Template ( ) <EOL> self . assertRaises ( ValueError , t . prepend , '<STR_LIT>' , <EOL> pipes . FILEIN_FILEOUT ) <EOL> t = pipes . Template ( ) <EOL> self . assertRaises ( ValueError , t . prepend , '<STR_LIT>' , <EOL> pipes . FILEIN_STDOUT ) <EOL> t = pipes . Template ( ) <EOL> self . assertRaises ( ValueError , t . prepend , '<STR_LIT>' , <EOL> pipes . FILEIN_FILEOUT ) <EOL> t = pipes . Template ( ) <EOL> self . assertRaises ( ValueError , t . prepend , '<STR_LIT>' , <EOL> pipes . STDIN_FILEOUT ) <EOL> def testBadOpenMode ( self ) : <EOL> t = pipes . Template ( ) <EOL> self . assertRaises ( ValueError , t . open , '<STR_LIT>' , '<STR_LIT:x>' ) <EOL> def testClone ( self ) : <EOL> t = pipes . Template ( ) <EOL> t . append ( '<STR_LIT>' , pipes . STDIN_STDOUT ) <EOL> u = t . clone ( ) <EOL> self . assertNotEqual ( id ( t ) , id ( u ) ) <EOL> self . assertEqual ( t . steps , u . steps ) <EOL> self . assertNotEqual ( id ( t . steps ) , id ( u . steps ) ) <EOL> self . assertEqual ( t . debugging , u . debugging ) <EOL> def test_main ( ) : <EOL> run_unittest ( SimplePipeTests ) <EOL> reap_children ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> test_main ( ) </s>
