Example #1
0
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 = []
    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")
        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']

    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
        os.environ['PYTHONWARNINGS'] = 'default,ignore:::site:'
    if 'PYTHONFAULTHANDLER' not in os.environ:
        os.environ['PYTHONFAULTHANDLER'] = 'true'

    if 'GEVENT_DEBUG' not in os.environ:
        os.environ['GEVENT_DEBUG'] = 'error'

    tests = discover(options.tests, options.ignore, 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,
                 expected=FAILING_TESTS,
                 failfast=options.failfast,
                 quiet=options.quiet)
Example #2
0
 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__))
Example #3
0
def walk_modules(basedir=None,
                 modpath=None,
                 include_so=False,
                 recursive=False):
    if 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('.so'):
            if '.pypy-' in fn:
                continue
            if fn.endswith('_d.so'):
                yield path, modpath + fn[:-5]
            else:
                yield path, modpath + fn[:-3]
Example #4
0
def main():
    # FIXME: transition to argparse
    import optparse  # pylint:disable=deprecated-module
    parser = optparse.OptionParser()
    parser.add_option('--ignore')
    parser.add_option('--discover', action='store_true')
    parser.add_option('--full', action='store_true')
    parser.add_option('--config')
    parser.add_option('--failfast', action='store_true')
    parser.add_option("--coverage", action="store_true")
    parser.add_option("--quiet", action="store_true")
    options, args = parser.parse_args()
    FAILING_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")
        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']
    tests = discover(args, options.ignore, 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,
                 expected=FAILING_TESTS,
                 failfast=options.failfast,
                 quiet=options.quiet)
Example #5
0
def walk_modules(basedir=None, modpath=None, include_so=False, recursive=False):
    if 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('.so'):
            if '.pypy-' in fn:
                continue
            if fn.endswith('_d.so'):
                yield path, modpath + fn[:-5]
            else:
                yield path, modpath + fn[:-3]
Example #6
0
    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()
Example #7
0
def main():
    # FIXME: transition to argparse
    import optparse # pylint:disable=deprecated-module
    parser = optparse.OptionParser()
    parser.add_option('--ignore')
    parser.add_option('--discover', action='store_true')
    parser.add_option('--full', action='store_true')
    parser.add_option('--config')
    parser.add_option('--failfast', action='store_true')
    parser.add_option("--coverage", action="store_true")
    parser.add_option("--quiet", action="store_true")
    options, args = parser.parse_args()
    FAILING_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")
        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']
    tests = discover(args, options.ignore, 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, expected=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})
Example #9
0
 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})