Index: Lib/test/test_sundry.py =================================================================== --- Lib/test/test_sundry.py (revision 54420) +++ Lib/test/test_sundry.py (working copy) @@ -43,7 +43,6 @@ import opcode import os2emxpath import pdb -import pipes #import poplib import posixfile import pstats Index: Lib/test/regrtest.py =================================================================== --- Lib/test/regrtest.py (revision 54420) +++ Lib/test/regrtest.py (working copy) @@ -834,6 +834,7 @@ test_nis test_openpty test_ossaudiodev + test_pipes test_poll test_posix test_pty Index: Lib/pipes.py =================================================================== --- Lib/pipes.py (revision 54420) +++ Lib/pipes.py (working copy) @@ -60,7 +60,6 @@ import re - import os import tempfile import string @@ -281,18 +280,3 @@ c = '\\' + c res = res + c return '"' + res + '"' - - -# Small test program and example - -def test(): - print 'Testing...' - t = Template() - t.append('togif $IN $OUT', 'ff') - t.append('giftoppm', '--') - t.append('ppmtogif >$OUT', '-f') - t.append('fromgif $IN $OUT', 'ff') - t.debug(1) - FILE = '/usr/local/images/rgb/rogues/guido.rgb' - t.copy(FILE, '@temp') - print 'Done.' Index: Lib/test/test_pipes.py =================================================================== --- Lib/test/test_pipes.py (revision 0) +++ Lib/test/test_pipes.py (revision 0) @@ -0,0 +1,187 @@ +import pipes +import os +import string +import unittest +from test.test_support import TESTFN, run_unittest + +TESTFN2 = TESTFN + "2" + +class SimplePipeTests(unittest.TestCase): + def tearDown(self): + for f in (TESTFN, TESTFN2): + try: + os.unlink(f) + except: + pass + + def testSimplePipe1(self): + t = pipes.Template() + t.append('tr a-z A-Z', pipes.STDIN_STDOUT) + f = t.open(TESTFN, 'w') + f.write('hello world #1') + f.close() + self.assertEqual(open(TESTFN).read(), 'HELLO WORLD #1') + + def testSimplePipe2(self): + file(TESTFN, 'w').write('hello world #2') + t = pipes.Template() + t.append('tr a-z A-Z < $IN > $OUT', pipes.FILEIN_FILEOUT) + t.copy(TESTFN, TESTFN2) + self.assertEqual(open(TESTFN2).read(), 'HELLO WORLD #2') + + def testSimplePipe3(self): + file(TESTFN, 'w').write('hello world #2') + t = pipes.Template() + t.append('tr a-z A-Z < $IN', pipes.FILEIN_STDOUT) + self.assertEqual(t.open(TESTFN, 'r').read(), 'HELLO WORLD #2') + + def testEmptyPipeline1(self): + # copy through empty pipe + d = 'empty pipeline test COPY' + file(TESTFN, 'w').write(d) + file(TESTFN2, 'w').write('') + t=pipes.Template() + t.copy(TESTFN, TESTFN2) + self.assertEqual(open(TESTFN2).read(), d) + + def testEmptyPipeline2(self): + # read through empty pipe + d = 'empty pipeline test READ' + file(TESTFN, 'w').write(d) + t=pipes.Template() + self.assertEqual(t.open(TESTFN, 'r').read(), d) + + def testEmptyPipeline3(self): + # write through empty pipe + d = 'empty pipeline test WRITE' + t = pipes.Template() + t.open(TESTFN, 'w').write(d) + self.assertEqual(open(TESTFN).read(), d) + + def testQuoting(self): + safeunquoted = string.ascii_letters + string.digits + '!@%_-+=:,./' + unsafe = '"`$\\' + + self.assertEqual(pipes.quote(safeunquoted), safeunquoted) + self.assertEqual(pipes.quote('test file name'), "'test file name'") + for u in unsafe: + self.assertEqual(pipes.quote('test%sname' % u), + "'test%sname'" % u) + for u in unsafe: + self.assertEqual(pipes.quote("test%s'name'" % u), + '"test\\%s\'name\'"' % u) + + def testRepr(self): + t = pipes.Template() + self.assertEqual(repr(t), "