test_ok2/bin-for-dist/py.test-in

57 lines
1.4 KiB
Python
Executable File

#! /usr/bin/env python
sources = """
@SOURCES@"""
import sys
import base64
import zlib
import imp
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
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
from types import ModuleType
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, ModuleType(fullname))
module.__file__ = "%s/%s" % (__file__, fullname)
module.__loader__ = self
if is_pkg:
module.__path__ = [fullname]
do_exec(co, module.__dict__)
return sys.modules[fullname]
importer = DictImporter()
sys.meta_path.append(importer)
if __name__ == "__main__":
import py
py.cmdline.pytest()