def test_unexpected_warning(self): msg = 'Testing unexpected warnings, nothing to see here.' category = ResourceWarning for parents in ((AzulUnitTestCase, ), (AzulUnitTestCase, AlwaysTearDownTestCase), (AlwaysTearDownTestCase, AzulUnitTestCase)): with self.subTest(parents=parents): class Test(*parents): def test(self): warnings.warn(message=msg, category=category) case = Test('test') suite = TestSuite() result = TestResult() suite.addTest(case) suite.run(result) self.assertEqual(1, result.testsRun) failed_test, trace_back = cast(Tuple[Any, str], one(result.errors)) self.assertEqual( f'tearDownClass ({__name__}.{Test.__qualname__})', str(failed_test)) error_line = trace_back.splitlines()[-1] self.assertRegex(error_line, '^AssertionError') self.assertIn(str(category(msg)), error_line)
def selftest(logger): if os.environ.get('BORG_SELFTEST') == 'disabled': logger.debug("borg selftest disabled via BORG_SELFTEST env variable") return selftest_started = time.perf_counter() result = SelfTestResult() test_suite = TestSuite() for test_case in SELFTEST_CASES: module = sys.modules[test_case.__module__] # a normal borg user does not have pytest installed, we must not require it in the test modules used here. # note: this only detects the usual toplevel import assert 'pytest' not in dir(module), "pytest must not be imported in %s" % module.__name__ test_suite.addTest(defaultTestLoader.loadTestsFromTestCase(test_case)) test_suite.run(result) result.log_results(logger) successful_tests = result.successful_test_count() count_mismatch = successful_tests != SELFTEST_COUNT if result.wasSuccessful() and count_mismatch: # only print this if all tests succeeded logger.error("self test count (%d != %d) mismatch, either test discovery is broken or a test was added " "without updating borg.selftest", successful_tests, SELFTEST_COUNT) if not result.wasSuccessful() or count_mismatch: logger.error("self test failed\n" "Could be a bug either in Borg, the package / distribution you use, your OS or your hardware.") sys.exit(2) assert False, "sanity assertion failed: ran beyond sys.exit()" selftest_elapsed = time.perf_counter() - selftest_started logger.debug("%d self tests completed in %.2f seconds", successful_tests, selftest_elapsed)
def selftest(logger): selftest_started = time.perf_counter() result = SelfTestResult() test_suite = TestSuite() for test_case in SELFTEST_CASES: test_suite.addTest(defaultTestLoader.loadTestsFromTestCase(test_case)) test_suite.run(result) result.log_results(logger) successful_tests = result.successful_test_count() count_mismatch = successful_tests != SELFTEST_COUNT if result.wasSuccessful() and count_mismatch: # only print this if all tests succeeded logger.error( "self test count (%d != %d) mismatch, either test discovery is broken or a test was added " "without updating borg.selftest", successful_tests, SELFTEST_COUNT) if not result.wasSuccessful() or count_mismatch: logger.error( "self test failed\n" "This is a bug either in Borg or in the package / distribution you use." ) sys.exit(2) assert False, "sanity assertion failed: ran beyond sys.exit()" selftest_elapsed = time.perf_counter() - selftest_started logger.debug("%d self tests completed in %.2f seconds", successful_tests, selftest_elapsed)
def main(): modules = ['test_360', 'test_dependencies', 'test_optional_dependencies', 'test_simple'] simple_suite = TestSuite() loader = TestLoader() result = TestResult() for module in modules: suite = loader.loadTestsFromName(module) simple_suite.addTest(suite) print print 'Running simple test suite...' print simple_suite.run(result) print print 'Ran {0} tests.'.format(result.testsRun) print if len(result.errors) > 0: print '#########################################################' print 'There are {0} errors. See below for tracebacks:'.format(len(result.errors)) print '#########################################################' print for error in result.errors: print error[1] print print '#########################################################' print 'There are {0} errors. See above for tracebacks.'.format(len(result.errors)) print '#########################################################' else: print 'All tests passed.' print
def run(suite: unittest.TestSuite) -> str: result = unittest.TestResult() with contextlib.ExitStack() as stack: if nowidget.IPYTHON: import IPython stack.enter_context(ipython_compiler(IPython.get_ipython())) suite.run(result) return result
def run(self, result): if not testProgram is None: # Run compiled tests, parse output and prepare tests log.debug("CTestTestSuite.run(): preparing to run test program %s", self.testProgram) log.debug("Tests to run: %s", repr((test.__name__ for test in tests))) pass TestSuite.run(self, result)
def selftest(logger): selftest_started = time.perf_counter() result = SelfTestResult() test_suite = TestSuite() for test_case in SELFTEST_CASES: test_suite.addTest(defaultTestLoader.loadTestsFromTestCase(test_case)) test_suite.run(result) result.log_results(logger) successful_tests = result.successful_test_count() count_mismatch = successful_tests != SELFTEST_COUNT if result.wasSuccessful() and count_mismatch: # only print this if all tests succeeded logger.error("self test count (%d != %d) mismatch, either test discovery is broken or a test was added " "without updating borg.selftest", successful_tests, SELFTEST_COUNT) if not result.wasSuccessful() or count_mismatch: logger.error("self test failed\n" "This is a bug either in Borg or in the package / distribution you use.") sys.exit(2) assert False, "sanity assertion failed: ran beyond sys.exit()" selftest_elapsed = time.perf_counter() - selftest_started logger.debug("%d self tests completed in %.2f seconds", successful_tests, selftest_elapsed)
from pathlib import Path from unittest import TestLoader, TestResult, TestSuite from Applications.Unittests import module1, module2, module3, module4, module5 __author__ = 'Xavier ROSSET' __maintainer__ = 'Xavier ROSSET' __email__ = '*****@*****.**' __status__ = "Production" # ========================== # Define French environment. # ========================== locale.setlocale(locale.LC_ALL, "fr_FR") # ============ # Main script. # ============ exit_code = {False: 1, True: 0} suite, loader, result = TestSuite(), TestLoader(), TestResult() suite.addTests(loader.loadTestsFromModule(module1)) suite.addTests(loader.loadTestsFromModule(module2)) suite.addTests(loader.loadTestsFromModule(module3)) suite.addTests(loader.loadTestsFromModule(module4)) suite.addTests(loader.loadTestsFromModule(module5)) if Path("F:/").exists(): from Applications.Unittests import module6 suite.addTests(loader.loadTestsFromModule(module6)) suite.run(result) sys.exit(exit_code[result.wasSuccessful()])
if t.plugin in PLUGINS: tag = 'enabled' else: tag = 'disabled' print " %-10s %s" % (tag, str(t)) s = TestSuite() for t in tests: if t.plugin in PLUGINS: s.addTest(t) if OPTIONS.tinderbox: r = TinderboxTestResult() else: r = DevTestResult() s.run(r) r.finish() if r.wasSuccessful(): print "OK: %d tests passed" % r.testsRun else: for c, tr in r.errors: print "Test Error: Python Exception" print " Test command: %s" % c.getCommand() print " Stack trace:" print tr for c, tr in r.failures: print "Test Failure: %s" % "" print " Test command: %s" % c.getCommand() print " Failure msg: %s" % tr
test_modules = [test_core, test_csv, test_database, test_datatypes, test_dispatcher, test_gettext, test_handlers, test_html, test_i18n, test_ical, test_odf, test_rss, test_srx, test_stl, test_tmx, test_uri, test_fs, test_validators, test_web, test_workflow, test_xliff, test_xml, test_xmlfile] loader = TestLoader() if __name__ == '__main__': usage = '%prog [OPTIONS]' description = 'Run ikaaro tests' parser = OptionParser(usage, description=description) parser.add_option('-m', '--mode', default='standard', help='tests mode') options, args = parser.parse_args() suite = TestSuite() for module in test_modules: suite.addTest(loader.loadTestsFromModule(module)) if options.mode == 'standard': ret = TextTestRunner(verbosity=1).run(suite) elif options.mode == 'junitxml': path = get_abspath('./junit.xml') print('Result is here: %s' % path) f = file(path, 'wb') result = JUnitXmlResult(f) result.startTestRun() ret = suite.run(result) result.stopTestRun() exit_code = not ret.wasSuccessful() exit(exit_code)
def run(self, result, debug=False): self.output_prerun_info() TestSuite.run(self, result, debug) self.output_postrun_info()
def run_test_suite(self, suite: unittest.TestSuite) -> None: self.result = unittest.TestResult() suite.run(self.result)
action="store") argument_parser.add_argument("-gfk", "--generateFileKey", type=bool, required=False, default=False, action="store") arguments = argument_parser.parse_args() if arguments.test: print("Running unittests...") test_result = TestResult() unit_test_suite = TestSuite() unit_test_suite.addTests( tests=[Test_VigenereCipher.test_encode_and_decode]) unit_test_suite.run(test_result) print("Unittest error count: ", len(test_result.errors)) elif arguments.encodeFile is not None: pass elif arguments.decodeFile is not None: pass elif arguments.encodeResources: files_to_encode = [ file for file in listdir(RESOURCE_DIRECTORY) if isfile(join(RESOURCE_DIRECTORY, file)) and ".json" or ".csv" in file ] ciphers = initialize_lock_and_key_ciphers() for file_name in files_to_encode: encoded_file_name = ciphers['file_name'].encode(file_name)
test_modules = [ test_core, test_csv, test_database, test_datatypes, test_dispatcher, test_gettext, test_handlers, test_html, test_i18n, test_ical, test_odf, test_rss, test_srx, test_stl, test_tmx, test_uri, test_fs, test_validators, test_web, test_workflow, test_xliff, test_xml, test_xmlfile ] loader = TestLoader() if __name__ == '__main__': usage = '%prog [OPTIONS]' description = 'Run ikaaro tests' parser = OptionParser(usage, description=description) parser.add_option('-m', '--mode', default='standard', help='tests mode') options, args = parser.parse_args() suite = TestSuite() for module in test_modules: suite.addTest(loader.loadTestsFromModule(module)) if options.mode == 'standard': ret = TextTestRunner(verbosity=1).run(suite) elif options.mode == 'junitxml': path = get_abspath('./junit.xml') print('Result is here: %s' % path) f = file(path, 'wb') result = JUnitXmlResult(f) result.startTestRun() ret = suite.run(result) result.stopTestRun() exit_code = not ret.wasSuccessful() exit(exit_code)
from Applications.Unittests import module1, module2, module3 __author__ = 'Xavier ROSSET' __maintainer__ = 'Xavier ROSSET' __email__ = '*****@*****.**' __status__ = "Production" # ========================== # Define French environment. # ========================== if sys.platform.startswith("win"): locale.setlocale(locale.LC_ALL, ("french", "fr_FR.ISO8859-1")) elif sys.platform.startswith("lin"): locale.setlocale(locale.LC_ALL, "fr_FR.utf8") # ============ # Main script. # ============ exit_code = {False: 1, True: 0} suite, loader, result = TestSuite(), TestLoader(), TestResult() suite.addTests(loader.loadTestsFromModule(module1)) suite.addTests(loader.loadTestsFromModule(module2)) suite.addTests(loader.loadTestsFromModule(module3)) if sys.platform.startswith("win"): from Applications.Unittests import module4, module5 suite.addTests(loader.loadTestsFromModule(module4)) suite.addTests(loader.loadTestsFromModule(module5)) suite.run(result) sys.exit(exit_code[result.wasSuccessful()])