Author: Armin Rigo <[email protected]>
Branch:
Changeset: r1024:568b239a7824
Date: 2012-10-30 15:08 +0100
http://bitbucket.org/cffi/cffi/changeset/568b239a7824/
Log: Fix the tests for Python 3.
diff --git a/testing/backend_tests.py b/testing/backend_tests.py
--- a/testing/backend_tests.py
+++ b/testing/backend_tests.py
@@ -9,11 +9,6 @@
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:
@@ -1078,12 +1073,12 @@
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):
@@ -1096,10 +1091,10 @@
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
@@ -1114,11 +1109,11 @@
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):
diff --git a/testing/test_verify.py b/testing/test_verify.py
--- a/testing/test_verify.py
+++ b/testing/test_verify.py
@@ -1234,9 +1234,9 @@
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:
#
@@ -1248,9 +1248,11 @@
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()
@@ -1262,9 +1264,9 @@
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")
@@ -1272,9 +1274,11 @@
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()
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit