mirror of
https://github.com/python/cpython.git
synced 2025-07-24 03:35:53 +00:00

svn+ssh://pythondev@svn.python.org/python/trunk ........ r58061 | ronald.oussoren | 2007-09-09 13:13:42 +0200 (Sun, 09 Sep 2007) | 12 lines Newer autoconf versions (from 2.60) want a 'datarootdir' definition in (Make-)files that use mandir (and other data directory macros). This patch solves a warning during configure, specifically: ... config.status: creating Makefile.pre config.status: WARNING: ../Makefile.pre.in seems to ignore the --datarootdir setting ... See also: <http://www.gnu.org/software/automake/manual/autoconf/Changed-Directory-Variables.html> ........ r58064 | gregory.p.smith | 2007-09-09 22:25:00 +0200 (Sun, 09 Sep 2007) | 2 lines email address update ........ r58067 | gregory.p.smith | 2007-09-10 01:36:46 +0200 (Mon, 10 Sep 2007) | 22 lines Change socket.error to inherit from IOError rather than being a stand alone class. This addresses the primary concern in http://bugs.python.org/issue1706815 python-dev discussion here: http://mail.python.org/pipermail/python-dev/2007-July/073749.html I chose IOError rather than EnvironmentError as the base class since socket objects are often used as transparent duck typed file objects in code already prepared to deal with IOError exceptions. also a minor fix: urllib2 - fix a couple places where IOError was raised rather than URLError. for better or worse, URLError already inherits from IOError so this won't break any existing code. test_urllib2net - replace bad ftp urls. ........ r58084 | martin.v.loewis | 2007-09-10 08:18:32 +0200 (Mon, 10 Sep 2007) | 3 lines tr a-z A-Z does not work on Solaris (would require /usr/xpg4/bin/tr); make the character ranges explicit. ........ r58086 | martin.v.loewis | 2007-09-10 12:21:22 +0200 (Mon, 10 Sep 2007) | 1 line Take chm file from build/htmlhelp/pydoc.chm. ........ r58087 | martin.v.loewis | 2007-09-10 12:22:05 +0200 (Mon, 10 Sep 2007) | 1 line Beginnings of a "build MSI" step. ........ r58088 | martin.v.loewis | 2007-09-10 15:19:10 +0200 (Mon, 10 Sep 2007) | 1 line Allow making update with no prior checkout. ........ r58089 | martin.v.loewis | 2007-09-10 15:20:03 +0200 (Mon, 10 Sep 2007) | 1 line Update before making htmlhelp. ........ r58090 | martin.v.loewis | 2007-09-10 15:30:38 +0200 (Mon, 10 Sep 2007) | 1 line Require that bash.exe is on the path, along with the rest of Cygwin. ........
190 lines
6.5 KiB
Python
190 lines
6.5 KiB
Python
import pipes
|
|
import os
|
|
import string
|
|
import unittest
|
|
from test.test_support import TESTFN, run_unittest, unlink, TestSkipped
|
|
|
|
if os.name != 'posix':
|
|
raise TestSkipped('pipes module only works on posix')
|
|
|
|
TESTFN2 = TESTFN + "2"
|
|
|
|
# tr a-z A-Z is not portable, so make the ranges explicit
|
|
s_command = 'tr %s %s' % (string.ascii_lowercase, string.ascii_uppercase)
|
|
|
|
class SimplePipeTests(unittest.TestCase):
|
|
def tearDown(self):
|
|
for f in (TESTFN, TESTFN2):
|
|
unlink(f)
|
|
|
|
def testSimplePipe1(self):
|
|
t = pipes.Template()
|
|
t.append(s_command, 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):
|
|
open(TESTFN, 'w').write('hello world #2')
|
|
t = pipes.Template()
|
|
t.append(s_command + ' < $IN > $OUT', pipes.FILEIN_FILEOUT)
|
|
t.copy(TESTFN, TESTFN2)
|
|
self.assertEqual(open(TESTFN2).read(), 'HELLO WORLD #2')
|
|
|
|
def testSimplePipe3(self):
|
|
open(TESTFN, 'w').write('hello world #2')
|
|
t = pipes.Template()
|
|
t.append(s_command + ' < $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'
|
|
open(TESTFN, 'w').write(d)
|
|
open(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'
|
|
open(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), "<Template instance, steps=[]>")
|
|
t.append('tr a-z A-Z', pipes.STDIN_STDOUT)
|
|
self.assertEqual(repr(t),
|
|
"<Template instance, steps=[('tr a-z A-Z', '--')]>")
|
|
|
|
def testSetDebug(self):
|
|
t = pipes.Template()
|
|
t.debug(False)
|
|
self.assertEqual(t.debugging, False)
|
|
t.debug(True)
|
|
self.assertEqual(t.debugging, True)
|
|
|
|
def testReadOpenSink(self):
|
|
# check calling open('r') on a pipe ending with
|
|
# a sink raises ValueError
|
|
t = pipes.Template()
|
|
t.append('boguscmd', pipes.SINK)
|
|
self.assertRaises(ValueError, t.open, 'bogusfile', 'r')
|
|
|
|
def testWriteOpenSource(self):
|
|
# check calling open('w') on a pipe ending with
|
|
# a source raises ValueError
|
|
t = pipes.Template()
|
|
t.prepend('boguscmd', pipes.SOURCE)
|
|
self.assertRaises(ValueError, t.open, 'bogusfile', 'w')
|
|
|
|
def testBadAppendOptions(self):
|
|
t = pipes.Template()
|
|
|
|
# try a non-string command
|
|
self.assertRaises(TypeError, t.append, 7, pipes.STDIN_STDOUT)
|
|
|
|
# try a type that isn't recognized
|
|
self.assertRaises(ValueError, t.append, 'boguscmd', 'xx')
|
|
|
|
# shouldn't be able to append a source
|
|
self.assertRaises(ValueError, t.append, 'boguscmd', pipes.SOURCE)
|
|
|
|
# check appending two sinks
|
|
t = pipes.Template()
|
|
t.append('boguscmd', pipes.SINK)
|
|
self.assertRaises(ValueError, t.append, 'boguscmd', pipes.SINK)
|
|
|
|
# command needing file input but with no $IN
|
|
t = pipes.Template()
|
|
self.assertRaises(ValueError, t.append, 'boguscmd $OUT',
|
|
pipes.FILEIN_FILEOUT)
|
|
t = pipes.Template()
|
|
self.assertRaises(ValueError, t.append, 'boguscmd',
|
|
pipes.FILEIN_STDOUT)
|
|
|
|
# command needing file output but with no $OUT
|
|
t = pipes.Template()
|
|
self.assertRaises(ValueError, t.append, 'boguscmd $IN',
|
|
pipes.FILEIN_FILEOUT)
|
|
t = pipes.Template()
|
|
self.assertRaises(ValueError, t.append, 'boguscmd',
|
|
pipes.STDIN_FILEOUT)
|
|
|
|
|
|
def testBadPrependOptions(self):
|
|
t = pipes.Template()
|
|
|
|
# try a non-string command
|
|
self.assertRaises(TypeError, t.prepend, 7, pipes.STDIN_STDOUT)
|
|
|
|
# try a type that isn't recognized
|
|
self.assertRaises(ValueError, t.prepend, 'tr a-z A-Z', 'xx')
|
|
|
|
# shouldn't be able to prepend a sink
|
|
self.assertRaises(ValueError, t.prepend, 'boguscmd', pipes.SINK)
|
|
|
|
# check prepending two sources
|
|
t = pipes.Template()
|
|
t.prepend('boguscmd', pipes.SOURCE)
|
|
self.assertRaises(ValueError, t.prepend, 'boguscmd', pipes.SOURCE)
|
|
|
|
# command needing file input but with no $IN
|
|
t = pipes.Template()
|
|
self.assertRaises(ValueError, t.prepend, 'boguscmd $OUT',
|
|
pipes.FILEIN_FILEOUT)
|
|
t = pipes.Template()
|
|
self.assertRaises(ValueError, t.prepend, 'boguscmd',
|
|
pipes.FILEIN_STDOUT)
|
|
|
|
# command needing file output but with no $OUT
|
|
t = pipes.Template()
|
|
self.assertRaises(ValueError, t.prepend, 'boguscmd $IN',
|
|
pipes.FILEIN_FILEOUT)
|
|
t = pipes.Template()
|
|
self.assertRaises(ValueError, t.prepend, 'boguscmd',
|
|
pipes.STDIN_FILEOUT)
|
|
|
|
def testBadOpenMode(self):
|
|
t = pipes.Template()
|
|
self.assertRaises(ValueError, t.open, 'bogusfile', 'x')
|
|
|
|
def testClone(self):
|
|
t = pipes.Template()
|
|
t.append('tr a-z A-Z', pipes.STDIN_STDOUT)
|
|
|
|
u = t.clone()
|
|
self.assertNotEqual(id(t), id(u))
|
|
self.assertEqual(t.steps, u.steps)
|
|
self.assertNotEqual(id(t.steps), id(u.steps))
|
|
self.assertEqual(t.debugging, u.debugging)
|
|
|
|
def test_main():
|
|
run_unittest(SimplePipeTests)
|
|
|
|
if __name__ == "__main__":
|
|
test_main()
|