[pypy-commit] cffi cpy-extension: Fix tests.

arigo noreply at buildbot.pypy.org
Tue Jun 12 16:29:31 CEST 2012


Author: Armin Rigo <arigo at tunes.org>
Branch: cpy-extension
Changeset: r291:fd2838e95908
Date: 2012-06-12 16:29 +0200
http://bitbucket.org/cffi/cffi/changeset/fd2838e95908/

Log:	Fix tests.

diff --git a/cffi/verifier.py b/cffi/verifier.py
--- a/cffi/verifier.py
+++ b/cffi/verifier.py
@@ -76,8 +76,14 @@
                 # float types
                 converter = 'PyFloat_AsDouble'
                 errvalue = '-1'
+            elif tp.name.startswith('unsigned '):
+                # unsigned integer types
+                xxx
+            elif tp.name == 'char':
+                # char
+                xxx
             else:
-                # integer types
+                # signed integer types
                 xxx
         #
         elif isinstance(tp, model.PointerType):
diff --git a/testing/backend_tests.py b/testing/backend_tests.py
--- a/testing/backend_tests.py
+++ b/testing/backend_tests.py
@@ -50,6 +50,8 @@
         else:
             min = -(1 << (8*size-1))
             max = (1 << (8*size-1)) - 1
+        min = int(min)
+        max = int(max)
         p = ffi.cast(c_decl, min)
         assert p != min       # no __eq__(int)
         assert bool(p) is True
@@ -68,6 +70,10 @@
         py.test.raises(OverflowError, ffi.new, c_decl, max + 1)
         py.test.raises(OverflowError, ffi.new, c_decl, long(min - 1))
         py.test.raises(OverflowError, ffi.new, c_decl, long(max + 1))
+        assert ffi.new(c_decl, min)[0] == min
+        assert ffi.new(c_decl, max)[0] == max
+        assert ffi.new(c_decl, long(min))[0] == min
+        assert ffi.new(c_decl, long(max))[0] == max
 
     def test_new_single_integer(self):
         ffi = FFI(backend=self.Backend())
diff --git a/testing/test_function.py b/testing/test_function.py
--- a/testing/test_function.py
+++ b/testing/test_function.py
@@ -36,7 +36,7 @@
         ffi.cdef("""
             double sin(double x);
         """)
-        m = ffi.load("m")
+        m = ffi.rawload("m")
         x = m.sin(1.23)
         assert x == math.sin(1.23)
 
@@ -45,7 +45,7 @@
         ffi.cdef("""
             float sinf(float x);
         """)
-        m = ffi.load("m")
+        m = ffi.rawload("m")
         x = m.sinf(1.23)
         assert type(x) is float
         assert x != math.sin(1.23)    # rounding effects
@@ -57,6 +57,7 @@
             int puts(const char *);
             int fflush(void *);
         """)
+        ffi.C = ffi.rawload(None)
         ffi.C.puts   # fetch before capturing, for easier debugging
         with FdWriteCapture() as fd:
             ffi.C.puts("hello")
@@ -71,6 +72,7 @@
             int puts(char *);
             int fflush(void *);
         """)
+        ffi.C = ffi.rawload(None)
         ffi.C.puts   # fetch before capturing, for easier debugging
         with FdWriteCapture() as fd:
             ffi.C.puts("hello")
@@ -85,6 +87,7 @@
             int fputs(const char *, void *);
             void *stdout, *stderr;
         """)
+        ffi.C = ffi.rawload(None)
         with FdWriteCapture(2) as fd:
             ffi.C.fputs("hello from stderr\n", ffi.C.stderr)
         res = fd.getvalue()
@@ -96,6 +99,7 @@
            int printf(const char *format, ...);
            int fflush(void *);
         """)
+        ffi.C = ffi.rawload(None)
         with FdWriteCapture() as fd:
             ffi.C.printf("hello with no arguments\n")
             ffi.C.printf("hello, %s!\n", ffi.new("char[]", "world"))
@@ -119,6 +123,7 @@
         ffi.cdef("""
            int printf(const char *format, ...);
         """)
+        ffi.C = ffi.rawload(None)
         e = py.test.raises(TypeError, ffi.C.printf, "hello %d\n", 42)
         assert str(e.value) == ("argument 2 passed in the variadic part "
                                 "needs to be a cdata object (got int)")
@@ -128,6 +133,7 @@
         ffi.cdef("""
             int puts(const char *);
         """)
+        ffi.C = ffi.rawload(None)
         fptr = ffi.C.puts
         assert ffi.typeof(fptr) == ffi.typeof("int(*)(const char*)")
         if self.Backend is CTypesBackend:
@@ -148,6 +154,7 @@
             int puts(const char *);
             int fflush(void *);
         """)
+        ffi.C = ffi.rawload(None)
         fptr = ffi.cast("int(*)(const char *txt)", ffi.C.puts)
         assert fptr == ffi.C.puts
         assert repr(fptr) == "<cdata 'int(*)(char *)'>"
@@ -162,6 +169,7 @@
         ffi.cdef("""
             int strlen(char[]);
         """)
+        ffi.C = ffi.rawload(None)
         p = ffi.new("char[]", "hello")
         res = ffi.C.strlen(p)
         assert res == 5
@@ -172,6 +180,7 @@
             int puts(const char *);
             void *stdout, *stderr;
         """)
+        ffi.C = ffi.rawload(None)
         pout = ffi.C.stdout
         perr = ffi.C.stderr
         assert repr(pout) == "<cdata 'void *'>"
@@ -190,6 +199,7 @@
         ffi.cdef("""
             char *strchr(const char *s, int c);
         """)
+        ffi.C = ffi.rawload(None)
         p = ffi.new("char[]", "hello world!")
         q = ffi.C.strchr(p, ord('w'))
         assert str(q) == "world!"
@@ -200,6 +210,7 @@
             struct in_addr { unsigned int s_addr; };
             char *inet_ntoa(struct in_addr in);
         """)
+        ffi.C = ffi.rawload(None)
         ina = ffi.new("struct in_addr", [0x04040404])
         a = ffi.C.inet_ntoa(ina[0])
         assert str(a) == '4.4.4.4'
diff --git a/testing/test_ownlib.py b/testing/test_ownlib.py
--- a/testing/test_ownlib.py
+++ b/testing/test_ownlib.py
@@ -33,10 +33,11 @@
         ffi.cdef("""
             int test_getting_errno(void);
         """)
-        ownlib = ffi.load(self.module)
+        ownlib = ffi.rawload(self.module)
+        C = ffi.rawload(None)
         res = ownlib.test_getting_errno()
         assert res == -1
-        assert ffi.C.errno == 123
+        assert C.errno == 123
 
     def test_setting_errno(self):
         if self.Backend is CTypesBackend and '__pypy__' in sys.modules:
@@ -45,8 +46,9 @@
         ffi.cdef("""
             int test_setting_errno(void);
         """)
-        ownlib = ffi.load(self.module)
-        ffi.C.errno = 42
+        ownlib = ffi.rawload(self.module)
+        C = ffi.rawload(None)
+        C.errno = 42
         res = ownlib.test_setting_errno()
         assert res == 42
-        assert ffi.C.errno == 42
+        assert C.errno == 42


More information about the pypy-commit mailing list