[py-svn] py-trunk commit f0c844a51152: add script to generate standalone py.test
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Sun Dec 27 23:05:43 CET 2009
# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User Ralf Schmitt <ralf at systemexit.de>
# Date 1261951384 -3600
# Node ID f0c844a51152aedfe4b446520f03d3d25893c162
# Parent 78da77459ff7ac56f1417f3eb27dba24db0381df
add script to generate standalone py.test
--- a/py/impl/test/conftesthandle.py
+++ b/py/impl/test/conftesthandle.py
@@ -41,7 +41,12 @@ class Conftest(object):
if path is None:
raise ValueError("missing default conftest.")
dp = path.dirpath()
- if dp == path:
+ if dp == path:
+ if not defaultconftestpath.check(): # zip file, single-file py.test?
+ import defaultconftest
+ if self._onimport:
+ self._onimport(defaultconftest)
+ return [defaultconftest]
return [self.importconftest(defaultconftestpath)]
clist = self.getconftestmodules(dp)
conftestpath = path.join("conftest.py")
--- /dev/null
+++ b/bin-for-dist/generate_standalone_pytest.py
@@ -0,0 +1,42 @@
+#! /usr/bin/env python
+
+import os
+import cPickle
+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))
+
+ files = []
+ for dirpath, dirnames, filenames in os.walk("py"):
+ for f in filenames:
+ if not f.endswith(".py"):
+ continue
+
+ fn = os.path.join(dirpath, f)
+ files.append(fn)
+
+ name2src = {}
+ for f in files:
+ k = f.replace("/", ".")[:-3]
+ name2src[k] = open(f, "rb").read()
+
+ data = cPickle.dumps(name2src, 2)
+ data = zlib.compress(data, 9)
+ data = base64.encodestring(data)
+
+ exe = open(infile, "rb").read()
+ exe = exe.replace("@SOURCES@", data)
+
+ open(outfile, "wb").write(exe)
+ os.chmod(outfile, 493) # 0755
+ sys.stdout.write("generated %s\n" % outfile)
+
+if __name__=="__main__":
+ main()
--- /dev/null
+++ b/bin-for-dist/py.test-in
@@ -0,0 +1,50 @@
+#! /usr/bin/env python
+
+sources = """
+ at SOURCES@"""
+
+import sys
+import cPickle
+import base64
+import zlib
+import imp
+
+sources = cPickle.loads(zlib.decompress(base64.decodestring(sources)))
+
+class DictImporter(object):
+ sources = sources
+ def find_module(self, fullname, path=None):
+ if fullname in self.sources:
+ return self
+ if fullname+'.__init__' in self.sources:
+ return self
+ return None
+
+ def load_module(self, fullname):
+ # print "load_module:", fullname
+ import new
+
+ try:
+ s = self.sources[fullname]
+ is_pkg = False
+ except KeyError:
+ s = self.sources[fullname+'.__init__']
+ is_pkg = True
+
+ co = compile(s, fullname, 'exec')
+ module = sys.modules.setdefault(fullname, new.module(fullname))
+ module.__file__ = "%s/%s" % (__file__, fullname)
+ module.__loader__ = self
+ if is_pkg:
+ module.__path__ = [fullname]
+
+ exec co in module.__dict__
+ return sys.modules[fullname]
+
+importer = DictImporter()
+
+sys.meta_path.append(importer)
+
+if __name__ == "__main__":
+ import py
+ py.cmdline.pytest()
More information about the pytest-commit
mailing list