]> granicus.if.org Git - python/commitdiff
Fix sporadic test_os failure under Windows
authorAntoine Pitrou <solipsis@pitrou.net>
Wed, 22 Feb 2012 21:16:25 +0000 (22:16 +0100)
committerAntoine Pitrou <solipsis@pitrou.net>
Wed, 22 Feb 2012 21:16:25 +0000 (22:16 +0100)
Lib/test/test_os.py

index 4898e4ea091cfaba91fbd94ed13b0d9929583f76..1d673f65202d6321264b1fada3b45a7a1fb25798 100644 (file)
@@ -541,10 +541,12 @@ class URandomTests (unittest.TestCase):
         self.assertNotEqual(data1, data2)
 
     def get_urandom_subprocess(self, count):
+        # We need to use repr() and eval() to avoid line ending conversions
+        # under Windows.
         code = '\n'.join((
             'import os, sys',
             'data = os.urandom(%s)' % count,
-            'sys.stdout.write(data)',
+            'sys.stdout.write(repr(data))',
             'sys.stdout.flush()',
             'print >> sys.stderr, (len(data), data)'))
         cmd_line = [sys.executable, '-c', code]
@@ -552,7 +554,8 @@ class URandomTests (unittest.TestCase):
                              stdout=subprocess.PIPE, stderr=subprocess.PIPE)
         out, err = p.communicate()
         self.assertEqual(p.wait(), 0, (p.wait(), err))
-        self.assertEqual(len(out), count)
+        out = eval(out)
+        self.assertEqual(len(out), count, err)
         return out
 
     def test_urandom_subprocess(self):