Commits

Armin Rigo committed 568b239

Fix the tests for Python 3.

Comments (0)

Files changed (2)

testing/backend_tests.py

 SIZE_OF_PTR   = ctypes.sizeof(ctypes.c_void_p)
 SIZE_OF_WCHAR = ctypes.sizeof(ctypes.c_wchar)
 
-if sys.version_info < (3, 3):
-    bufitem = lambda x: x
-else:
-    bufitem = ord
-
 
 class BackendTests:
 
         assert len(content) == len(b) == 2
         if sys.byteorder == 'little':
             assert content == b'\x64\x00'
-            assert b[0] == bufitem(b'\x64')
-            b[0] = bufitem(b'\x65')
+            assert b[0] == b'\x64'
+            b[0] = b'\x65'
         else:
             assert content == b'\x00\x64'
-            assert b[1] == bufitem(b'\x64')
-            b[1] = bufitem(b'\x65')
+            assert b[1] == b'\x64'
+            b[1] = b'\x65'
         assert a[0] == 101
 
     def test_ffi_buffer_array(self):
         content = b[:]
         if sys.byteorder == 'little':
             assert content.startswith(b'\x64\x00\x00\x00\x65\x00\x00\x00')
-            b[4] = bufitem(b'\x45')
+            b[4] = b'\x45'
         else:
             assert content.startswith('\x00\x00\x00\x64\x00\x00\x00\x65')
-            b[7] = bufitem(b'\x45')
+            b[7] = b'\x45'
         assert len(content) == 4 * 10
         assert a[1] == 0x45
 
         assert len(content) == 1
         if sys.byteorder == 'little':
             assert content == b'\x43'
-            b[0] = bufitem(b'\x62')
+            b[0] = b'\x62'
             assert a[0] == 0x4262
         else:
             assert content == b'\x42'
-            b[0] = bufitem(b'\x63')
+            b[0] = b'\x63'
             assert a[0] == 0x6343
 
     def test_ffi_buffer_array_size(self):

testing/test_verify.py

             return result;
         }
     """)
-    import posix
-    fdr, fdw = posix.pipe()
-    fw1 = posix.fdopen(fdw, 'wb', 256)
+    import os
+    fdr, fdw = os.pipe()
+    fw1 = os.fdopen(fdw, 'wb', 256)
     old_stdout = lib.setstdout(fw1)
     try:
         #
     finally:
         lib.setstdout(old_stdout)
     #
-    result = posix.read(fdr, 256)
-    posix.close(fdr)
-    assert result == b"Xhello, 42!\n"
+    result = os.read(fdr, 256)
+    os.close(fdr)
+    # the 'X' might remain in the user-level buffer of 'fw1' and
+    # end up showing up after the 'hello, 42!\n'
+    assert result == b"Xhello, 42!\n" or result == b"hello, 42!\nX"
 
 def test_FILE_stored_explicitly():
     ffi = FFI()
             return fprintf(myfile, out, value);
         }
     """)
-    import posix
-    fdr, fdw = posix.pipe()
-    fw1 = posix.fdopen(fdw, 'wb', 256)
+    import os
+    fdr, fdw = os.pipe()
+    fw1 = os.fdopen(fdw, 'wb', 256)
     lib.myfile = ffi.cast("FILE *", fw1)
     #
     fw1.write(b"X")
     fw1.close()
     assert r == len("hello, 42!\n")
     #
-    result = posix.read(fdr, 256)
-    posix.close(fdr)
-    assert result == b"Xhello, 42!\n"
+    result = os.read(fdr, 256)
+    os.close(fdr)
+    # the 'X' might remain in the user-level buffer of 'fw1' and
+    # end up showing up after the 'hello, 42!\n'
+    assert result == b"Xhello, 42!\n" or result == b"hello, 42!\nX"
 
 def test_global_array_with_missing_length():
     ffi = FFI()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.