Commits

Maciej Fijalkowski committed 4a8e419

use udir and check in more cases

Comments (0)

Files changed (5)

testing/snippets/package/setup.py

+
+from distutils.core import setup
+import snip_package
+
+setup(
+    ext_package=['ext_package'],
+    ext_modules=[snip_package.ffi.verifier.get_extension()])

testing/snippets/package/snip_package/__init__.py

+
+from cffi import FFI
+
+ffi = FFI()
+ffi.cdef("""     // some declarations from the man page
+    struct passwd {
+        char *pw_name;
+        ...;
+    };
+    struct passwd *getpwuid(int uid);
+""")
+C = ffi.verify("""   // passed to the real C compiler
+#include <sys/types.h>
+#include <pwd.h>
+""", libraries=[], ext_package="ext_package")

testing/snippets/setuptools_package/setup.py

+
+from setuptools import setup
+import snip_setuptools_verify
+
+setup(
+    zip_safe=False,
+    packages=['snip_setuptools_verify'],
+    ext_modules=[snip_setuptools_verify.ffi.verifier.get_extension()])

testing/snippets/setuptools_package/snip_setuptools_verify/__init__.py

+
+from cffi import FFI
+
+ffi = FFI()
+ffi.cdef("""     // some declarations from the man page
+    struct passwd {
+        char *pw_name;
+        ...;
+    };
+    struct passwd *getpwuid(int uid);
+""")
+C = ffi.verify("""   // passed to the real C compiler
+#include <sys/types.h>
+#include <pwd.h>
+""", libraries=[])   # or a list of libraries to link with

testing/test_integration.py

 
 import py, os, sys
-import tempfile
 import subprocess
+from testing.udir import udir
 
 class DummyLogger(object):
     indent = 0
     def __getattr__(self, attr):
         return lambda *args: None
 
-def create_venv():
-    tmpdir = tempfile.mkdtemp()
-    subprocess.call(['virtualenv', '-p', sys.executable, tmpdir])
-    return py.path.local(tmpdir)
+def create_venv(name):
+    tmpdir = udir.join(name)
+    subprocess.call(['virtualenv', '-p', sys.executable, str(tmpdir)])
+    return tmpdir
 
 SNIPPET_DIR = py.path.local(__file__).join('..', 'snippets')
 
 def run_setup_and_program(dirname, venv_dir, python_snippet):
     olddir = os.getcwd()
-    tmpdir2 = py.path.local(tempfile.mkdtemp()) # this is for python files
-    python_f = tmpdir2.join('x.py')
+    python_f = udir.join('x.py')
     python_f.write(py.code.Source(python_snippet))
     try:
         os.chdir(str(SNIPPET_DIR.join(dirname)))
         os.chdir(olddir)
 
 def test_infrastructure():
-    venv_dir = create_venv()
+    venv_dir = create_venv('infrastructure')
     run_setup_and_program('infrastructure', venv_dir, '''
     import snip_infrastructure
     assert snip_infrastructure.func() == 42
     ''')
 
 def test_basic_verify():
-    venv_dir = create_venv()
+    venv_dir = create_venv('basic_verify')
     run_setup_and_program("basic_verify", venv_dir, '''
     import snip_basic_verify
     p = snip_basic_verify.C.getpwuid(0)
     ''')
 
 def test_setuptools_verify():
-    venv_dir = create_venv()
+    venv_dir = create_venv('setuptools_verify')
     run_setup_and_program("setuptools_verify", venv_dir, '''
     import snip_setuptools_verify
     p = snip_setuptools_verify.C.getpwuid(0)
     assert snip_setuptools_verify.ffi.string(p.pw_name) == "root"
     ''')
     
+def test_package():
+    venv_dir = create_venv('package')
+    run_setup_and_program("package", venv_dir, '''
+    import snip_package
+    p = snip_package.C.getpwuid(0)
+    assert snip_package.ffi.string(p.pw_name) == "root"
+    ''')