[pypy-commit] cffi default: another approach

fijal noreply at buildbot.pypy.org
Sat Sep 22 13:26:57 CEST 2012


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: 
Changeset: r960:a71441696379
Date: 2012-09-22 13:26 +0200
http://bitbucket.org/cffi/cffi/changeset/a71441696379/

Log:	another approach

diff --git a/testing/test_integration.py b/testing/test_integration.py
--- a/testing/test_integration.py
+++ b/testing/test_integration.py
@@ -1,6 +1,7 @@
 
-import py, sys, os
+import py, os, sys
 import tempfile
+import subprocess
 
 class DummyLogger(object):
     indent = 0
@@ -12,22 +13,42 @@
     import virtualenv
     tmpdir = tempfile.mkdtemp()
     virtualenv.logger = DummyLogger()
-    virtualenv.create_environment(tmpdir, site_packages=False)
-    tmpdir = py.path.local(tmpdir)
-    execfile(str(tmpdir.join("bin", "activate_this.py")))
+    virtualenv.create_environment(tmpdir, site_packages=True)
+    return py.path.local(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.write(py.code.Source(python_snippet))
+    try:
+        os.chdir(str(SNIPPET_DIR.join(dirname)))
+        python = sys.executable
+        venv = venv_dir.join('bin/activate')
+        p = subprocess.Popen(['bash', '-c', '. %(venv)s && %(python)s setup.py '
+                              'install && %(python)s %(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():
-    create_venv()
-    oldargv = sys.argv
-    olddir = os.getcwd()
-    try:
-        os.chdir(str(SNIPPET_DIR.join('infrastructure')))
-        sys.argv = ['setup.py', 'install']
-        execfile(str(SNIPPET_DIR.join('infrastructure', 'setup.py')))
-    finally:
-        sys.argv = oldargv
-        os.chdir(olddir)
+    venv_dir = create_venv()
+    run_setup_and_program('infrastructure', venv_dir, '''
     import snip_infrastructure
     assert snip_infrastructure.func() == 42
+    ''')
+
+def test_basic_verify():
+    venv_dir = create_venv()
+    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"
+    ''')


More information about the pypy-commit mailing list