Changeset 391 for python/trunk/Lib/test/test_pipes.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/test/test_pipes.py
r2 r391 3 3 import string 4 4 import unittest 5 from test.test_support import TESTFN, run_unittest, unlink, TestSkipped5 from test.test_support import TESTFN, run_unittest, unlink, reap_children 6 6 7 7 if os.name != 'posix': 8 raise TestSkipped('pipes module only works on posix')8 raise unittest.SkipTest('pipes module only works on posix') 9 9 10 10 TESTFN2 = TESTFN + "2" … … 24 24 f.write('hello world #1') 25 25 f.close() 26 self.assertEqual(open(TESTFN).read(), 'HELLO WORLD #1') 26 with open(TESTFN) as f: 27 self.assertEqual(f.read(), 'HELLO WORLD #1') 27 28 28 29 def testSimplePipe2(self): 29 file(TESTFN, 'w').write('hello world #2') 30 with open(TESTFN, 'w') as f: 31 f.write('hello world #2') 30 32 t = pipes.Template() 31 33 t.append(s_command + ' < $IN > $OUT', pipes.FILEIN_FILEOUT) 32 34 t.copy(TESTFN, TESTFN2) 33 self.assertEqual(open(TESTFN2).read(), 'HELLO WORLD #2') 35 with open(TESTFN2) as f: 36 self.assertEqual(f.read(), 'HELLO WORLD #2') 34 37 35 38 def testSimplePipe3(self): 36 file(TESTFN, 'w').write('hello world #2') 39 with open(TESTFN, 'w') as f: 40 f.write('hello world #2') 37 41 t = pipes.Template() 38 42 t.append(s_command + ' < $IN', pipes.FILEIN_STDOUT) 39 self.assertEqual(t.open(TESTFN, 'r').read(), 'HELLO WORLD #2') 43 with t.open(TESTFN, 'r') as f: 44 self.assertEqual(f.read(), 'HELLO WORLD #2') 40 45 41 46 def testEmptyPipeline1(self): 42 47 # copy through empty pipe 43 48 d = 'empty pipeline test COPY' 44 file(TESTFN, 'w').write(d) 45 file(TESTFN2, 'w').write('') 49 with open(TESTFN, 'w') as f: 50 f.write(d) 51 with open(TESTFN2, 'w') as f: 52 f.write('') 46 53 t=pipes.Template() 47 54 t.copy(TESTFN, TESTFN2) 48 self.assertEqual(open(TESTFN2).read(), d) 55 with open(TESTFN2) as f: 56 self.assertEqual(f.read(), d) 49 57 50 58 def testEmptyPipeline2(self): 51 59 # read through empty pipe 52 60 d = 'empty pipeline test READ' 53 file(TESTFN, 'w').write(d) 61 with open(TESTFN, 'w') as f: 62 f.write(d) 54 63 t=pipes.Template() 55 self.assertEqual(t.open(TESTFN, 'r').read(), d) 64 with t.open(TESTFN, 'r') as f: 65 self.assertEqual(f.read(), d) 56 66 57 67 def testEmptyPipeline3(self): … … 59 69 d = 'empty pipeline test WRITE' 60 70 t = pipes.Template() 61 t.open(TESTFN, 'w').write(d) 62 self.assertEqual(open(TESTFN).read(), d) 71 with t.open(TESTFN, 'w') as f: 72 f.write(d) 73 with open(TESTFN) as f: 74 self.assertEqual(f.read(), d) 63 75 64 76 def testQuoting(self): 65 safeunquoted = string.ascii_letters + string.digits + '!@%_-+=:,./' 66 unsafe = '"`$\\' 67 77 safeunquoted = string.ascii_letters + string.digits + '@%_-+=:,./' 78 unsafe = '"`$\\!' 79 80 self.assertEqual(pipes.quote(''), "''") 68 81 self.assertEqual(pipes.quote(safeunquoted), safeunquoted) 69 82 self.assertEqual(pipes.quote('test file name'), "'test file name'") … … 73 86 for u in unsafe: 74 87 self.assertEqual(pipes.quote("test%s'name'" % u), 75 '"test\\%s\'name\'"' % u) 76 77 self.assertEqual(pipes.quote(''), "''") 88 "'test%s'\"'\"'name'\"'\"''" % u) 78 89 79 90 def testRepr(self): … … 188 199 def test_main(): 189 200 run_unittest(SimplePipeTests) 201 reap_children() 190 202 191 203 if __name__ == "__main__":
Note:
See TracChangeset
for help on using the changeset viewer.