2009-12-28 06:03:04 +08:00
|
|
|
#! /usr/bin/env python
|
|
|
|
|
2014-10-24 19:04:20 +08:00
|
|
|
# Hi There!
|
|
|
|
# You may be wondering what this giant blob of binary data here is, you might
|
|
|
|
# even be worried that we're up to something nefarious (good for you for being
|
|
|
|
# paranoid!). This is a base64 encoding of a zip file, this zip file contains
|
|
|
|
# a fully functional basic pytest script.
|
|
|
|
#
|
|
|
|
# Pytest is a thing that tests packages, pytest itself is a package that some-
|
|
|
|
# one might want to install, especially if they're looking to run tests inside
|
|
|
|
# some package they want to install. Pytest has a lot of code to collect and
|
|
|
|
# execute tests, and other such sort of "tribal knowledge" that has been en-
|
|
|
|
# coded in its code base. Because of this we basically include a basic copy
|
|
|
|
# of pytest inside this blob. We do this because it let's you as a maintainer
|
|
|
|
# or application developer who wants people who don't deal with python much to
|
|
|
|
# easily run tests without installing the complete pytest package.
|
|
|
|
#
|
|
|
|
# If you're wondering how this is created: you can create it yourself if you
|
|
|
|
# have a complete pytest installation by using this command on the command-
|
|
|
|
# line: ``py.test --genscript=runtests.py``.
|
|
|
|
|
2009-12-28 06:03:04 +08:00
|
|
|
sources = """
|
|
|
|
@SOURCES@"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import base64
|
|
|
|
import zlib
|
|
|
|
|
|
|
|
class DictImporter(object):
|
2010-01-16 01:45:06 +08:00
|
|
|
def __init__(self, sources):
|
|
|
|
self.sources = sources
|
|
|
|
|
2009-12-28 06:03:04 +08:00
|
|
|
def find_module(self, fullname, path=None):
|
2013-07-26 14:59:31 +08:00
|
|
|
if fullname == "argparse" and sys.version_info >= (2,7):
|
|
|
|
# we were generated with <python2.7 (which pulls in argparse)
|
|
|
|
# but we are running now on a stdlib which has it, so use that.
|
|
|
|
return None
|
2009-12-28 06:03:04 +08:00
|
|
|
if fullname in self.sources:
|
|
|
|
return self
|
2010-11-14 06:33:50 +08:00
|
|
|
if fullname + '.__init__' in self.sources:
|
2009-12-28 06:03:04 +08:00
|
|
|
return self
|
|
|
|
return None
|
|
|
|
|
|
|
|
def load_module(self, fullname):
|
|
|
|
# print "load_module:", fullname
|
2009-12-31 00:08:45 +08:00
|
|
|
from types import ModuleType
|
2009-12-28 06:03:04 +08:00
|
|
|
try:
|
|
|
|
s = self.sources[fullname]
|
|
|
|
is_pkg = False
|
|
|
|
except KeyError:
|
2010-11-14 06:33:50 +08:00
|
|
|
s = self.sources[fullname + '.__init__']
|
2009-12-28 06:03:04 +08:00
|
|
|
is_pkg = True
|
2010-07-27 03:15:15 +08:00
|
|
|
|
2009-12-28 06:03:04 +08:00
|
|
|
co = compile(s, fullname, 'exec')
|
2009-12-31 00:08:45 +08:00
|
|
|
module = sys.modules.setdefault(fullname, ModuleType(fullname))
|
2009-12-28 06:03:04 +08:00
|
|
|
module.__file__ = "%s/%s" % (__file__, fullname)
|
|
|
|
module.__loader__ = self
|
|
|
|
if is_pkg:
|
|
|
|
module.__path__ = [fullname]
|
2010-07-27 03:15:15 +08:00
|
|
|
|
2013-10-12 21:39:22 +08:00
|
|
|
do_exec(co, module.__dict__) # noqa
|
2009-12-28 06:03:04 +08:00
|
|
|
return sys.modules[fullname]
|
|
|
|
|
2009-12-31 02:01:46 +08:00
|
|
|
def get_source(self, name):
|
|
|
|
res = self.sources.get(name)
|
|
|
|
if res is None:
|
2010-11-14 06:33:50 +08:00
|
|
|
res = self.sources.get(name + '.__init__')
|
2009-12-31 02:01:46 +08:00
|
|
|
return res
|
|
|
|
|
2009-12-28 06:03:04 +08:00
|
|
|
if __name__ == "__main__":
|
2010-11-14 06:33:50 +08:00
|
|
|
if sys.version_info >= (3, 0):
|
2010-01-16 01:45:06 +08:00
|
|
|
exec("def do_exec(co, loc): exec(co, loc)\n")
|
|
|
|
import pickle
|
2010-07-27 03:15:15 +08:00
|
|
|
sources = sources.encode("ascii") # ensure bytes
|
2010-01-16 01:45:06 +08:00
|
|
|
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)))
|
|
|
|
|
|
|
|
importer = DictImporter(sources)
|
2013-02-13 05:59:29 +08:00
|
|
|
sys.meta_path.insert(0, importer)
|
2010-01-16 01:45:06 +08:00
|
|
|
|
2010-10-16 09:10:14 +08:00
|
|
|
entry = "@ENTRY@"
|
2013-10-12 21:39:22 +08:00
|
|
|
do_exec(entry, locals()) # noqa
|