move standalone script to become a plugin offering "--genscript",
adjust paths accordingly and add CHANGELOG entry. --HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									1103f2ad62
								
							
						
					
					
						commit
						fa0c7b18bf
					
				|  | @ -1,6 +1,9 @@ | |||
| Changes between 1.X and 1.1.1 | ||||
| ===================================== | ||||
| 
 | ||||
| - new option: --genscript=path will generate a standalone py.test script | ||||
|   which will not need any libraries installed.  thanks to Ralf Schmitt.  | ||||
| 
 | ||||
| - new option: --ignore will prevent specified path from collection.  | ||||
|   Can be specified multiple times.  | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,43 +0,0 @@ | |||
| #! /usr/bin/env python | ||||
| 
 | ||||
| import os | ||||
| import cPickle | ||||
| import zlib | ||||
| import base64 | ||||
| import sys | ||||
| 
 | ||||
| def main(pybasedir, outfile, infile): | ||||
|     os.chdir(str(pybasedir)) | ||||
|     outfile = str(outfile) | ||||
|     infile = str(infile) | ||||
|     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__": | ||||
|     dn = os.path.dirname | ||||
|     pybasedir = dn(dn(os.path.abspath(__file__))) | ||||
|     outfile = os.path.join(dn(__file__), "py.test") | ||||
|     infile = outfile+"-in" | ||||
|     main(pybasedir, outfile, infile) | ||||
|  | @ -8,7 +8,7 @@ from py.impl.test.outcome import Skipped | |||
| 
 | ||||
| default_plugins = ( | ||||
|     "default runner capture terminal mark skipping tmpdir monkeypatch " | ||||
|     "recwarn pdb pastebin unittest helpconfig nose assertion").split() | ||||
|     "recwarn pdb pastebin unittest helpconfig nose assertion genscript").split() | ||||
| 
 | ||||
| def check_old_use(mod, modname): | ||||
|     clsname = modname[len('pytest_'):].capitalize() + "Plugin"  | ||||
|  |  | |||
|  | @ -0,0 +1,63 @@ | |||
| #! /usr/bin/env python | ||||
| 
 | ||||
| import os | ||||
| import zlib | ||||
| import base64 | ||||
| import sys | ||||
| try: | ||||
|     import pickle | ||||
| except Importerror: | ||||
|     import cPickle as pickle | ||||
| 
 | ||||
| def pytest_addoption(parser): | ||||
|     group = parser.getgroup("general") | ||||
|     group.addoption("--genscript", action="store", default=None,  | ||||
|         dest="genscript", metavar="path",  | ||||
|         help="create standalone py.test script at given target path.") | ||||
| 
 | ||||
| def pytest_configure(config): | ||||
|     genscript = config.getvalue("genscript") | ||||
|     if genscript: | ||||
|         import py | ||||
|         mydir = py.path.local(__file__).dirpath() | ||||
|         infile = mydir.join("standalonetemplate.py") | ||||
|         pybasedir = py.path.local(py.__file__).dirpath().dirpath() | ||||
|         main(pybasedir, outfile=genscript, infile=infile) | ||||
|         raise SystemExit(0) | ||||
| 
 | ||||
| def main(pybasedir, outfile, infile): | ||||
|     os.chdir(str(pybasedir)) | ||||
|     outfile = str(outfile) | ||||
|     infile = str(infile) | ||||
|     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 = pickle.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 standalone py.test at %r, have fun!\n" % outfile) | ||||
| 
 | ||||
| if __name__=="__main__": | ||||
|     dn = os.path.dirname | ||||
|     here = os.path.abspath(dn(__file__)) # py/plugin/ | ||||
|     pybasedir = dn(dn(here)) | ||||
|     outfile = os.path.join(os.getcwd(), "py.test-standalone") | ||||
|     infile = os.path.join(here, 'standalonetemplate.py') | ||||
|     main(pybasedir, outfile, infile) | ||||
|  | @ -12,11 +12,11 @@ if sys.version_info >= (3,0): | |||
|     exec("def do_exec(co, loc): exec(co, loc)\n") | ||||
|     import pickle | ||||
|     sources = sources.encode("ascii") # ensure bytes  | ||||
|     sources = pickle.loads(zlib.decompress(base64.decodebytes(sources))) | ||||
| else: | ||||
|     import cPickle as pickle | ||||
|     exec("def do_exec(co, loc): exec co in loc\n") | ||||
| 
 | ||||
| sources = pickle.loads(zlib.decompress(base64.decodestring(sources))) | ||||
|     sources = pickle.loads(zlib.decompress(base64.decodestring(sources))) | ||||
| 
 | ||||
| class DictImporter(object): | ||||
|     sources = sources | ||||
|  | @ -8,7 +8,7 @@ | |||
| import time | ||||
| 
 | ||||
| def pytest_addoption(parser): | ||||
|     group = parser.addgroup("xmlresult", "xmlresult plugin options") | ||||
|     group = parser.getgroup("xmlresult", "xmlresult plugin options") | ||||
|     group.addoption('--xmlresult', action="store", dest="xmlresult", metavar="path", default=None, | ||||
|            help="path for machine-readable xml result log.") | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,9 +1,5 @@ | |||
| import py, os, sys | ||||
| import generate_standalone_pytest | ||||
| import subprocess | ||||
| mydir = py.path.local(__file__).dirpath() | ||||
| pybasedir = mydir.join("..") | ||||
| assert pybasedir.join("py").check() | ||||
| 
 | ||||
| def pytest_funcarg__standalone(request): | ||||
|     return request.cached_setup(scope="module", setup=lambda: Standalone(request)) | ||||
|  | @ -11,10 +7,8 @@ def pytest_funcarg__standalone(request): | |||
| class Standalone: | ||||
|     def __init__(self, request): | ||||
|         self.testdir = request.getfuncargvalue("testdir") | ||||
|         infile = mydir.join("py.test-in") | ||||
|         self.script = self.testdir.tmpdir.join("mypytest") | ||||
|         generate_standalone_pytest.main(pybasedir=pybasedir, | ||||
|             infile=infile, outfile=self.script) | ||||
|         self.testdir.runpytest("--genscript=%s" % self.script) | ||||
| 
 | ||||
|     def run(self, anypython, testdir, *args): | ||||
|         testdir.chdir() | ||||
		Loading…
	
		Reference in New Issue