[pypy-commit] pypy use-file-star-for-file: this test fails on cpython on mac/win, adjust

bdkearns noreply at buildbot.pypy.org
Fri Sep 12 02:44:34 CEST 2014


Author: Brian Kearns <bdkearns at gmail.com>
Branch: use-file-star-for-file
Changeset: r73496:120342e28cf1
Date: 2014-09-11 17:43 -0700
http://bitbucket.org/pypy/pypy/changeset/120342e28cf1/

Log:	this test fails on cpython on mac/win, adjust

diff --git a/pypy/module/_file/test/test_file_extra.py b/pypy/module/_file/test/test_file_extra.py
--- a/pypy/module/_file/test/test_file_extra.py
+++ b/pypy/module/_file/test/test_file_extra.py
@@ -431,6 +431,7 @@
         f.close()
 
     def test_rw_bin(self):
+        import sys
         import random
         flags = 'w+b'
         checkflags = 'rb'
@@ -440,44 +441,49 @@
         f = file(fn, flags)
         expected = ''
         pos = 0
-        for i in range(5000):
-            x = random.random()
-            if x < 0.4:
-                l = int(x*100)
-                buf = f.read(l)
-                assert buf == expected[pos:pos+l]
-                pos += len(buf)
-            elif x < 0.75:
-                writeeol, expecteol = random.choice(eolstyles)
-                x = str(x)
-                buf1 = x+writeeol
-                buf2 = x+expecteol
-                f.write(buf1)
-                expected = expected[:pos] + buf2 + expected[pos+len(buf2):]
-                pos += len(buf2)
-            elif x < 0.80:
-                pos = random.randint(0, len(expected))
-                f.seek(pos)
-            elif x < 0.85:
-                pos = random.randint(0, len(expected))
-                f.seek(pos - len(expected), 2)
-            elif x < 0.90:
-                currentpos = pos
-                pos = random.randint(0, len(expected))
-                f.seek(pos - currentpos, 1)
-            elif x < 0.95:
-                assert f.tell() == pos
-            else:
-                f.flush()
-                g = open(fn, checkflags)
-                buf = g.read()
-                g.close()
-                assert buf == expected
-        f.close()
-        g = open(fn, checkflags)
-        buf = g.read()
-        g.close()
-        assert buf == expected
+        try:
+            for i in range(5000):
+                x = random.random()
+                if x < 0.4:
+                    l = int(x*100)
+                    buf = f.read(l)
+                    assert buf == expected[pos:pos+l]
+                    pos += len(buf)
+                elif x < 0.75:
+                    writeeol, expecteol = random.choice(eolstyles)
+                    x = str(x)
+                    buf1 = x+writeeol
+                    buf2 = x+expecteol
+                    f.write(buf1)
+                    expected = expected[:pos] + buf2 + expected[pos+len(buf2):]
+                    pos += len(buf2)
+                elif x < 0.80:
+                    pos = random.randint(0, len(expected))
+                    f.seek(pos)
+                elif x < 0.85:
+                    pos = random.randint(0, len(expected))
+                    f.seek(pos - len(expected), 2)
+                elif x < 0.90:
+                    currentpos = pos
+                    pos = random.randint(0, len(expected))
+                    f.seek(pos - currentpos, 1)
+                elif x < 0.95:
+                    assert f.tell() == pos
+                else:
+                    f.flush()
+                    g = open(fn, checkflags)
+                    buf = g.read()
+                    g.close()
+                    assert buf == expected
+            f.close()
+            g = open(fn, checkflags)
+            buf = g.read()
+            g.close()
+            assert buf == expected
+        except AssertionError:
+            assert sys.platform in {'darwin', 'win32'}
+        else:
+            assert sys.platform.startswith('linux')
 
     def test_rw(self):
         fn = self.temptestfile


More information about the pypy-commit mailing list