Commits

Amaury Forgeot d'Arc committed 1506731

Fix tests in module/imp, and add -A support to run most of them.

Comments (0)

Files changed (3)

pypy/module/imp/test/test_app.py

 from __future__ import with_statement
 from pypy.tool.udir import udir
 
-MARKER = 42
-
 class AppTestImpModule:
     spaceconfig = dict(usemodules=('imp',))
 
         cls.w_udir = cls.space.wrap(str(udir))
 
     def w__py_file(self):
-        fn = self.file_module
-        if fn.lower().endswith('c') or fn.lower().endswith('o'):
-            fn = fn[:-1]
-        assert fn.lower().endswith('.py')
-        return fn
+        f = open('@TEST.py', 'w')
+        f.write('MARKER = 42\n')
+        f.close()
+        return '@TEST.py'
 
     def w__pyc_file(self):
         import marshal, imp

pypy/module/imp/test/test_import.py

     """)
 
 class AppTestImport:
-    spaceconfig = dict(usemodules=['itertools'])
-
     def setup_class(cls): # interpreter-level
         cls.w_runappdirect = cls.space.wrap(conftest.option.runappdirect)
-        cls.saved_modules = _setup(cls.space)
+        cls.w_saved_modules = _setup(cls.space)
         #XXX Compile class
 
         
     def teardown_class(cls): # interpreter-level
-        _teardown(cls.space, cls.saved_modules)
+        _teardown(cls.space, cls.w_saved_modules)
 
     def w_exec_(self, cmd, ns):
         exec(cmd, ns)

pypy/tool/pytest/apptest.py

             defs.append(str(code))
             args = ','.join(repr(arg) for arg in args)
             defs.append("self.%s = anonymous(%s)\n" % (symbol, args))
+        elif isinstance(value, types.MethodType):
+            # "def w_method(self)"
+            code = py.code.Code(value)
+            defs.append(str(code.source()))
+            defs.append("type(self).%s = w_%s\n" % (symbol, symbol))
+        elif isinstance(value, types.ModuleType):
+            name = value.__name__
+            defs.append("import %s; self.%s = %s\n" % (name, symbol, name))
+        elif isinstance(value, (int, str)):
+            defs.append("self.%s = %r\n" % (symbol, value))
     source = py.code.Source(target_)[1:].deindent()
     pyfile = udir.join('src.py')
     source = helpers + '\n'.join(defs) + str(source)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.