summaryrefslogtreecommitdiff
path: root/testing/cffi1
diff options
context:
space:
mode:
authorMichal Vyskocil <michal.vyskocil@gmail.com>2019-01-08 08:32:16 +0100
committerMichal Vyskocil <michal.vyskocil@gmail.com>2019-01-08 08:32:16 +0100
commita074df4d40f178c21249bc3f0791082f6230499f (patch)
treec4a1e946f9bd659503e73c220c5c05301675af46 /testing/cffi1
parentfed468bcee7be3ce005321cbcd97fd1d1a64b567 (diff)
downloadcffi-a074df4d40f178c21249bc3f0791082f6230499f.tar.gz
Increase testing coverage and refactor method names
Making `pkgconfig.call` function accessible, tests can monkey patch it and provide mock. This improves testing, however raised a need to give functions better names than `pkgconfig.pkgconfig_kwargs` or `pkgconfig.pc`.
Diffstat (limited to 'testing/cffi1')
-rw-r--r--testing/cffi1/test_pkgconfig.py45
1 files changed, 29 insertions, 16 deletions
diff --git a/testing/cffi1/test_pkgconfig.py b/testing/cffi1/test_pkgconfig.py
index 0c72c94..e96c0b8 100644
--- a/testing/cffi1/test_pkgconfig.py
+++ b/testing/cffi1/test_pkgconfig.py
@@ -1,30 +1,43 @@
import sys
import subprocess
import py
-from cffi.pkgconfig import pkgconfig_installed, merge_dicts, pkgconfig_kwargs
+import cffi.pkgconfig as pkgconfig
-def test_merge_dicts ():
+def mock_call(libname, flag):
+ assert libname=="python-3.6", "mocked pc function supports python-3.6 input ONLY"
+
+ flags = {
+ "--cflags-only-I": b"-I/usr/include/python3.6m\n",
+ "--libs-only-L": b"-L/usr/lib64\n",
+ "--libs-only-l": b"-lpython3.6\n",
+ "--cflags-only-other": b"-DCFFI_TEST=1 -O42\n",
+ "--libs-only-other": b"-lm\n",
+ }
+ return flags[flag]
+
+pkgconfig.call = mock_call
+
+
+def test_merge_flags():
d1 = {"ham": [1, 2, 3], "spam" : ["a", "b", "c"], "foo" : []}
d2 = {"spam" : ["spam", "spam", "spam"], "bar" : ["b", "a", "z"]}
- merge_dicts (d1, d2)
+ pkgconfig.merge_flags(d1, d2)
assert d1 == {
"ham": [1, 2, 3],
"spam" : ["a", "b", "c", "spam", "spam", "spam"],
"bar" : ["b", "a", "z"],
"foo" : []}
-def test_pkgconfig ():
- if not pkgconfig_installed:
- py.test.skip ("pkg-config is not installed on the system")
-
- version = sys.version_info.major
- kwargs = {}
- try:
- kwargs = pkgconfig_kwargs ("python%s" % version)
- except subprocess.CalledProcessError as e:
- py.test.skip ("No python%s pkg-config file installed" % version)
-
- assert any (b"python" in lib for lib in kwargs ["libraries"]) == True
- assert any (b"python" in dir for dir in kwargs ["include_dirs"]) == True
+
+def test_pkgconfig():
+ kwargs = pkgconfig.flags("python-3.6")
+ assert kwargs == {
+ 'include_dirs': [b'/usr/include/python3.6m'],
+ 'library_dirs': [b'/usr/lib64'],
+ 'libraries': [b'python3.6'],
+ 'define_macros': [(b'CFFI_TEST', b'1')],
+ 'extra_compile_args': [b'-O42'],
+ 'extra_link_args': [b'-lm']
+ }