[py-svn] py-trunk commit 9e18a1a2a67a: a first go at testing schmir's generate_standalone_pytest script and
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Wed Dec 30 17:09:10 CET 2009
# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User holger krekel <holger at merlinux.eu>
# Date 1262189325 -3600
# Node ID 9e18a1a2a67a215f5f9ffef2679be08c7061d7c2
# Parent 06dfbfa6fb8df272db923d742dc06e5ab6a97474
a first go at testing schmir's generate_standalone_pytest script and
making it work on python2.4-3.1 + jython.
--- /dev/null
+++ b/bin-for-dist/test_generate_standalone.py
@@ -0,0 +1,18 @@
+import py, os
+import generate_standalone_pytest
+import subprocess
+mydir = py.path.local(__file__).dirpath()
+
+def test_gen(testdir, anypython):
+ testdir.chdir()
+ infile = mydir.join("py.test-in")
+ outfile = testdir.tmpdir.join("mypytest")
+ generate_standalone_pytest.main(pydir=os.path.dirname(py.__file__),
+ infile=infile, outfile=outfile)
+ result = testdir._run(anypython, outfile, '-h')
+ assert result.ret == 0
+ result = testdir._run(anypython, outfile, '--version')
+ assert result.ret == 0
+ result.stderr.fnmatch_lines([
+ "*imported from*mypytest"
+ ])
--- a/conftest.py
+++ b/conftest.py
@@ -63,3 +63,47 @@ def pytest_generate_tests(metafunc):
for name, l in multi.kwargs.items():
for val in l:
metafunc.addcall(funcargs={name: val})
+
+# XXX copied from execnet's conftest.py - needs to be merged
+winpymap = {
+ 'python2.7': r'C:\Python27\python.exe',
+ 'python2.6': r'C:\Python26\python.exe',
+ 'python2.5': r'C:\Python25\python.exe',
+ 'python2.4': r'C:\Python24\python.exe',
+ 'python3.1': r'C:\Python31\python.exe',
+}
+
+def pytest_generate_tests(metafunc):
+ if 'anypython' in metafunc.funcargnames:
+ for name in ('python2.4', 'python2.5', 'python2.6',
+ 'python2.7', 'python3.1', 'pypy-c', 'jython'):
+ metafunc.addcall(id=name, param=name)
+
+def getexecutable(name, cache={}):
+ try:
+ return cache[name]
+ except KeyError:
+ executable = py.path.local.sysfind(name)
+ if executable:
+ if name == "jython":
+ import subprocess
+ popen = subprocess.Popen([str(executable), "--version"],
+ universal_newlines=True, stderr=subprocess.PIPE)
+ out, err = popen.communicate()
+ if not err or "2.5" not in err:
+ executable = None
+ cache[name] = executable
+ return executable
+
+def pytest_funcarg__anypython(request):
+ name = request.param
+ executable = getexecutable(name)
+ if executable is None:
+ if sys.platform == "win32":
+ executable = winpymap.get(name, None)
+ if executable:
+ executable = py.path.local(executable)
+ if executable.check():
+ return executable
+ py.test.skip("no %s found" % (name,))
+ return executable
--- a/bin-for-dist/generate_standalone_pytest.py
+++ b/bin-for-dist/generate_standalone_pytest.py
@@ -6,13 +6,10 @@ import zlib
import base64
import sys
-def main():
- here = os.path.dirname(os.path.abspath(__file__))
- outfile = os.path.join(here, "py.test")
- infile = outfile+"-in"
-
- os.chdir(os.path.dirname(here))
-
+def main(pydir, outfile, infile):
+ os.chdir(os.path.dirname(str(pydir)))
+ outfile = str(outfile)
+ infile = str(infile)
files = []
for dirpath, dirnames, filenames in os.walk("py"):
for f in filenames:
@@ -39,4 +36,8 @@ def main():
sys.stdout.write("generated %s\n" % outfile)
if __name__=="__main__":
- main()
+ dn = os.path.dirname
+ pydir = os.path.join(dn(dn(os.path.abspath(__file__))), 'py')
+ outfile = os.path.join(dn(__file__), "py.test")
+ infile = outfile+"-in"
+ main(pydir, outfile, infile)
--- a/bin-for-dist/py.test-in
+++ b/bin-for-dist/py.test-in
@@ -4,12 +4,19 @@ sources = """
@SOURCES@"""
import sys
-import cPickle
import base64
import zlib
import imp
-sources = cPickle.loads(zlib.decompress(base64.decodestring(sources)))
+if sys.version_info >= (3,0):
+ exec("def do_exec(co, loc): exec(co, loc)\n")
+ import pickle
+ sources = sources.encode("ascii") # ensure bytes
+else:
+ import cPickle as pickle
+ exec("def do_exec(co, loc): exec co in loc\n")
+
+sources = pickle.loads(zlib.decompress(base64.decodestring(sources)))
class DictImporter(object):
sources = sources
@@ -22,8 +29,7 @@ class DictImporter(object):
def load_module(self, fullname):
# print "load_module:", fullname
- import new
-
+ from types import ModuleType
try:
s = self.sources[fullname]
is_pkg = False
@@ -32,13 +38,13 @@ class DictImporter(object):
is_pkg = True
co = compile(s, fullname, 'exec')
- module = sys.modules.setdefault(fullname, new.module(fullname))
+ module = sys.modules.setdefault(fullname, ModuleType(fullname))
module.__file__ = "%s/%s" % (__file__, fullname)
module.__loader__ = self
if is_pkg:
module.__path__ = [fullname]
- exec co in module.__dict__
+ do_exec(co, module.__dict__)
return sys.modules[fullname]
importer = DictImporter()
More information about the pytest-commit
mailing list