def get_coverage_for_function(function, startfile, cover_mech=None, fresh_coverage=True): """ cover_mech = 'coverage'|'figleaf'|None >>> get_coverage_for_function('add_argument','../../pylibs/argparse/argparse.py', cover_mech='coverage' ) """ # get tests for function tf = TestFinder(function, startfile) tests = tf.candidate_files(walk_callback) # run tests with coverage # here's how to run specific tests: # PYTHONPATH=/home/matt/work/pylibs/argparse/ nosetests -w /home/matt/work/pylibs/argparse -v path/to/testfile.py:TestClass.test_method path/other.py:TestClass.test_method nose_test_cmds = [] for filename, classname, methodname, line_num in tests: nose_test_cmds.append( get_nose_cmd(filename, classname, methodname, line_num)) nose_argv = ['-v'] + nose_test_cmds + ['-w', os.path.dirname(startfile)] if cover_mech == 'coverage': # .coverage will be in the -w os.path.dirname(startfile) directory nose_argv.append('--with-coverage') if fresh_coverage: nose_argv.append('--cover-erase') # probably should deal with "--cover-package" elif cover_mech == 'figleaf': pass print "RUNNING", " ".join(nose_argv) core.run(argv=nose_argv)
def get_coverage_for_function(function, startfile, cover_mech=None, fresh_coverage=True): """ cover_mech = 'coverage'|'figleaf'|None >>> get_coverage_for_function('add_argument','../../pylibs/argparse/argparse.py', cover_mech='coverage' ) """ # get tests for function tf = TestFinder(function, startfile) tests = tf.candidate_files(walk_callback) # run tests with coverage # here's how to run specific tests: # PYTHONPATH=/home/matt/work/pylibs/argparse/ nosetests -w /home/matt/work/pylibs/argparse -v path/to/testfile.py:TestClass.test_method path/other.py:TestClass.test_method nose_test_cmds = [] for filename, classname, methodname, line_num in tests: nose_test_cmds.append(get_nose_cmd(filename, classname, methodname, line_num)) nose_argv = ['-v'] + nose_test_cmds + ['-w', os.path.dirname(startfile)] if cover_mech == 'coverage': # .coverage will be in the -w os.path.dirname(startfile) directory nose_argv.append('--with-coverage') if fresh_coverage: nose_argv.append('--cover-erase') # probably should deal with "--cover-package" elif cover_mech == 'figleaf': pass print "RUNNING", " ".join(nose_argv) core.run(argv=nose_argv)
def test_run(self): with Stub() as selector: selector.wantFile(any()) >> False with Stub() as run: from nose.core import run run(argv=any(), addplugins=any()) >> True runner = MutationRunner(mutations_path='/mutations/path', test_selector=selector) runner.run(None)
def main(): if os.path.exists('xunit_results'): shutil.rmtree('xunit_results') os.mkdir('xunit_results') numpy.test('full', extra_argv='--with-xunit --xunit-file=xunit_results/numpy_tests.xml'.split()) run(defaultTest='jasmin_scivm/tests', argv='dummy --with-xunit --xunit-file=xunit_results/jap_tests.xml'.split(), exit=False) run(defaultTest='cdat_lite', argv='dummy --with-xunit --xunit-file=xunit_results/cdat_tests.xml'.split(), exit=False)
def run_test(): try: loader = TestLoader() run(argv=[ "--nocapture", "--nologcapture", "--where=/root/tests", "--with-coverage", "--cover-erase", "--cover-package=/root/src/train", "--cover-xml", "--cover-xml-file=/root/tests/results/coverage.xml", "--with-xunit", "--xunit-file=/root/tests/results/nosetests.xml" ], testLoader=loader) except (KeyboardInterrupt): sys.exit(0)
def run(): # This is a fix to allow the --hide-elapsed flag while accepting # arbitrary nosetest flags as well argv = [x for x in sys.argv if x != '--hide-elapsed'] hide_elapsed = argv != sys.argv logging.setup() # If any argument looks like a test name but doesn't have "nova.tests" in # front of it, automatically add that so we don't have to type as much for i, arg in enumerate(argv): if arg.startswith('test_'): argv[i] = 'nova.tests.%s' % arg testdir = os.path.abspath(os.path.join("nova", "tests")) c = config.Config(stream=sys.stdout, env=os.environ, verbosity=3, workingDir=testdir, plugins=core.DefaultPluginManager()) runner = NovaTestRunner(stream=c.stream, verbosity=c.verbosity, config=c, show_elapsed=not hide_elapsed) sys.exit(not core.run(config=c, testRunner=runner, argv=argv))
def run(): logging.setup() # If any argument looks like a test name but doesn't have "nova.tests" in # front of it, automatically add that so we don't have to type as much show_elapsed = True argv = [] for x in sys.argv: if x.startswith('test_'): argv.append('nova.tests.%s' % x) elif x.startswith('--hide-elapsed'): show_elapsed = False else: argv.append(x) testdir = os.path.abspath(os.path.join("nova", "tests")) c = config.Config(stream=sys.stdout, env=os.environ, verbosity=3, workingDir=testdir, plugins=core.DefaultPluginManager()) runner = NovaTestRunner(stream=c.stream, verbosity=c.verbosity, config=c, show_elapsed=show_elapsed) sys.exit(not core.run(config=c, testRunner=runner, argv=argv))
def run_nose(self, apps, config_path, paths, project_name): from nose.core import run from nose.config import Config argv = ["-d", "-s", "--verbose"] use_coverage = True try: import coverage argv.append("--with-coverage") argv.append("--cover-erase") #argv.append("--cover-package=%s" % project_name) argv.append("--cover-inclusive") except ImportError: pass if exists(config_path): argv.append("--config=%s" % config_path) for path in paths: argv.append(path) if use_coverage: for app in apps: argv.append("--cover-package=%s" % app) result = run(argv=argv) if not result: sys.exit(1)
def run_tests(): # Consider the directory... directory = '.' if FLAGS.directory is not None: directory = FLAGS.directory # Set up the arguments... args = [sys.argv[0], '-v', '--exe', directory] # Is this a dry run? if FLAGS.dry_run: args.insert(-2, '--collect-only') else: # Are we in debug mode? if FLAGS.debug: args.insert(-2, '--nocapture') # Process skip... if FLAGS.no_skip: args.insert(-2, '--no-skip') elif FLAGS.skip: args.insert(-2, '--attr=%s' % FLAGS.skip) # Run the integration tests return core.run(argv=args, addplugins=[Timed(), DepFail(), DependsPlugin()])
def run(): # This is a fix to allow the --hide-elapsed flag while accepting # arbitrary nosetest flags as well argv = [x for x in sys.argv if x != '--hide-elapsed'] hide_elapsed = argv != sys.argv logging.setup("cinder") # If any argument looks like a test name but doesn't have "cinder.tests" in # front of it, automatically add that so we don't have to type as much for i, arg in enumerate(argv): if arg.startswith('test_'): argv[i] = 'cinder.tests.%s' % arg testdir = os.path.abspath(os.path.join("cinder", "tests")) c = config.Config(stream=sys.stdout, env=os.environ, verbosity=3, workingDir=testdir, plugins=core.DefaultPluginManager()) runner = CinderTestRunner(stream=c.stream, verbosity=c.verbosity, config=c, show_elapsed=not hide_elapsed) sys.exit(not core.run(config=c, testRunner=runner, argv=argv))
def main(): description = ("Runs unit and/or integration tests. " "Arguments will be passed on to nosetests. " "See nosetests --help for more information.") parser = argparse.ArgumentParser(description=description) parser.add_argument('-t', '--service-tests', action="append", default=[], help="Run tests for a given service. This will " "run any test tagged with the specified value, " "e.g -t clusters -t instances") known_args, remaining_args = parser.parse_known_args() attribute_args = [] for service_attribute in known_args.service_tests: attribute_args.extend(['-a', '!notdefault,' + service_attribute]) if not attribute_args: # If the user did not specify any filtering criteria, we at least # will filter out any test tagged 'notdefault'. attribute_args = ['-a', '!notdefault'] all_args = [__file__] + attribute_args + remaining_args print "nose command:", ' '.join(all_args) if run(argv=all_args): # run will return True is all the tests pass. We want # this to equal a 0 rc return 0 else: return 1
def main(): description = ("Runs boto unit and/or integration tests. " "Arguments will be passed on to nosetests. " "See nosetests --help for more information.") parser = argparse.ArgumentParser(description=description) parser.add_argument('-t', '--service-tests', action="append", default=[], help="Run tests for a given service. This will " "run any test tagged with the specified value, " "e.g -t s3 -t ec2") known_args, remaining_args = parser.parse_known_args() attribute_args = [] for service_attribute in known_args.service_tests: attribute_args.extend(['-a', '!notdefault,' +service_attribute]) if not attribute_args: # If the user did not specify any filtering criteria, we at least # will filter out any test tagged 'notdefault'. attribute_args = ['-a', '!notdefault'] all_args = [__file__] + attribute_args + remaining_args print "nose command:", ' '.join(all_args) if run(argv=all_args): # run will return True is all the tests pass. We want # this to equal a 0 rc return 0 else: return 1
def main(): description = ("Runs footmark unit and/or integration tests. " "Arguments will be passed on to nosetests. " "See nosetests --help for more information.") parser = argparse.ArgumentParser(description=description) parser.add_argument('-t', '--service-tests', action="append", default=[], help="Run tests for a given service. This will " "run any test tagged with the specified value, " "e.g -t test_instance_attribute -t test_manage_instances") known_args, remaining_args = parser.parse_known_args() attribute_args = [] for service_attribute in known_args.service_tests: attribute_args.extend(['-a', '!notdefault,' + service_attribute]) if not attribute_args: # If the user did not specify any filtering criteria, we at least # will filter out any test tagged 'notdefault'. attribute_args = ['-a', '!notdefault'] # Set default tests used by e.g. tox. For Py2 this means all unit # tests, while for Py3 it's just whitelisted ones. if 'default' in remaining_args: # Run from the base project directory os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) for i, arg in enumerate(remaining_args): if arg == 'default': remaining_args[i] = 'tests/unit' all_args = [__file__] + attribute_args + remaining_args if run(argv=all_args): # run will return True is all the tests pass. We want # this to equal a 0 rc return 0 else: return 1
def main(): description = ("Runs scarlett unit and/or integration tests. " "Arguments will be passed on to nosetests. " "See nosetests --help for more information.") parser = argparse.ArgumentParser(description=description) parser.add_argument('-t', '--service-tests', action="append", default=[], help="Run tests for a given service. This will " "run any test tagged with the specified value, " "e.g -t listeners -t client") known_args, remaining_args = parser.parse_known_args() attribute_args = [] for service_attribute in known_args.service_tests: attribute_args.extend([ '-a', '!notdefault,' + service_attribute, '--with-coverage' '-v', '--cover-erase', '--cover-package=scarlett' '-d' ]) if not attribute_args: # If the user did not specify any filtering criteria, we at least # will filter out any test tagged 'notdefault'. attribute_args = [ '-a', '!notdefault', '--with-coverage', '-v', '--cover-erase', '--cover-package=scarlett', '-d' ] # Set default tests used by e.g. tox. For Py2 this means all unit # tests, while for Py3 it's just whitelisted ones. if 'default' in remaining_args: # Run from the base project directory os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) for i, arg in enumerate(remaining_args): if arg == 'default': remaining_args[i] = 'tests/unit' if 'gst_improved' in remaining_args: # Run from the base project directory os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) for i, arg in enumerate(remaining_args): if arg == 'gst_improved': remaining_args[i] = 'tests/unit/future' all_args = [__file__] + attribute_args + remaining_args print("nose command:", ' '.join(all_args)) if run(argv=all_args): # run will return True is all the tests pass. We want # this to equal a 0 rc del os.environ['MAIN_DIR'] del os.environ['SCARLETT_CONFIG'] del os.environ['SCARLETT_HMM'] del os.environ['SCARLETT_LM'] del os.environ['SCARLETT_DICT'] return 0 else: return 1
def main(): if os.path.exists('xunit_results'): shutil.rmtree('xunit_results') os.mkdir('xunit_results') numpy.test( 'full', extra_argv='--with-xunit --xunit-file=xunit_results/numpy_tests.xml'. split()) run(defaultTest='jasmin_scivm/tests', argv='dummy --with-xunit --xunit-file=xunit_results/jap_tests.xml'. split(), exit=False) run(defaultTest='cdat_lite', argv='dummy --with-xunit --xunit-file=xunit_results/cdat_tests.xml'. split(), exit=False)
def run(self, args=None): try: self.setUp() # discover and run tests # TODO(zns): check if we still need a verbosity flag verbosity = 1 if '--verbose' in sys.argv: verbosity = 2 # If any argument looks like a test name but doesn't have # "nova.tests" in front of it, automatically add that so we don't # have to type as much show_elapsed = True argv = [] if args is None: args = sys.argv has_base = False for x in args: if x.startswith(('functional', 'unit', 'client')): argv.append('keystone.test.%s' % x) has_base = True elif x.startswith('--hide-elapsed'): show_elapsed = False elif x.startswith('--trace-calls'): pass elif x.startswith('--debug'): pass elif x.startswith('-'): argv.append(x) else: argv.append(x) if x != args[0]: has_base = True if not has_base and self.directory_base is not None: argv.append(self.directory_base) c = noseconfig.Config(stream=sys.stdout, env=os.environ, verbosity=3, workingDir=TEST_DIR, plugins=core.DefaultPluginManager()) runner = NovaTestRunner(stream=c.stream, verbosity=c.verbosity, config=c, show_elapsed=show_elapsed) return not core.run(config=c, testRunner=runner, argv=argv + ['--no-path-adjustment']) finally: self.tearDown()
def run_tests(c=None): # NOTE(bgh): I'm not entirely sure why but nose gets confused here when # calling run_tests from a plugin directory run_tests.py (instead of the # main run_tests.py). It will call run_tests with no arguments and the # testing of run_tests will fail (though the plugin tests will pass). For # now we just return True to let the run_tests test pass. if not c: return True runner = CrdTestRunner(stream=c.stream, verbosity=c.verbosity, config=c) return not core.run(config=c, testRunner=runner)
def run_tests(c): logger = logging.getLogger() hdlr = logging.StreamHandler() formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formatter) logger.addHandler(hdlr) logger.setLevel(logging.DEBUG) runner = QuantumTestRunner(stream=c.stream, verbosity=c.verbosity, config=c) return not core.run(config=c, testRunner=runner)
def run(self): try: from nose.core import run except ImportError: raise DistutilsModuleError('nose <http://nose.readthedocs.org/> ' 'is needed to run the tests') self.run_command('build') major, minor = sys.version_info[:2] lib_dir = "build/lib.{0}-{1}.{2}".format(get_platform(), major, minor) print(header(' Tests ')) if not run(argv=[__file__, '-v', lib_dir]): raise DistutilsError('at least one of the tests failed')
def wrap_func(): stdout = os.sys.stdout stderr = os.sys.stderr redirected = RedirectText(self.txt_ctrl) os.sys.stdout = redirected os.sys.stderr = redirected try: nose_cmd = self.__get_nose_command() browser_name = self.cb_browser.GetStringSelection() Browser.DEFAULT_BROWSER = browser_name report_folder = self.__get_safe_path_from_root_folder(RootFolder.REPORTS) BaseTest.FAILED_SCREENSHOT_FOLDER = report_folder easy_selenium_cmd = u" ".join(nose_cmd).replace("nosetests", "easy_selenium_cli.py -b " + browser_name) print u"Executing command:\n%s" % easy_selenium_cmd print u"Nose output:" run(argv=nose_cmd[1:]) finally: dialog.close_event.set() os.sys.stdout = stdout os.sys.stderr = stderr
def run_tests(c=None): # NOTE(bgh): I'm not entirely sure why but nose gets confused here when # calling run_tests from a plugin directory run_tests.py (instead of the # main run_tests.py). It will call run_tests with no arguments and the # testing of run_tests will fail (though the plugin tests will pass). For # now we just return True to let the run_tests test pass. if not c: return True runner = QuantumTestRunner(stream=c.stream, verbosity=c.verbosity, config=c) return not core.run(config=c, testRunner=runner)
def run(): argv = sys.argv stream = sys.stdout verbosity = 3 testdir = os.path.dirname(os.path.abspath(__file__)) conf = config.Config(stream=stream, env=os.environ, verbosity=verbosity, workingDir=testdir, plugins=core.DefaultPluginManager()) sys.exit(not core.run(config=conf, argv=argv))
def run(self, args=None): try: print 'Running test suite: %s' % self.__class__.__name__ self.setUp() # discover and run tests # If any argument looks like a test name but doesn't have # "keystone.test" in front of it, automatically add that so we # don't have to type as much show_elapsed = True argv = [] if args is None: args = sys.argv has_base = False for x in args: if x.startswith(('functional', 'unit', 'client')): argv.append('keystone.test.%s' % x) has_base = True elif x.startswith('--hide-elapsed'): show_elapsed = False elif x.startswith('-'): argv.append(x) else: argv.append(x) if x != args[0]: has_base = True if not has_base and self.directory_base is not None: argv.append(self.directory_base) argv = ['--no-path-adjustment'] + argv[1:] logger.debug("Running set of tests with args=%s" % argv) c = noseconfig.Config(stream=sys.stdout, env=os.environ, verbosity=3, workingDir=TEST_DIR, plugins=core.DefaultPluginManager(), args=argv) runner = NovaTestRunner(stream=c.stream, verbosity=c.verbosity, config=c, show_elapsed=show_elapsed) result = not core.run(config=c, testRunner=runner, argv=argv) return int(result) # convert to values applicable to sys.exit() except Exception, exc: logger.exception(exc) raise exc
def run(): argv = sys.argv stream = sys.stdout verbosity = 3 testdir = os.path.dirname(os.path.abspath(__file__)) conf = config.Config( stream=stream, env=os.environ, verbosity=verbosity, workingDir=testdir, plugins=core.DefaultPluginManager() ) conf.plugins.addPlugin(SlowTestsPlugin()) conf.plugins.addPlugin(StressTestsPlugin()) runner = VdsmTestRunner(stream=conf.stream, verbosity=conf.verbosity, config=conf) sys.exit(not core.run(config=conf, testRunner=runner, argv=argv))
def main(): description = ("Runs velvet unit and/or integration tests. " "Arguments will be passed on to nosetests. " "See nosetests --help for more information.") parser = argparse.ArgumentParser(description=description) known_args, remaining_args = parser.parse_known_args() attribute_args = ['-a', '!notdefault'] all_args = [__file__] + attribute_args + remaining_args print "nose command:", ' '.join(all_args) if run(argv=all_args): # run will return True is all the tests pass. We want # this to equal a 0 rc return 0 else: return 1
def wrap_func(): stdout = os.sys.stdout stderr = os.sys.stderr redirected = RedirectText(self.txt_ctrl) os.sys.stdout = redirected os.sys.stderr = redirected try: nose_cmd = self.__get_nose_command() browser_name = self.cb_browser.GetStringSelection() Browser.DEFAULT_BROWSER = browser_name report_folder = self.__get_safe_path_from_root_folder( RootFolder.REPORTS) BaseTest.FAILED_SCREENSHOT_FOLDER = report_folder easy_selenium_cmd = u" ".join(nose_cmd).replace( "nosetests", "easy_selenium_cli.py -b " + browser_name) print(u"Executing command:\n%s" % easy_selenium_cmd) print(u"Nose output:") run(argv=nose_cmd[1:]) finally: dialog.close_event.set() os.sys.stdout = stdout os.sys.stderr = stderr
def run(self, args=None): try: self.setUp() # discover and run tests # TODO(zns): check if we still need a verbosity flag verbosity = 1 if "--verbose" in sys.argv: verbosity = 2 # If any argument looks like a test name but doesn't have # "nova.tests" in front of it, automatically add that so we don't # have to type as much show_elapsed = True argv = [] if args is None: args = sys.argv has_base = False for x in args: if x.startswith(("functional", "unit", "client")): argv.append("keystone.test.%s" % x) has_base = True elif x.startswith("--hide-elapsed"): show_elapsed = False elif x.startswith("--trace-calls"): pass elif x.startswith("--debug"): pass elif x.startswith("-"): argv.append(x) else: argv.append(x) if x != args[0]: has_base = True if not has_base and self.directory_base is not None: argv.append(self.directory_base) c = noseconfig.Config( stream=sys.stdout, env=os.environ, verbosity=3, workingDir=TEST_DIR, plugins=core.DefaultPluginManager() ) runner = NovaTestRunner(stream=c.stream, verbosity=c.verbosity, config=c, show_elapsed=show_elapsed) return not core.run(config=c, testRunner=runner, argv=argv + ["--no-path-adjustment"]) finally: self.tearDown()
def run(): argv = sys.argv stream = sys.stdout testdir = os.path.dirname(os.path.abspath(__file__)) conf = config.Config(stream=stream, env=os.environ, workingDir=testdir, plugins=core.DefaultPluginManager()) conf.plugins.addPlugin(SlowTestsPlugin()) conf.plugins.addPlugin(StressTestsPlugin()) runner = VdsmTestRunner(stream=conf.stream, verbosity=conf.verbosity, config=conf) sys.exit(not core.run(config=conf, testRunner=runner, argv=argv))
def unit_test(extra_args=[]): """ run unit tests for this code base. Pass any arguments that nose accepts. """ path = os.path.realpath(os.path.join(os.getcwd(), 'tests/unit')) args = [ path, '-x', '-v', '--with-coverage', '--cover-erase', '--cover-package=./customs' ] if extra_args: args.extend(extra_args) if run(argv=args): return 0 else: return 1
def unit_test(extra_args=[]): """ run unit tests for this code base. Pass any arguments that nose accepts. """ path = os.path.realpath(os.path.join(os.getcwd(), 'tests/unit')) args = [ path, '-x', '-v', '--with-coverage', '--cover-erase', '--cover-package=./build/lib/freight_forwarder', '--cover-package=./freight_forwarder' ] if extra_args: args.extend(extra_args) if run(argv=args): return 0 else: return 1
def run_tests(c=None): logger = logging.getLogger() hdlr = logging.StreamHandler() formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formatter) logger.addHandler(hdlr) logger.setLevel(logging.DEBUG) # NOTE(bgh): I'm not entirely sure why but nose gets confused here when # calling run_tests from a plugin directory run_tests.py (instead of the # main run_tests.py). It will call run_tests with no arguments and the # testing of run_tests will fail (though the plugin tests will pass). For # now we just return True to let the run_tests test pass. if not c: return True runner = RyuTestRunner(stream=c.stream, verbosity=c.verbosity, config=c) return not core.run(config=c, testRunner=runner)
def run_tests(c=None): logger = logging.getLogger() hdlr = logging.StreamHandler() formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s") hdlr.setFormatter(formatter) logger.addHandler(hdlr) logger.setLevel(logging.DEBUG) # NOTE(bgh): I'm not entirely sure why but nose gets confused here when # calling run_tests from a plugin directory run_tests.py (instead of the # main run_tests.py). It will call run_tests with no arguments and the # testing of run_tests will fail (though the plugin tests will pass). For # now we just return True to let the run_tests test pass. if not c: return True runner = QuantumTestRunner(stream=c.stream, verbosity=c.verbosity, config=c) return not core.run(config=c, testRunner=runner)
def main(): description = "Runs slack unit and/or integration tests." parser = argparse.ArgumentParser(description=description) parser.add_argument('-t', '--service-tests', action='append', default=[], help="Run tests for a given service. This will " "run any test tagged with the specified value, " "e.g -t s3 -t chat") known_args, remaining_args = parser.parse_known_args() attribute_args = [] for service_attribute in known_args.service_tests: attribute_args.extend(['-a', '!notdefault,' +service_attribute]) if not attribute_args: attribute_args = ['-a', '!notdefault'] all_args = [__file__] + attribute_args + remaining_args print "nose command: {0}".format(' '.join(all_args)) if run(argv=all_args): return 0 else: return 1
def integration_tests(extra_args=[]): """ Run unit tests for this code base. Pass any arguments that nose accepts. :argument list extra_args: List of extra arguments """ path = os.path.realpath(os.path.join(os.getcwd(), 'tests/integration/')) args = [ '-x', '-v', '--with-coverage', '--cover-erase', '--cover-package=./app', path ] if extra_args: args.extend(extra_args) if run(argv=args): return 0 else: return 1
def test(self, verbose=False): """Performs the actual running of the tests. Parameters ---------- verbose : bool flag for running in verbose mode. Returns ------- bool test run success status """ # NOTE: it doesn't seem to matter what the first element of the argv # list is, there just needs to be something there. argv = [self._filename, '-I DO_NOT_IGNORE_ANYTHING'] if PY3: argv.extend(['--with-doctest', '--doctest-tests']) if verbose: argv.append('-v') return core.run(argv=argv, defaultTest=self._test_dir)
def main(whitelist=[]): description = ("Runs boto unit and/or integration tests. " "Arguments will be passed on to nosetests. " "See nosetests --help for more information.") parser = argparse.ArgumentParser(description=description) parser.add_argument('-t', '--service-tests', action="append", default=[], help="Run tests for a given service. This will " "run any test tagged with the specified value, " "e.g -t s3 -t ec2") known_args, remaining_args = parser.parse_known_args() attribute_args = [] for service_attribute in known_args.service_tests: attribute_args.extend(['-a', '!notdefault,' +service_attribute]) if not attribute_args: # If the user did not specify any filtering criteria, we at least # will filter out any test tagged 'notdefault'. attribute_args = ['-a', '!notdefault'] # Set default tests used by e.g. tox. For Py2 this means all unit # tests, while for Py3 it's just whitelisted ones. if 'default' in remaining_args: # Run from the base project directory os.chdir(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) for i, arg in enumerate(remaining_args): if arg == 'default': if sys.version_info[0] == 3: del remaining_args[i] remaining_args += PY3_WHITELIST else: remaining_args[i] = 'tests/unit' all_args = [__file__] + attribute_args + remaining_args print("nose command:", ' '.join(all_args)) if run(argv=all_args): # run will return True is all the tests pass. We want # this to equal a 0 rc return 0 else: return 1
def main(): description = "Runs slack unit and/or integration tests." parser = argparse.ArgumentParser(description=description) parser.add_argument('-t', '--service-tests', action='append', default=[], help="Run tests for a given service. This will " "run any test tagged with the specified value, " "e.g -t s3 -t chat") known_args, remaining_args = parser.parse_known_args() attribute_args = [] for service_attribute in known_args.service_tests: attribute_args.extend(['-a', '!notdefault,' + service_attribute]) if not attribute_args: attribute_args = ['-a', '!notdefault'] all_args = [__file__] + attribute_args + remaining_args print "nose command: {0}".format(' '.join(all_args)) if run(argv=all_args): return 0 else: return 1
def run(): flags.FLAGS.register_cli_opt(cfg.BoolOpt('hide-elapsed', default=False)) argv = flags.FLAGS(sys.argv) logging.setup() # If any argument looks like a test name but doesn't have "nova.tests" in # front of it, automatically add that so we don't have to type as much for i, arg in enumerate(argv): if arg.startswith('test_'): argv[i] = 'nova.tests.%s' % arg testdir = os.path.abspath(os.path.join("nova", "tests")) c = config.Config(stream=sys.stdout, env=os.environ, verbosity=3, workingDir=testdir, plugins=core.DefaultPluginManager()) runner = NovaTestRunner(stream=c.stream, verbosity=c.verbosity, config=c, show_elapsed=not flags.FLAGS.hide_elapsed) sys.exit(not core.run(config=c, testRunner=runner, argv=argv))
def run_nose(self, path, project_name): from nose.core import run from nose.config import Config argv = ["-d", "-s", "--verbose"] if exists(join(path, 'nose.cfg')): argv.append("--config=%s" % (join(path, 'nose.cfg'))) use_coverage = True try: import coverage argv.append("--with-coverage") argv.append("--cover-erase") #argv.append("--cover-package=%s" % project_name) argv.append("--cover-inclusive") except ImportError: pass argv.append(path) result = run(argv=argv) if not result: sys.exit(1)
''' SmartAPI Read-Only Test ''' from nose.core import run from biothings.tests import TornadoTestServerMixin from remote import SmartAPIRemoteTest class SmartAPILocalTest(TornadoTestServerMixin, SmartAPIRemoteTest): ''' Self contained test class Starts a Tornado server and perform tests against this server. ''' __test__ = True # explicitly set this to be a test class if __name__ == '__main__': print() print('SmartAPI Local Test') print('-' * 70 + '\n') run(argv=['', '--logging-level=INFO', '-v'], defaultTest='local.SmartAPILocalTest')
' %s' % str(test.test._testMethodName).ljust(60)) self.stream.flush() class GlanceTestRunner(core.TextTestRunner): def _makeResult(self): return GlanceTestResult(self.stream, self.descriptions, self.verbosity, self.config) if __name__ == '__main__': logger = logging.getLogger() hdlr = logging.StreamHandler() formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formatter) logger.addHandler(hdlr) logger.setLevel(logging.DEBUG) c = config.Config(stream=sys.stdout, env=os.environ, verbosity=3, plugins=core.DefaultPluginManager()) runner = GlanceTestRunner(stream=c.stream, verbosity=c.verbosity, config=c) sys.exit(not core.run(config=c, testRunner=runner, addplugins=[logcapture.GlanceLogCapture()]))
self.stream.flush() class NovaTestRunner(core.TextTestRunner): def _makeResult(self): return NovaTestResult(self.stream, self.descriptions, self.verbosity, self.config) if __name__ == '__main__': if not os.getenv('EC2_ACCESS_KEY'): print _('Missing EC2 environment variables. Please ' 'source the appropriate novarc file before ' 'running this test.') sys.exit(1) argv = FLAGS(sys.argv) testdir = os.path.abspath("./") c = config.Config(stream=sys.stdout, env=os.environ, verbosity=3, workingDir=testdir, plugins=core.DefaultPluginManager()) runner = NovaTestRunner(stream=c.stream, verbosity=c.verbosity, config=c) sys.exit(not core.run(config=c, testRunner=runner, argv=argv))
#!/usr/bin/env python import sys from nose.core import run if __name__ == '__main__': # This is a hack to get around the fact that this project does not use Django sys.argv = sys.argv[:1] + sys.argv[2:] run(*[], **{})
########NEW FILE######## __FILENAME__ = runtests #!/usr/bin/env python from django.conf import settings # collector import is required otherwise setuptools errors from nose.core import run, collector # Trick Django into thinking that we've configured a project, so importing # anything that tries to access attributes of `django.conf.settings` will just # return the default values, instead of crashing out. if not settings.configured: settings.configure() if __name__ == '__main__': run() ########NEW FILE######## __FILENAME__ = tests from unittest2 import TestCase from urllib import urlencode from django.contrib.auth.models import AnonymousUser from django.utils.datastructures import MergeDict from mock import Mock from mock_django.http import MockHttpRequest from mock_django.http import WsgiHttpRequest
# Copyright 2011 Josh Kearney # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Pyhole Unit Tests""" import os import sys from nose import config from nose import core if __name__ == "__main__": tests = os.path.abspath(os.path.join("tests")) tests_config = config.Config(stream=sys.stdout, env=os.environ, verbosity=3, workingDir=tests, plugins=core.DefaultPluginManager()) core.run(config=tests_config, argv=sys.argv)
self.store.create_block(myblock) ret = self.store._update_collection(GenericServerStore.BLOCK_ST, {Block.SERIAL_ID_KEY: myblock.ID.serialize()}, set_statement={"$set": {Block.SERIAL_CONTENT_COUNTER: 89}}, upsert=True, trx_record=False) self.assertIsInstance(ret, dict) def test_update_permissions(self): myblock = self.mother.make_block(self.user) # Check default permissions access = self.store.read_block_permissions(myblock.ID) perm = ElementPermissions(False) self.assertTrue(access, perm) # Update permissions access.read.grant("pepe") access.read.grant("jaunito") access.write.grant("jaunito") self.store.update_block_permissions(access) perms = self.store.read_block_permissions(myblock.ID) self.assertTrue(perms.read.is_granted("pepe")) self.assertFalse(perms.write.is_granted("pepe")) self.assertTrue(perms.read.is_granted("jaunito")) self.assertTrue(perms.write.is_granted("jaunito")) if __name__ == "__main__": run()
#!/usr/bin/env python # coding: utf-8 from nose.core import run if __name__ == '__main__': args = ['', '--cover-package=pyshorteners', '--with-coverage'] run(argv=args)
''' Discovery Tester Entry Point ''' from nose.core import run if __name__ == '__main__': print() print('Discovery Local Test') print('-' * 70) print() run(argv=['', '--logging-level=INFO', '-v'], defaultTest='discovery.tests')
self.stream.write( ' %s' % str(test.test._testMethodName).ljust(60)) self.stream.flush() class GlanceTestRunner(core.TextTestRunner): def _makeResult(self): return GlanceTestResult(self.stream, self.descriptions, self.verbosity, self.config) if __name__ == '__main__': logger = logging.getLogger() hdlr = logging.StreamHandler() formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formatter) logger.addHandler(hdlr) logger.setLevel(logging.DEBUG) c = config.Config(stream=sys.stdout, env=os.environ, verbosity=3, plugins=core.DefaultPluginManager()) runner = GlanceTestRunner(stream=c.stream, verbosity=c.verbosity, config=c) sys.exit(not core.run(config=c, testRunner=runner))
logger = logging.getLogger('melange') hdlr = logging.StreamHandler() formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formatter) logger.addHandler(hdlr) logger.setLevel(logging.DEBUG) # If any argument looks like a test name but doesn't have "melange.tests" # in front of it, automatically add that so we don't have to type as much show_elapsed = True argv = [] for x in sys.argv: if x.startswith('test_'): argv.append('melange.tests.%s' % x) elif x.startswith('--hide-elapsed'): show_elapsed = False else: argv.append(x) testdir = os.path.abspath(os.path.join("melange", "tests")) c = config.Config(stream=sys.stdout, env=os.environ, verbosity=3, workingDir=testdir, plugins=core.DefaultPluginManager()) runner = MelangeTestRunner(stream=c.stream, verbosity=c.verbosity, config=c, show_elapsed=show_elapsed) sys.exit(not core.run(config=c, testRunner=runner, argv=argv))
self._last_case = current_case self.stream.write(' %s' % str(test.test._testMethodName).ljust(60)) self.stream.flush() class BalancerTestRunner(core.TextTestRunner): def _makeResult(self): return BalancerTestResult(self.stream, self.descriptions, self.verbosity, self.config) if __name__ == '__main__': logger = logging.getLogger() hdlr = logging.StreamHandler() formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') hdlr.setFormatter(formatter) logger.addHandler(hdlr) logger.setLevel(logging.INFO) c = config.Config(stream=sys.stdout, env=os.environ, verbosity=3, plugins=core.DefaultPluginManager()) runner = BalancerTestRunner(stream=c.stream, verbosity=c.verbosity, config=c) sys.exit(not core.run(config=c, testRunner=runner))
#!/usr/bin/env python # coding: utf-8 from nose.core import run if __name__ == '__main__': args = [ '', ] run(argv=args)
""" Use <unit> to run only unit tests. Use <integration> to run only integration tests. Before start integration test set PW_TOKEN, PW_APP_CODE and PW_APP_GROUP_CODE in your environment variables """ if __name__ == '__main__': import argparse import os import sys from nose.core import run base_dir = os.path.dirname(os.path.abspath(__file__)) sys.path.append(base_dir) argv = [__file__, '-vv'] parser = argparse.ArgumentParser(description='Run tests.') known_args, remaining_args = parser.parse_known_args() argv = argv + remaining_args run(argv=argv)