def check_all(self): "Check that __all__ is present and does not contain invalid entries" if not hasattr(self.module, '__all__'): assert self.modname in NO_ALL return names = {} six.exec_("from %s import *" % self.modname, names) names.pop('__builtins__', None) self.assertEqual(sorted(names), sorted(self.module.__all__))
def main(): import argparse parser = argparse.ArgumentParser() parser.add_argument('--ignore') parser.add_argument('--discover', action='store_true') parser.add_argument('--full', action='store_true') parser.add_argument('--config', default='known_failures.py') parser.add_argument('--failfast', action='store_true') parser.add_argument("--coverage", action="store_true") parser.add_argument("--quiet", action="store_true", default=True) parser.add_argument("--verbose", action="store_false", dest='quiet') parser.add_argument("--debug", action="store_true", default=False) parser.add_argument('tests', nargs='*') options = parser.parse_args() FAILING_TESTS = [] IGNORED_TESTS = [] coverage = False if options.coverage or os.environ.get("GEVENTTEST_COVERAGE"): coverage = True # NOTE: This must be run from the greentest directory os.environ['COVERAGE_PROCESS_START'] = os.path.abspath(".coveragerc") if PYPY: os.environ['COVERAGE_PROCESS_START'] = os.path.abspath(".coveragerc-pypy") os.environ['PYTHONPATH'] = os.path.abspath("coveragesite") + os.pathsep + os.environ.get("PYTHONPATH", "") # We change directory often, use an absolute path to keep all the # coverage files (which will have distinct suffixes because of parallel=true in .coveragerc # in this directory; makes them easier to combine and use with coverage report) os.environ['COVERAGE_FILE'] = os.path.abspath(".") + os.sep + ".coverage" print("Enabling coverage to", os.environ['COVERAGE_FILE']) _setup_environ(debug=options.debug) if options.config: config = {} with open(options.config) as f: config_data = f.read() six.exec_(config_data, config) FAILING_TESTS = config['FAILING_TESTS'] IGNORED_TESTS = config['IGNORED_TESTS'] tests = discover(options.tests, ignore_files=options.ignore, ignored=IGNORED_TESTS, coverage=coverage) if options.discover: for cmd, options in tests: print(util.getname(cmd, env=options.get('env'), setenv=options.get('setenv'))) print('%s tests found.' % len(tests)) else: if PYPY and RESOLVER_ARES: # XXX: Add a way to force these. print("Not running tests on pypy with c-ares; not a supported configuration") return run_many(tests, configured_failing_tests=FAILING_TESTS, failfast=options.failfast, quiet=options.quiet)
def walk_modules(basedir=None, modpath=None, include_so=False, recursive=False): # pylint:disable=too-many-branches if sysinfo.PYPY: include_so = False if basedir is None: basedir = os.path.dirname(gevent.__file__) if modpath is None: modpath = 'gevent.' else: if modpath is None: modpath = '' for fn in sorted(os.listdir(basedir)): path = os.path.join(basedir, fn) if os.path.isdir(path): if not recursive: continue pkg_init = os.path.join(path, '__init__.py') if os.path.exists(pkg_init): yield pkg_init, modpath + fn for p, m in walk_modules(path, modpath + fn + "."): yield p, m continue if fn.endswith('.py'): x = fn[:-3] if x.endswith('_d'): x = x[:-2] if x in [ '__init__', 'core', 'ares', '_util', '_semaphore', 'corecffi', '_corecffi', '_corecffi_build' ]: continue if x in OPTIONAL_MODULES: try: six.exec_("import %s" % x, {}) except ImportError: continue yield path, modpath + x elif include_so and fn.endswith(sysinfo.SHARED_OBJECT_EXTENSION): if '.pypy-' in fn: continue if fn.endswith('_d.so'): yield path, modpath + fn[:-5] else: yield path, modpath + fn[:-3]
def _test(self, modname): for x in PLATFORM_SPECIFIC_SUFFIXES: if modname.endswith(x): return self.modname = modname six.exec_("import %s" % modname, {}) self.module = sys.modules[modname] self.check_all() self.__implements__ = getattr(self.module, '__implements__', None) self.__imports__ = getattr(self.module, '__imports__', []) self.__extensions__ = getattr(self.module, '__extensions__', []) self.stdlib_name = MAPPING.get(modname) self.stdlib_module = None if self.stdlib_name is not None: try: self.stdlib_module = __import__(self.stdlib_name) except ImportError: pass self.check_implements_presence_justified() if self.stdlib_module is None: return # use __all__ as __implements__ if self.__implements__ is None: self.__implements__ = sorted(self.module.__all__) self.set_stdlib_all() self.check_implements_subset_of_stdlib_all() self.check_implements_actually_implements() self.check_imports_actually_imports() self.check_extensions_actually_extend() self.check_completeness()
def main(): import argparse parser = argparse.ArgumentParser() parser.add_argument('--ignore') parser.add_argument('--discover', action='store_true') parser.add_argument('--full', action='store_true') parser.add_argument('--config') parser.add_argument('--failfast', action='store_true') parser.add_argument("--coverage", action="store_true") parser.add_argument("--quiet", action="store_true") parser.add_argument('tests', nargs='*') options = parser.parse_args() FAILING_TESTS = [] IGNORED_TESTS = [] coverage = False if options.coverage or os.environ.get("GEVENTTEST_COVERAGE"): coverage = True # NOTE: This must be run from the greentest directory os.environ['COVERAGE_PROCESS_START'] = os.path.abspath(".coveragerc") if PYPY: os.environ['COVERAGE_PROCESS_START'] = os.path.abspath(".coveragerc-pypy") os.environ['PYTHONPATH'] = os.path.abspath("coveragesite") + os.pathsep + os.environ.get("PYTHONPATH", "") # We change directory often, use an absolute path to keep all the # coverage files (which will have distinct suffixes because of parallel=true in .coveragerc # in this directory; makes them easier to combine and use with coverage report) os.environ['COVERAGE_FILE'] = os.path.abspath(".") + os.sep + ".coverage" print("Enabling coverage to", os.environ['COVERAGE_FILE']) if options.config: config = {} with open(options.config) as f: config_data = f.read() six.exec_(config_data, config) FAILING_TESTS = config['FAILING_TESTS'] IGNORED_TESTS = config['IGNORED_TESTS'] if 'PYTHONWARNINGS' not in os.environ and not sys.warnoptions: # Enable default warnings such as ResourceWarning. # On Python 3[.6], the system site.py module has # "open(fullname, 'rU')" which produces the warning that # 'U' is deprecated, so ignore warnings from site.py # importlib/_bootstrap.py likes to spit out "ImportWarning: # can't resolve package from __spec__ or __package__, falling # back on __name__ and __path__". I have no idea what that means, but it seems harmless # and is annoying. os.environ['PYTHONWARNINGS'] = 'default,ignore:::site:,ignore:::importlib._bootstrap:,ignore:::importlib._bootstrap_external:' if 'PYTHONFAULTHANDLER' not in os.environ: os.environ['PYTHONFAULTHANDLER'] = 'true' if 'GEVENT_DEBUG' not in os.environ: os.environ['GEVENT_DEBUG'] = 'debug' tests = discover(options.tests, ignore_files=options.ignore, ignored=IGNORED_TESTS, coverage=coverage) if options.discover: for cmd, options in tests: print(util.getname(cmd, env=options.get('env'), setenv=options.get('setenv'))) print('%s tests found.' % len(tests)) else: run_many(tests, configured_failing_tests=FAILING_TESTS, failfast=options.failfast, quiet=options.quiet)
def test(self): #sys.stderr.write('%s %s\n' % (module, path)) with open(path, 'rb') as f: src = f.read() six.exec_(src, {'__file__': path})