diff options
Diffstat (limited to 'testing/embedding')
-rw-r--r-- | testing/embedding/add1.py | 6 | ||||
-rw-r--r-- | testing/embedding/add_recursive.py | 2 | ||||
-rw-r--r-- | testing/embedding/test_basic.py | 13 | ||||
-rw-r--r-- | testing/embedding/test_performance.py | 4 | ||||
-rw-r--r-- | testing/embedding/test_thread.py | 26 | ||||
-rw-r--r-- | testing/embedding/withunicode.py | 26 |
6 files changed, 59 insertions, 18 deletions
diff --git a/testing/embedding/add1.py b/testing/embedding/add1.py index e5b3de1..6f89ae9 100644 --- a/testing/embedding/add1.py +++ b/testing/embedding/add1.py @@ -11,7 +11,11 @@ ffi.embedding_init_code(r""" sys.stdout.write("preparing") for i in range(3): sys.stdout.flush() - time.sleep(0.2) + # Windows: sometimes time.sleep() doesn't sleep at all. + # This appears to occur on recent versions of python only. + t_end = time.time() + 0.19 + while time.time() < t_end: + time.sleep(0.2) sys.stdout.write(".") sys.stdout.write("\n") diff --git a/testing/embedding/add_recursive.py b/testing/embedding/add_recursive.py index 9fa463d..a88aa8f 100644 --- a/testing/embedding/add_recursive.py +++ b/testing/embedding/add_recursive.py @@ -3,7 +3,7 @@ import cffi ffi = cffi.FFI() ffi.embedding_api(""" - int (*my_callback)(int); + extern int (*my_callback)(int); int add_rec(int, int); """) diff --git a/testing/embedding/test_basic.py b/testing/embedding/test_basic.py index 8463c3f..8d2e776 100644 --- a/testing/embedding/test_basic.py +++ b/testing/embedding/test_basic.py @@ -63,8 +63,8 @@ class EmbeddingTests: output = popen.stdout.read() err = popen.wait() if err: - raise OSError("popen failed with exit code %r: %r" % ( - err, args)) + raise OSError(("popen failed with exit code %r: %r\n\n%s" % ( + err, args, output)).rstrip()) print(output.rstrip()) return output @@ -172,7 +172,8 @@ if sys.platform == 'win32': result = popen.stdout.read() err = popen.wait() if err: - raise OSError("%r failed with exit code %r" % (name, err)) + raise OSError("%r failed with exit code %r" % ( + os.path.join(path, executable_name), err)) return result @@ -205,3 +206,9 @@ class TestBasic(EmbeddingTests): self.compile('add1-test', [initerror_cffi]) output = self.execute('add1-test') assert output == "got: 0 0\n" # plus lots of info to stderr + + def test_embedding_with_unicode(self): + withunicode_cffi = self.prepare_module('withunicode') + self.compile('add1-test', [withunicode_cffi]) + output = self.execute('add1-test') + assert output == "255\n4660\n65244\ngot: 0 0\n" diff --git a/testing/embedding/test_performance.py b/testing/embedding/test_performance.py index f9f2605..a0e8458 100644 --- a/testing/embedding/test_performance.py +++ b/testing/embedding/test_performance.py @@ -2,8 +2,8 @@ import sys from testing.embedding.test_basic import EmbeddingTests if sys.platform == 'win32': - import py - py.test.skip("written with POSIX functions") + import pytest + pytestmark = pytest.mark.skip("written with POSIX functions") class TestPerformance(EmbeddingTests): diff --git a/testing/embedding/test_thread.py b/testing/embedding/test_thread.py index 1895076..9a5936d 100644 --- a/testing/embedding/test_thread.py +++ b/testing/embedding/test_thread.py @@ -21,17 +21,21 @@ class TestThread(EmbeddingTests): add1_cffi = self.prepare_module('add1') add2_cffi = self.prepare_module('add2') self.compile('thread2-test', [add1_cffi, add2_cffi], threads=True) - output = self.execute('thread2-test') - output = self._take_out(output, "preparing") - output = self._take_out(output, ".") - output = self._take_out(output, ".") - # at least the 3rd dot should be after everything from ADD2 - assert output == ("starting\n" - "prepADD2\n" - "adding 1000 and 200 and 30\n" - ".\n" - "adding 40 and 2\n" - "done\n") + for i in range(3): + output = self.execute('thread2-test') + print('='*79) + print(output) + print('='*79) + output = self._take_out(output, "preparing") + output = self._take_out(output, ".") + output = self._take_out(output, ".") + # at least the 3rd dot should be after everything from ADD2 + assert output == ("starting\n" + "prepADD2\n" + "adding 1000 and 200 and 30\n" + ".\n" + "adding 40 and 2\n" + "done\n") def test_alt_issue(self): add1_cffi = self.prepare_module('add1') diff --git a/testing/embedding/withunicode.py b/testing/embedding/withunicode.py new file mode 100644 index 0000000..839c6cd --- /dev/null +++ b/testing/embedding/withunicode.py @@ -0,0 +1,26 @@ +import sys, cffi +if sys.version_info < (3,): + u_prefix = "u" +else: + u_prefix = "" + unichr = chr + + +ffi = cffi.FFI() + +ffi.embedding_api(u""" + int add1(int, int); +""") + +ffi.embedding_init_code((""" + import sys, time + for c in %s'""" + unichr(0x00ff) + unichr(0x1234) + unichr(0xfedc) + """': + sys.stdout.write(str(ord(c)) + '\\n') + sys.stdout.flush() +""") % u_prefix) + +ffi.set_source("_withunicode_cffi", """ +""") + +fn = ffi.compile(verbose=True) +print('FILENAME: %s' % (fn,)) |