Mercurial > cpython-lru_cache-weakref
annotate Lib/test/test_pipes.py @ 54294:dba767bc3155 legacy-trunk
remove mention of old ctypes version
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Sat, 23 May 2009 20:59:09 +0000 |
| parents | 228cfb6e2900 |
| children | 6c6425563918 |
| rev | line source |
|---|---|
|
43042
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
1 import pipes |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
2 import os |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
3 import string |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
4 import unittest |
|
52355
228cfb6e2900
fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents:
52353
diff
changeset
|
5 from test.test_support import TESTFN, run_unittest, unlink |
|
43043
113220dace64
* Skip test_pipes on non-POSIX.
Georg Brandl <georg@python.org>
parents:
43042
diff
changeset
|
6 |
|
113220dace64
* Skip test_pipes on non-POSIX.
Georg Brandl <georg@python.org>
parents:
43042
diff
changeset
|
7 if os.name != 'posix': |
|
52355
228cfb6e2900
fix incorrect auto-translation of TestSkipped -> unittest.SkipTest
Benjamin Peterson <benjamin@python.org>
parents:
52353
diff
changeset
|
8 raise unittest.SkipTest('pipes module only works on posix') |
|
43042
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
9 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
10 TESTFN2 = TESTFN + "2" |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
11 |
|
43312
5a51d1b65629
tr a-z A-Z does not work on Solaris (would require
Martin v. Löwis <martin@v.loewis.de>
parents:
43043
diff
changeset
|
12 # tr a-z A-Z is not portable, so make the ranges explicit |
|
5a51d1b65629
tr a-z A-Z does not work on Solaris (would require
Martin v. Löwis <martin@v.loewis.de>
parents:
43043
diff
changeset
|
13 s_command = 'tr %s %s' % (string.ascii_lowercase, string.ascii_uppercase) |
|
5a51d1b65629
tr a-z A-Z does not work on Solaris (would require
Martin v. Löwis <martin@v.loewis.de>
parents:
43043
diff
changeset
|
14 |
|
43042
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
15 class SimplePipeTests(unittest.TestCase): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
16 def tearDown(self): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
17 for f in (TESTFN, TESTFN2): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
18 unlink(f) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
19 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
20 def testSimplePipe1(self): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
21 t = pipes.Template() |
|
43312
5a51d1b65629
tr a-z A-Z does not work on Solaris (would require
Martin v. Löwis <martin@v.loewis.de>
parents:
43043
diff
changeset
|
22 t.append(s_command, pipes.STDIN_STDOUT) |
|
43042
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
23 f = t.open(TESTFN, 'w') |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
24 f.write('hello world #1') |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
25 f.close() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
26 self.assertEqual(open(TESTFN).read(), 'HELLO WORLD #1') |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
27 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
28 def testSimplePipe2(self): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
29 file(TESTFN, 'w').write('hello world #2') |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
30 t = pipes.Template() |
|
43312
5a51d1b65629
tr a-z A-Z does not work on Solaris (would require
Martin v. Löwis <martin@v.loewis.de>
parents:
43043
diff
changeset
|
31 t.append(s_command + ' < $IN > $OUT', pipes.FILEIN_FILEOUT) |
|
43042
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
32 t.copy(TESTFN, TESTFN2) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
33 self.assertEqual(open(TESTFN2).read(), 'HELLO WORLD #2') |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
34 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
35 def testSimplePipe3(self): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
36 file(TESTFN, 'w').write('hello world #2') |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
37 t = pipes.Template() |
|
43312
5a51d1b65629
tr a-z A-Z does not work on Solaris (would require
Martin v. Löwis <martin@v.loewis.de>
parents:
43043
diff
changeset
|
38 t.append(s_command + ' < $IN', pipes.FILEIN_STDOUT) |
|
43042
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
39 self.assertEqual(t.open(TESTFN, 'r').read(), 'HELLO WORLD #2') |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
40 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
41 def testEmptyPipeline1(self): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
42 # copy through empty pipe |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
43 d = 'empty pipeline test COPY' |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
44 file(TESTFN, 'w').write(d) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
45 file(TESTFN2, 'w').write('') |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
46 t=pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
47 t.copy(TESTFN, TESTFN2) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
48 self.assertEqual(open(TESTFN2).read(), d) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
49 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
50 def testEmptyPipeline2(self): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
51 # read through empty pipe |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
52 d = 'empty pipeline test READ' |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
53 file(TESTFN, 'w').write(d) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
54 t=pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
55 self.assertEqual(t.open(TESTFN, 'r').read(), d) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
56 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
57 def testEmptyPipeline3(self): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
58 # write through empty pipe |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
59 d = 'empty pipeline test WRITE' |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
60 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
61 t.open(TESTFN, 'w').write(d) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
62 self.assertEqual(open(TESTFN).read(), d) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
63 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
64 def testQuoting(self): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
65 safeunquoted = string.ascii_letters + string.digits + '!@%_-+=:,./' |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
66 unsafe = '"`$\\' |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
67 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
68 self.assertEqual(pipes.quote(safeunquoted), safeunquoted) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
69 self.assertEqual(pipes.quote('test file name'), "'test file name'") |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
70 for u in unsafe: |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
71 self.assertEqual(pipes.quote('test%sname' % u), |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
72 "'test%sname'" % u) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
73 for u in unsafe: |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
74 self.assertEqual(pipes.quote("test%s'name'" % u), |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
75 '"test\\%s\'name\'"' % u) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
76 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
77 def testRepr(self): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
78 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
79 self.assertEqual(repr(t), "<Template instance, steps=[]>") |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
80 t.append('tr a-z A-Z', pipes.STDIN_STDOUT) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
81 self.assertEqual(repr(t), |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
82 "<Template instance, steps=[('tr a-z A-Z', '--')]>") |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
83 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
84 def testSetDebug(self): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
85 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
86 t.debug(False) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
87 self.assertEqual(t.debugging, False) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
88 t.debug(True) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
89 self.assertEqual(t.debugging, True) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
90 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
91 def testReadOpenSink(self): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
92 # check calling open('r') on a pipe ending with |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
93 # a sink raises ValueError |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
94 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
95 t.append('boguscmd', pipes.SINK) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
96 self.assertRaises(ValueError, t.open, 'bogusfile', 'r') |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
97 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
98 def testWriteOpenSource(self): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
99 # check calling open('w') on a pipe ending with |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
100 # a source raises ValueError |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
101 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
102 t.prepend('boguscmd', pipes.SOURCE) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
103 self.assertRaises(ValueError, t.open, 'bogusfile', 'w') |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
104 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
105 def testBadAppendOptions(self): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
106 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
107 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
108 # try a non-string command |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
109 self.assertRaises(TypeError, t.append, 7, pipes.STDIN_STDOUT) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
110 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
111 # try a type that isn't recognized |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
112 self.assertRaises(ValueError, t.append, 'boguscmd', 'xx') |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
113 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
114 # shouldn't be able to append a source |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
115 self.assertRaises(ValueError, t.append, 'boguscmd', pipes.SOURCE) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
116 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
117 # check appending two sinks |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
118 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
119 t.append('boguscmd', pipes.SINK) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
120 self.assertRaises(ValueError, t.append, 'boguscmd', pipes.SINK) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
121 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
122 # command needing file input but with no $IN |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
123 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
124 self.assertRaises(ValueError, t.append, 'boguscmd $OUT', |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
125 pipes.FILEIN_FILEOUT) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
126 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
127 self.assertRaises(ValueError, t.append, 'boguscmd', |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
128 pipes.FILEIN_STDOUT) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
129 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
130 # command needing file output but with no $OUT |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
131 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
132 self.assertRaises(ValueError, t.append, 'boguscmd $IN', |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
133 pipes.FILEIN_FILEOUT) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
134 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
135 self.assertRaises(ValueError, t.append, 'boguscmd', |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
136 pipes.STDIN_FILEOUT) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
137 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
138 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
139 def testBadPrependOptions(self): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
140 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
141 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
142 # try a non-string command |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
143 self.assertRaises(TypeError, t.prepend, 7, pipes.STDIN_STDOUT) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
144 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
145 # try a type that isn't recognized |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
146 self.assertRaises(ValueError, t.prepend, 'tr a-z A-Z', 'xx') |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
147 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
148 # shouldn't be able to prepend a sink |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
149 self.assertRaises(ValueError, t.prepend, 'boguscmd', pipes.SINK) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
150 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
151 # check prepending two sources |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
152 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
153 t.prepend('boguscmd', pipes.SOURCE) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
154 self.assertRaises(ValueError, t.prepend, 'boguscmd', pipes.SOURCE) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
155 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
156 # command needing file input but with no $IN |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
157 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
158 self.assertRaises(ValueError, t.prepend, 'boguscmd $OUT', |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
159 pipes.FILEIN_FILEOUT) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
160 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
161 self.assertRaises(ValueError, t.prepend, 'boguscmd', |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
162 pipes.FILEIN_STDOUT) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
163 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
164 # command needing file output but with no $OUT |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
165 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
166 self.assertRaises(ValueError, t.prepend, 'boguscmd $IN', |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
167 pipes.FILEIN_FILEOUT) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
168 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
169 self.assertRaises(ValueError, t.prepend, 'boguscmd', |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
170 pipes.STDIN_FILEOUT) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
171 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
172 def testBadOpenMode(self): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
173 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
174 self.assertRaises(ValueError, t.open, 'bogusfile', 'x') |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
175 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
176 def testClone(self): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
177 t = pipes.Template() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
178 t.append('tr a-z A-Z', pipes.STDIN_STDOUT) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
179 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
180 u = t.clone() |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
181 self.assertNotEqual(id(t), id(u)) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
182 self.assertEqual(t.steps, u.steps) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
183 self.assertNotEqual(id(t.steps), id(u.steps)) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
184 self.assertEqual(t.debugging, u.debugging) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
185 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
186 def test_main(): |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
187 run_unittest(SimplePipeTests) |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
188 |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
189 if __name__ == "__main__": |
|
8b0b1146d908
Patch #1680959: add test suite for pipes module.
Georg Brandl <georg@python.org>
parents:
diff
changeset
|
190 test_main() |
