Debian Codegraph @

_pytest/standalonetemplate.py

raw symbols SCIP
1 #! /usr/bin/env python
2
3 # Hi There!
4 # You may be wondering what this giant blob of binary data here is, you might
5 # even be worried that we're up to something nefarious (good for you for being
6 # paranoid!). This is a base64 encoding of a zip file, this zip file contains
7 # a fully functional basic pytest script.
8 #
9 # Pytest is a thing that tests packages, pytest itself is a package that some-
10 # one might want to install, especially if they're looking to run tests inside
11 # some package they want to install. Pytest has a lot of code to collect and
12 # execute tests, and other such sort of "tribal knowledge" that has been en-
13 # coded in its code base. Because of this we basically include a basic copy
14 # of pytest inside this blob. We do this because it let's you as a maintainer
15 # or application developer who wants people who don't deal with python much to
16 # easily run tests without installing the complete pytest package.
17 #
18 # If you're wondering how this is created: you can create it yourself if you
19 # have a complete pytest installation by using this command on the command-
20 # line: ``py.test --genscript=runtests.py``.
21
22 sources = """
23 @SOURCES@"""
24
25 import sys
26 import base64
27 import zlib
28
29 class DictImporter(object):
30 def __init__(self, sources):
31 self.sources = sources
32
33 def find_module(self, fullname, path=None):
34 if fullname == "argparse" and sys.version_info >= (2,7):
35 # we were generated with <python2.7 (which pulls in argparse)
36 # but we are running now on a stdlib which has it, so use that.
37 return None
38 if fullname in self.sources:
39 return self
40 if fullname + '.__init__' in self.sources:
41 return self
42 return None
43
44 def load_module(self, fullname):
45 # print "load_module:", fullname
46 from types import ModuleType
47 try:
48 s = self.sources[fullname]
49 is_pkg = False
50 except KeyError:
51 s = self.sources[fullname + '.__init__']
52 is_pkg = True
53
54 co = compile(s, fullname, 'exec')
55 module = sys.modules.setdefault(fullname, ModuleType(fullname))
56 module.__file__ = "%s/%s" % (__file__, fullname)
57 module.__loader__ = self
58 if is_pkg:
59 module.__path__ = [fullname]
60
61 do_exec(co, module.__dict__) # noqa
62 return sys.modules[fullname]
63
64 def get_source(self, name):
65 res = self.sources.get(name)
66 if res is None:
67 res = self.sources.get(name + '.__init__')
68 return res
69
70 if __name__ == "__main__":
71 try:
72 import pkg_resources # noqa
73 except ImportError:
74 sys.stderr.write("ERROR: setuptools not installed\n")
75 sys.exit(2)
76 if sys.version_info >= (3, 0):
77 exec("def do_exec(co, loc): exec(co, loc)\n")
78 import pickle
79 sources = sources.encode("ascii") # ensure bytes
80 sources = pickle.loads(zlib.decompress(base64.decodebytes(sources)))
81 else:
82 import cPickle as pickle
83 exec("def do_exec(co, loc): exec co in loc\n")
84 sources = pickle.loads(zlib.decompress(base64.decodestring(sources)))
85
86 importer = DictImporter(sources)
87 sys.meta_path.insert(0, importer)
88 entry = "@ENTRY@"
89 do_exec(entry, locals()) # noqa