]> granicus.if.org Git - python/commitdiff
Make test_pipes a little bit more robust.
authorAntoine Pitrou <solipsis@pitrou.net>
Tue, 8 Dec 2009 19:46:38 +0000 (19:46 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Tue, 8 Dec 2009 19:46:38 +0000 (19:46 +0000)
Lib/test/test_pipes.py

index 052615961ee65e3bab4fdc48f7c081fe5cb37db4..d1053e8ae150a9342e1ff30dcaa07f3fd5c75647 100644 (file)
@@ -2,7 +2,7 @@ import pipes
 import os
 import string
 import unittest
-from test.test_support import TESTFN, run_unittest, unlink
+from test.test_support import TESTFN, run_unittest, unlink, reap_children
 
 if os.name != 'posix':
     raise unittest.SkipTest('pipes module only works on posix')
@@ -36,7 +36,8 @@ class SimplePipeTests(unittest.TestCase):
         file(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')
+        with t.open(TESTFN, 'r') as f:
+            self.assertEqual(f.read(), 'HELLO WORLD #2')
 
     def testEmptyPipeline1(self):
         # copy through empty pipe
@@ -52,7 +53,8 @@ class SimplePipeTests(unittest.TestCase):
         d = 'empty pipeline test READ'
         file(TESTFN, 'w').write(d)
         t=pipes.Template()
-        self.assertEqual(t.open(TESTFN, 'r').read(), d)
+        with t.open(TESTFN, 'r') as f:
+            self.assertEqual(f.read(), d)
 
     def testEmptyPipeline3(self):
         # write through empty pipe
@@ -185,6 +187,7 @@ class SimplePipeTests(unittest.TestCase):
 
 def test_main():
     run_unittest(SimplePipeTests)
+    reap_children()
 
 if __name__ == "__main__":
     test_main()