Back to index

python3.2  3.2.2
Public Member Functions
test.test_pipes.SimplePipeTests Class Reference

List of all members.

Public Member Functions

def tearDown
def testSimplePipe1
def testSimplePipe2
def testSimplePipe3
def testEmptyPipeline1
def testEmptyPipeline2
def testEmptyPipeline3
def testQuoting
def testRepr
def testSetDebug
def testReadOpenSink
def testWriteOpenSource
def testBadAppendOptions
def testBadPrependOptions
def testBadOpenMode
def testClone

Detailed Description

Definition at line 15 of file test_pipes.py.


Member Function Documentation

Definition at line 16 of file test_pipes.py.

00016 
00017     def tearDown(self):
00018         for f in (TESTFN, TESTFN2):
00019             unlink(f)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 125 of file test_pipes.py.

00125 
00126     def testBadAppendOptions(self):
00127         t = pipes.Template()
00128 
00129         # try a non-string command
00130         self.assertRaises(TypeError, t.append, 7, pipes.STDIN_STDOUT)
00131 
00132         # try a type that isn't recognized
00133         self.assertRaises(ValueError, t.append, 'boguscmd', 'xx')
00134 
00135         # shouldn't be able to append a source
00136         self.assertRaises(ValueError, t.append, 'boguscmd', pipes.SOURCE)
00137 
00138         # check appending two sinks
00139         t = pipes.Template()
00140         t.append('boguscmd', pipes.SINK)
00141         self.assertRaises(ValueError, t.append, 'boguscmd', pipes.SINK)
00142 
00143         # command needing file input but with no $IN
00144         t = pipes.Template()
00145         self.assertRaises(ValueError, t.append, 'boguscmd $OUT',
00146                            pipes.FILEIN_FILEOUT)
00147         t = pipes.Template()
00148         self.assertRaises(ValueError, t.append, 'boguscmd',
00149                            pipes.FILEIN_STDOUT)
00150 
00151         # command needing file output but with no $OUT
00152         t = pipes.Template()
00153         self.assertRaises(ValueError, t.append, 'boguscmd $IN',
00154                            pipes.FILEIN_FILEOUT)
00155         t = pipes.Template()
00156         self.assertRaises(ValueError, t.append, 'boguscmd',
00157                            pipes.STDIN_FILEOUT)
00158 

Here is the call graph for this function:

Definition at line 192 of file test_pipes.py.

00192 
00193     def testBadOpenMode(self):
00194         t = pipes.Template()
00195         self.assertRaises(ValueError, t.open, 'bogusfile', 'x')

Here is the call graph for this function:

Definition at line 159 of file test_pipes.py.

00159 
00160     def testBadPrependOptions(self):
00161         t = pipes.Template()
00162 
00163         # try a non-string command
00164         self.assertRaises(TypeError, t.prepend, 7, pipes.STDIN_STDOUT)
00165 
00166         # try a type that isn't recognized
00167         self.assertRaises(ValueError, t.prepend, 'tr a-z A-Z', 'xx')
00168 
00169         # shouldn't be able to prepend a sink
00170         self.assertRaises(ValueError, t.prepend, 'boguscmd', pipes.SINK)
00171 
00172         # check prepending two sources
00173         t = pipes.Template()
00174         t.prepend('boguscmd', pipes.SOURCE)
00175         self.assertRaises(ValueError, t.prepend, 'boguscmd', pipes.SOURCE)
00176 
00177         # command needing file input but with no $IN
00178         t = pipes.Template()
00179         self.assertRaises(ValueError, t.prepend, 'boguscmd $OUT',
00180                            pipes.FILEIN_FILEOUT)
00181         t = pipes.Template()
00182         self.assertRaises(ValueError, t.prepend, 'boguscmd',
00183                            pipes.FILEIN_STDOUT)
00184 
00185         # command needing file output but with no $OUT
00186         t = pipes.Template()
00187         self.assertRaises(ValueError, t.prepend, 'boguscmd $IN',
00188                            pipes.FILEIN_FILEOUT)
00189         t = pipes.Template()
00190         self.assertRaises(ValueError, t.prepend, 'boguscmd',
00191                            pipes.STDIN_FILEOUT)

Here is the call graph for this function:

Definition at line 196 of file test_pipes.py.

00196 
00197     def testClone(self):
00198         t = pipes.Template()
00199         t.append('tr a-z A-Z', pipes.STDIN_STDOUT)
00200 
00201         u = t.clone()
00202         self.assertNotEqual(id(t), id(u))
00203         self.assertEqual(t.steps, u.steps)
00204         self.assertNotEqual(id(t.steps), id(u.steps))
00205         self.assertEqual(t.debugging, u.debugging)

Here is the call graph for this function:

Definition at line 49 of file test_pipes.py.

00049 
00050     def testEmptyPipeline1(self):
00051         # copy through empty pipe
00052         d = 'empty pipeline test COPY'
00053         with open(TESTFN, 'w') as f:
00054             f.write(d)
00055         with open(TESTFN2, 'w') as f:
00056             f.write('')
00057         t=pipes.Template()
00058         t.copy(TESTFN, TESTFN2)
00059         with open(TESTFN2) as f:
00060             self.assertEqual(f.read(), d)

Here is the call graph for this function:

Definition at line 61 of file test_pipes.py.

00061 
00062     def testEmptyPipeline2(self):
00063         # read through empty pipe
00064         d = 'empty pipeline test READ'
00065         with open(TESTFN, 'w') as f:
00066             f.write(d)
00067         t=pipes.Template()
00068         f = t.open(TESTFN, 'r')
00069         try:
00070             self.assertEqual(f.read(), d)
00071         finally:
00072             f.close()

Here is the call graph for this function:

Definition at line 73 of file test_pipes.py.

00073 
00074     def testEmptyPipeline3(self):
00075         # write through empty pipe
00076         d = 'empty pipeline test WRITE'
00077         t = pipes.Template()
00078         with t.open(TESTFN, 'w') as f:
00079             f.write(d)
00080         with open(TESTFN) as f:
00081             self.assertEqual(f.read(), d)

Here is the call graph for this function:

Definition at line 82 of file test_pipes.py.

00082 
00083     def testQuoting(self):
00084         safeunquoted = string.ascii_letters + string.digits + '@%_-+=:,./'
00085         unicode_sample = '\xe9\xe0\xdf'  # e + acute accent, a + grave, sharp s
00086         unsafe = '"`$\\!' + unicode_sample
00087 
00088         self.assertEqual(pipes.quote(''), "''")
00089         self.assertEqual(pipes.quote(safeunquoted), safeunquoted)
00090         self.assertEqual(pipes.quote('test file name'), "'test file name'")
00091         for u in unsafe:
00092             self.assertEqual(pipes.quote('test%sname' % u),
00093                               "'test%sname'" % u)
00094         for u in unsafe:
00095             self.assertEqual(pipes.quote("test%s'name'" % u),
00096                              "'test%s'\"'\"'name'\"'\"''" % u)

Here is the call graph for this function:

Definition at line 111 of file test_pipes.py.

00111 
00112     def testReadOpenSink(self):
00113         # check calling open('r') on a pipe ending with
00114         # a sink raises ValueError
00115         t = pipes.Template()
00116         t.append('boguscmd', pipes.SINK)
00117         self.assertRaises(ValueError, t.open, 'bogusfile', 'r')

Here is the call graph for this function:

Definition at line 97 of file test_pipes.py.

00097 
00098     def testRepr(self):
00099         t = pipes.Template()
00100         self.assertEqual(repr(t), "<Template instance, steps=[]>")
00101         t.append('tr a-z A-Z', pipes.STDIN_STDOUT)
00102         self.assertEqual(repr(t),
00103                     "<Template instance, steps=[('tr a-z A-Z', '--')]>")

Here is the call graph for this function:

Definition at line 104 of file test_pipes.py.

00104 
00105     def testSetDebug(self):
00106         t = pipes.Template()
00107         t.debug(False)
00108         self.assertEqual(t.debugging, False)
00109         t.debug(True)
00110         self.assertEqual(t.debugging, True)

Here is the call graph for this function:

Definition at line 20 of file test_pipes.py.

00020 
00021     def testSimplePipe1(self):
00022         t = pipes.Template()
00023         t.append(s_command, pipes.STDIN_STDOUT)
00024         f = t.open(TESTFN, 'w')
00025         f.write('hello world #1')
00026         f.close()
00027         with open(TESTFN) as f:
00028             self.assertEqual(f.read(), 'HELLO WORLD #1')

Here is the call graph for this function:

Definition at line 29 of file test_pipes.py.

00029 
00030     def testSimplePipe2(self):
00031         with open(TESTFN, 'w') as f:
00032             f.write('hello world #2')
00033         t = pipes.Template()
00034         t.append(s_command + ' < $IN > $OUT', pipes.FILEIN_FILEOUT)
00035         t.copy(TESTFN, TESTFN2)
00036         with open(TESTFN2) as f:
00037             self.assertEqual(f.read(), 'HELLO WORLD #2')

Here is the call graph for this function:

Definition at line 38 of file test_pipes.py.

00038 
00039     def testSimplePipe3(self):
00040         with open(TESTFN, 'w') as f:
00041             f.write('hello world #2')
00042         t = pipes.Template()
00043         t.append(s_command + ' < $IN', pipes.FILEIN_STDOUT)
00044         f = t.open(TESTFN, 'r')
00045         try:
00046             self.assertEqual(f.read(), 'HELLO WORLD #2')
00047         finally:
00048             f.close()

Here is the call graph for this function:

Definition at line 118 of file test_pipes.py.

00118 
00119     def testWriteOpenSource(self):
00120         # check calling open('w') on a pipe ending with
00121         # a source raises ValueError
00122         t = pipes.Template()
00123         t.prepend('boguscmd', pipes.SOURCE)
00124         self.assertRaises(ValueError, t.open, 'bogusfile', 'w')

Here is the call graph for this function:


The documentation for this class was generated from the following file: