Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r63555:a0e9d0c4bc94
Date: 2013-04-22 11:50 -0700
http://bitbucket.org/pypy/pypy/changeset/a0e9d0c4bc94/

Log:    check for usemodules in appdirect tests

diff --git a/pypy/tool/pytest/apptest.py b/pypy/tool/pytest/apptest.py
--- a/pypy/tool/pytest/apptest.py
+++ b/pypy/tool/pytest/apptest.py
@@ -18,6 +18,13 @@
 from pypy.conftest import PyPyClassCollector
 from inspect import getmro
 
+RENAMED_USEMODULES = dict(
+    _winreg='winreg',
+    exceptions='__exceptions__',
+    rctime='time',
+    struct='_struct',
+    thread='_thread',
+    )
 
 class AppError(Exception):
     def __init__(self, excinfo):
@@ -53,7 +60,7 @@
         return repr(value)
 
 
-def run_with_python(python_, target_, **definitions):
+def run_with_python(python_, target_, usemodules, **definitions):
     if python_ is None:
         py.test.skip("Cannot find the default python3 interpreter to run with 
-A")
     # we assume that the source of target_ is in utf-8. Unfortunately, we don't
@@ -62,6 +69,7 @@
     helpers = r"""# -*- encoding: utf-8 -*-
 if 1:
     import sys
+%s
     def skip(message):
         print(message)
         raise SystemExit(0)
@@ -118,6 +126,14 @@
                                 dict)) or value is None:
             defs.append("self.%s = %s\n" % (symbol, py3k_repr(value)))
 
+    check_usemodules = ''
+    if usemodules:
+        usemodules = [RENAMED_USEMODULES.get(name, name)
+                      for name in usemodules]
+        check_usemodules = """\
+    if not set(%r).issubset(sys.builtin_module_names):
+        sys.exit(81)""" % usemodules
+
     source = list(py.code.Source(target_))
     while source[0].startswith(('@py.test.mark.', '@pytest.mark.')):
         source.pop(0)
@@ -130,7 +146,7 @@
     else:
         target_name = target_.__name__
     with pyfile.open('w') as f:
-        f.write(helpers)
+        f.write(helpers % check_usemodules)
         f.write('\n'.join(defs))
         f.write('def %s():\n' % target_name)
         f.write('\n'.join(source))
@@ -140,7 +156,10 @@
     print pyfile.read()
     print >> sys.stdout, stdout
     print >> sys.stderr, stderr
-    if res > 0:
+    if res == 81:
+        py.test.skip('%r was not compiled w/ required usemodules: %r' %
+                     (python_, usemodules))
+    elif res > 0:
         raise AssertionError("Subprocess failed:\n" + stderr)
 
 
@@ -183,7 +202,7 @@
         target = self.obj
         src = extract_docstring_if_empty_function(target)
         if self.config.option.runappdirect:
-            return run_with_python(self.config.option.python, src)
+            return run_with_python(self.config.option.python, src, None)
         space = gettestobjspace()
         filename = self._getdynfilename(target)
         func = app2interp_temp(src, filename=filename)
@@ -230,7 +249,9 @@
         space = target.im_self.space
         if self.config.option.runappdirect:
             appexec_definitions = self.parent.obj.__dict__
-            return run_with_python(self.config.option.python, src,
+            spaceconfig = getattr(self.parent.obj, 'spaceconfig', None)
+            usemodules = spaceconfig.get('usemodules') if spaceconfig else None
+            return run_with_python(self.config.option.python, src, usemodules,
                                    **appexec_definitions)
         filename = self._getdynfilename(target)
         func = app2interp_temp(src, filename=filename)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to