Commits

Armin Rigo committed a9952be

Write systematic tests for the 12 possible cases of installation.
Minor clean-ups.

  • Participants
  • Parent commits 614f97f

Comments (0)

Files changed (22)

testing/snippets/basic_verify/setup.py

-
-from distutils.core import setup
-import snip_basic_verify
-
-setup(
-    packages=['snip_basic_verify'],
-    ext_modules=[snip_basic_verify.ffi.verifier.get_extension()])

testing/snippets/basic_verify/snip_basic_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/snippets/distutils_module/setup.py

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

testing/snippets/distutils_module/snip_basic_verify.py

+
+from cffi import FFI
+import sys
+
+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
+     force_generic_engine=hasattr(sys, '_force_generic_engine_'))

testing/snippets/distutils_package_1/setup.py

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

testing/snippets/distutils_package_1/snip_basic_verify1/__init__.py

+
+from cffi import FFI
+import sys
+
+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
+     force_generic_engine=hasattr(sys, '_force_generic_engine_'))

testing/snippets/distutils_package_2/setup.py

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

testing/snippets/distutils_package_2/snip_basic_verify2/__init__.py

+
+from cffi import FFI
+import sys
+
+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
+     ext_package='snip_basic_verify2',
+     force_generic_engine=hasattr(sys, '_force_generic_engine_'))

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_module/setup.py

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

testing/snippets/setuptools_module/snip_setuptools_verify.py

+
+from cffi import FFI
+import sys
+
+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
+     force_generic_engine=hasattr(sys, '_force_generic_engine_'))

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/snippets/setuptools_package_1/setup.py

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

testing/snippets/setuptools_package_1/snip_setuptools_verify1/__init__.py

+
+from cffi import FFI
+import sys
+
+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
+     force_generic_engine=hasattr(sys, '_force_generic_engine_'))

testing/snippets/setuptools_package_2/setup.py

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

testing/snippets/setuptools_package_2/snip_setuptools_verify2/__init__.py

+
+from cffi import FFI
+import sys
+
+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
+     ext_package='snip_setuptools_verify2',
+     force_generic_engine=hasattr(sys, '_force_generic_engine_'))

testing/snippets/setuptools_verify/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_verify/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 subprocess
-from testing.udir import udir
-
-class DummyLogger(object):
-    indent = 0
-    
-    def __getattr__(self, attr):
-        return lambda *args: None
-
-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()
-    python_f = udir.join('x.py')
-    python_f.write(py.code.Source(python_snippet))
-    try:
-        os.chdir(str(SNIPPET_DIR.join(dirname)))
-        venv = venv_dir.join('bin/activate')
-        p = subprocess.Popen(['bash', '-c', '. %(venv)s && python setup.py '
-                              'install && python %(python_f)s' % locals()],
-                             stdout=subprocess.PIPE, stderr=subprocess.PIPE)
-        stdout, stderr = p.communicate()
-        if p.returncode != 0:
-            print stdout
-            print stderr
-            raise Exception("crashed")
-    finally:
-        os.chdir(olddir)
-
-def test_infrastructure():
-    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('basic_verify')
-    run_setup_and_program("basic_verify", venv_dir, '''
-    import snip_basic_verify
-    p = snip_basic_verify.C.getpwuid(0)
-    assert snip_basic_verify.ffi.string(p.pw_name) == "root"
-    ''')
-
-def test_setuptools_verify():
-    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"
-    ''')

testing/test_zintegration.py

+import py, os, sys, shutil
+import subprocess
+from testing.udir import udir
+
+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 really_run_setup_and_program(dirname, venv_dir, python_snippet):
+    shutil.rmtree(str(SNIPPET_DIR.join(dirname, 'build')),
+                  ignore_errors=True)
+    shutil.rmtree(str(SNIPPET_DIR.join(dirname, '__pycache__')),
+                  ignore_errors=True)
+    olddir = os.getcwd()
+    python_f = udir.join('x.py')
+    python_f.write(py.code.Source(python_snippet))
+    try:
+        os.chdir(str(SNIPPET_DIR.join(dirname)))
+        venv = venv_dir.join('bin/activate')
+        p = subprocess.Popen(['bash', '-c', '. %(venv)s && '
+                              'python setup.py clean && '
+                              'python setup.py install && '
+                              'python %(python_f)s' % locals()])
+        p.communicate()
+        if p.returncode != 0:
+            raise Exception("crashed")
+    finally:
+        os.chdir(olddir)
+
+def run_setup_and_program(dirname, python_snippet):
+    venv_dir = create_venv(dirname + '-cpy')
+    really_run_setup_and_program(dirname, venv_dir, python_snippet)
+    #
+    sys._force_generic_engine_ = True
+    try:
+        venv_dir = create_venv(dirname + '-gen')
+        really_run_setup_and_program(dirname, venv_dir, python_snippet)
+    finally:
+        del sys._force_generic_engine_
+
+def test_infrastructure():
+    run_setup_and_program('infrastructure', '''
+    import snip_infrastructure
+    assert snip_infrastructure.func() == 42
+    ''')
+
+def test_distutils_module():
+    run_setup_and_program("distutils_module", '''
+    import snip_basic_verify
+    p = snip_basic_verify.C.getpwuid(0)
+    assert snip_basic_verify.ffi.string(p.pw_name) == "root"
+    ''')
+
+def test_distutils_package_1():
+    run_setup_and_program("distutils_package_1", '''
+    import snip_basic_verify1
+    p = snip_basic_verify1.C.getpwuid(0)
+    assert snip_basic_verify1.ffi.string(p.pw_name) == "root"
+    ''')
+
+def test_distutils_package_2():
+    run_setup_and_program("distutils_package_2", '''
+    import snip_basic_verify2
+    p = snip_basic_verify2.C.getpwuid(0)
+    assert snip_basic_verify2.ffi.string(p.pw_name) == "root"
+    ''')
+
+def test_setuptools_module():
+    run_setup_and_program("setuptools_module", '''
+    import snip_setuptools_verify
+    p = snip_setuptools_verify.C.getpwuid(0)
+    assert snip_setuptools_verify.ffi.string(p.pw_name) == "root"
+    ''')
+
+def test_setuptools_package_1():
+    run_setup_and_program("setuptools_package_1", '''
+    import snip_setuptools_verify1
+    p = snip_setuptools_verify1.C.getpwuid(0)
+    assert snip_setuptools_verify1.ffi.string(p.pw_name) == "root"
+    ''')
+
+def test_setuptools_package_2():
+    run_setup_and_program("setuptools_package_2", '''
+    import snip_setuptools_verify2
+    p = snip_setuptools_verify2.C.getpwuid(0)
+    assert snip_setuptools_verify2.ffi.string(p.pw_name) == "root"
+    ''')