Example #1
0
    def test_basic_test(self):
        pkgname='fakepackage4'
        modname='fakemodule4'
        modcontents='\n\
def foofunc():\n\
    x=1\n\
    y=x\n\
'
        testcontents='\n\
from twisted.trial import unittest\n\
from %s import %s\n\
class T(unittest.TestCase):\n\
    def test_thing(self):\n\
        %s.foofunc()\n\
' % (pkgname, modname, modname)

        mockstdout = Mock()
        realstdout=sys.stdout
        sys.stdout = mockstdout
        mockstderr = Mock()
        realstderr=sys.stderr
        sys.stderr = mockstderr
        something = None
        try:
            fileutil.make_dirs(pkgname)
            fileutil.write_file(os.path.join(pkgname, '__init__.py'), '')
            fileutil.write_file(os.path.join(pkgname, modname+'.py'), modcontents)
            fileutil.make_dirs(os.path.join(pkgname, 'test'))
            fileutil.write_file(os.path.join(pkgname, 'test', '__init__.py'), '')
            fileutil.write_file(os.path.join(pkgname, 'test', 'test_'+modname+'.py'), testcontents)
            sys.path.append(os.getcwd())
            trialcoverage.init_paths()
            trialcoverage.start_coverage()

            config = trial.Options()
            config.parseOptions(['--reporter', 'bwverbose-coverage', '%s.test' % pkgname])
            trial._initialDebugSetup(config)
            trialRunner = trial._makeRunner(config)
            suite = trial._getSuite(config)
            something = trialRunner.run(suite)

        finally:
            sys.stdout = realstdout
            sys.stderr = realstderr
            if sys.modules.has_key(pkgname):
                del sys.modules[pkgname]
            fileutil.rm_dir(pkgname)
Example #2
0
    def run_tests(self):
        # We do the import from Twisted inside the function instead of the top
        # of the file because since Twisted is a setup_requires, we can't
        # assume that Twisted will be installed on the user's system prior, so
        # if we don't do the import here, then importing from this plugin will
        # fail.
        from twisted.scripts import trial

        if not self.testmodule:
            self.testmodule = "bridgedb.test"

        # Handle parsing the trial options passed through the setuptools
        # trial command.
        cmd_options = []
        for opt in self.boolean_options:
            if getattr(self, opt.replace('-', '_'), None):
                cmd_options.append('--%s' % opt)

        for opt in ('debugger', 'jobs', 'random', 'reactor', 'reporter',
                    'testmodule', 'tbformat', 'without-module'):
            value = getattr(self, opt.replace('-', '_'), None)
            if value is not None:
                cmd_options.extend(['--%s' % opt, value])

        config = trial.Options()
        config.parseOptions(cmd_options)
        config['tests'] = [
            self.testmodule,
        ]

        trial._initialDebugSetup(config)
        trialRunner = trial._makeRunner(config)
        suite = trial._getSuite(config)

        # run the tests
        if self.until_failure:
            test_result = trialRunner.runUntilFailure(suite)
        else:
            test_result = trialRunner.run(suite)

        if test_result.wasSuccessful():
            return 0  # success
        return 1  # failure
Example #3
0
    def run_tests(self):
        # We do the import from Twisted inside the function instead of the top
        # of the file because since Twisted is a setup_requires, we can't
        # assume that Twisted will be installed on the user's system prior, so
        # if we don't do the import here, then importing from this plugin will
        # fail.
        from twisted.scripts import trial

        if not self.testmodule:
            self.testmodule = "bridgedb.test"

        # Handle parsing the trial options passed through the setuptools
        # trial command.
        cmd_options = []
        for opt in self.boolean_options:
            if getattr(self, opt.replace('-', '_'), None):
                cmd_options.append('--%s' % opt)

        for opt in ('debugger', 'jobs', 'random', 'reactor', 'reporter',
                    'testmodule', 'tbformat', 'without-module'):
            value = getattr(self, opt.replace('-', '_'), None)
            if value is not None:
                cmd_options.extend(['--%s' % opt, value])

        config = trial.Options()
        config.parseOptions(cmd_options)
        config['tests'] = [self.testmodule,]

        trial._initialDebugSetup(config)
        trialRunner = trial._makeRunner(config)
        suite = trial._getSuite(config)

        # run the tests
        if self.until_failure:
            test_result = trialRunner.runUntilFailure(suite)
        else:
            test_result = trialRunner.run(suite)

        if test_result.wasSuccessful():
            return 0  # success
        return 1      # failure
Example #4
0
    def run_tests(self):
        # We do the import from Twisted inside the function instead of the top
        # of the file because since Twisted is a setup_requires, we can't
        # assume that Twisted will be installed on the user's system prior
        # to using Tahoe, so if we don't do the import here, then importing
        # from this plugin will fail.
        from twisted.scripts import trial

        # Handle parsing the trial options passed through the setuptools
        # trial command.
        cmd_options = []
        if self.reactor is not None:
            cmd_options.extend(['--reactor', self.reactor])
        else:
            # Cygwin requires the poll reactor to work at all.  Linux requires the poll reactor
            # to avoid twisted bug #3218.  In general, the poll reactor is better than the
            # select reactor, but it is not available on all platforms.  According to exarkun on
            # IRC, it is available but buggy on some versions of Mac OS X, so just because you
            # can install it doesn't mean we want to use it on every platform.
            # Unfortunately this leads to this error with some combinations of tools:
            # twisted.python.usage.UsageError: The specified reactor cannot be used, failed with error: reactor already installed.
            if sys.platform in ("cygwin"):
                cmd_options.extend(['--reactor', 'poll'])
        if self.reporter is not None:
            cmd_options.extend(['--reporter', self.reporter])
        if self.rterrors is not None:
            cmd_options.append('--rterrors')
        if self.debug_stacktraces is not None:
            cmd_options.append('--debug-stacktraces')
        config = trial.Options()
        config.parseOptions(cmd_options)

        args = self.test_args
        if type(args) == str:
            args = [
                args,
            ]

        config['tests'] = args

        if self.coverage:
            config.opt_coverage()

        trial._initialDebugSetup(config)
        trialRunner = trial._makeRunner(config)
        suite = trial._getSuite(config)

        # run the tests
        if self.until_failure:
            test_result = trialRunner.runUntilFailure(suite)
        else:
            test_result = trialRunner.run(suite)

        # write coverage data
        if config.tracer:
            sys.settrace(None)
            results = config.tracer.results()
            results.write_results(show_missing=1,
                                  summary=False,
                                  coverdir=config.coverdir)

        if test_result.wasSuccessful():
            sys.exit(0)  # success
        else:
            sys.exit(1)  # failure
Example #5
0
            r = datastore.Redis.instance()
            r.flushdb()
    else:
        from nova.tests.real_flags import *

    if len(argv) == 1 and len(config['tests']) == 0:
        # If no tests were specified run the ones imported in this file
        # NOTE(termie): "tests" is not a flag, just some Trial related stuff
        config['tests'].update(['__main__'])
    elif len(config['tests']):
        # If we specified tests check first whether they are in __main__
        for arg in config['tests']:
            key = arg.split('.')[0]
            if hasattr(__main__, key):
                config['tests'].remove(arg)
                config['tests'].add('__main__.%s' % arg)

    trial_script._initialDebugSetup(config)
    trialRunner = trial_script._makeRunner(config)
    suite = trial_script._getSuite(config)
    if config['until-failure']:
        test_result = trialRunner.runUntilFailure(suite)
    else:
        test_result = trialRunner.run(suite)
    if config.tracer:
        sys.settrace(None)
        results = config.tracer.results()
        results.write_results(show_missing=1, summary=False,
                              coverdir=config.coverdir)
    sys.exit(not test_result.wasSuccessful())
    def run_tests(self):
        global all_modules
        all_modules = self.distribution.get_command_obj(
            'build_py').find_all_modules()

        # We do the import from Twisted inside the function instead of the top
        # of the file because since Twisted is a setup_requires, we can't
        # assume that Twisted will be installed on the user's system prior
        # to using Tahoe, so if we don't do the import here, then importing
        # from this plugin will fail.
        from twisted.scripts import trial

        # Handle parsing the trial options passed through the setuptools
        # trial command.
        cmd_options = []
        if self.reactor is not None:
            cmd_options.extend(['--reactor', self.reactor])
        else:
            # Cygwin requires the poll reactor to work at all.  Linux
            # requires the poll reactor  to avoid twisted bug #3218.
            # In general, the poll reactor is better than the select reactor,
            # but it is not available on all platforms.  According to
            # exarkun on IRC, it is available but buggy on some versions of
            # Mac OS X, so just because you can install it doesn't mean we
            # want to use it on every platform.
            # Unfortunately this leads to this error with some
            # combinations of tools:
            # twisted.python.usage.UsageError: The specified reactor cannot be
            # used, failed with error: reactor already installed.
            if sys.platform in ("cygwin"):
                cmd_options.extend(['--reactor', 'poll'])
        if self.reporter is not None:
            cmd_options.extend(['--reporter', self.reporter])
        if self.rterrors is not None:
            cmd_options.append('--rterrors')
        if self.debug_stacktraces is not None:
            cmd_options.append('--debug-stacktraces')
        config = trial.Options()
        config.parseOptions(cmd_options)

        args = self.test_args
        if type(args) == str:
            args = [args, ]

        config['tests'] = args

        if self.coverage:
            config.opt_coverage()

        trial._initialDebugSetup(config)
        trialRunner = trial._makeRunner(config)
        suite = trial._getSuite(config)

        # run the tests
        if self.until_failure:
            test_result = trialRunner.runUntilFailure(suite)
        else:
            test_result = trialRunner.run(suite)

        # write coverage data
        if config.tracer:
            sys.settrace(None)
            results = config.tracer.results()
            results.write_results(show_missing=1, summary=False,
                                  coverdir=config.coverdir)

        if test_result.wasSuccessful():
            sys.exit(0)  # success
        else:
            sys.exit(1)  # failure
Example #7
0
class CustomSuite(unittest.TestSuite):
    def __init__(self, tests=()):
        stripped = []
        for test in tests:
            if isinstance(test, CustomSuite):
                stripped.append(test)
            elif any(member[0].startswith('test_')
                     for member in inspect.getmembers(test)):
                stripped.append(test)
        super(CustomSuite, self).__init__(tests=stripped)


if __name__ == "__main__":
    # We have to regen the plugins cache to be able to install
    # alternative reactors. Regen utility should be run in a separate
    # interpreter because reactors cannot be installed twice or unloaded.
    subprocess.call(["python", "regen_plugins_cache.py"])
    config = Options()
    config.parseOptions()
    config['tbformat'] = 'verbose'
    config['exitfirst'] = True

    _initialDebugSetup(config)
    trialRunner = _makeRunner(config)

    test_loader = TestLoader()
    test_loader.suiteClass = CustomSuite
    test_suite = test_loader.discover(abspath(join('.', 'ipv8', 'test')),
                                      top_level_dir=abspath('.'))
    test_result = trialRunner.run(test_suite)
Example #8
0

def main():
    always_succeed = '--always-succeed' in sys.argv
    if always_succeed:
        sys.argv.remove('--always-succeed')

    # Copypasta from twisted.scripts.trial.run, to tweak the return values
    if len(sys.argv) == 1:
        sys.argv.append("--help")
    config = trial.Options()
    try:
        config.parseOptions()
    except usage.error, ue:
        raise SystemExit, "%s: %s" % (sys.argv[0], ue)
    trial._initialDebugSetup(config)
    trialRunner = trial._makeRunner(config)
    suite = trial._getSuite(config)
    if config['until-failure']:
        test_result = trialRunner.runUntilFailure(suite)
    else:
        test_result = trialRunner.run(suite)
    if config.tracer:
        sys.settrace(None)
        results = config.tracer.results()
        results.write_results(show_missing=1, summary=False,
                              coverdir=config.coverdir)
    # Copypasta ends here
    if always_succeed or test_result.wasSuccessful():
        return 0
    else: