def test_double_case_multi_scenario_no_filter_no_topo(self): lm = LogManager(root_dir="test-logs") tsm = TestSystemManager(None, None, log_manager=lm) tsm.configure_logging(debug=True) result1 = tsm.run_scenario(SampleTestScenario, [SampleTestCase, SampleOtherTestCase]) result2 = tsm.run_scenario(SampleOtherTestScenario, [SampleTestCase, SampleOtherTestCase]) self.assertEqual(SampleTestScenario, result1.scenario) self.assertEqual(SampleOtherTestScenario, result2.scenario) self.assertEqual(4, result1.testsRun) self.assertEqual(2, len(result1.failures)) self.assertEqual(2, len(result1.successes)) self.assertEqual(0, len(result1.errors)) self.assertEqual(result1.successes[0].current_scenario.__class__, SampleTestScenario) self.assertEqual(result1.successes[0].__class__, SampleTestCase) self.assertEqual(result1.successes[1].current_scenario.__class__, SampleTestScenario) self.assertEqual(result1.successes[1].__class__, SampleOtherTestCase) self.assertEqual(2, result2.testsRun) self.assertEqual(1, len(result2.failures)) self.assertEqual(1, len(result2.successes)) self.assertEqual(0, len(result2.errors)) self.assertEqual(result2.successes[0].current_scenario.__class__, SampleOtherTestScenario) self.assertEqual(result2.successes[0].__class__, SampleTestCase)
def test_load_tests(self): lm = LogManager(root_dir="test-logs") tsm = TestSystemManager(None, None, log_manager=lm) tsm.configure_logging(debug=True) tsm.load_tests([SampleTestCase, SampleOtherTestCase]) for i, tc in tsm.test_cases.iteritems(): self.assertEqual(i, tc._get_name()) self.assertFalse(isinstance(tc, TestCase)) self.assertTrue(issubclass(tc, TestCase))
def test_single_case_single_scenario_no_filter_no_topo(self): lm = LogManager(root_dir="test-logs") tsm = TestSystemManager(None, None, log_manager=lm) tsm.configure_logging(debug=True) result = tsm.run_scenario(SampleTestScenario, [SampleOtherTestCase]) self.assertEqual(SampleTestScenario, result.scenario) self.assertEqual(2, result.testsRun) self.assertEqual(1, len(result.failures)) self.assertEqual(1, len(result.successes)) self.assertEqual(0, len(result.errors))
def test_multi_case_multi_scenario_filter_no_topo(self): lm = LogManager(root_dir="test-logs") tsm = TestSystemManager(None, None, log_manager=lm) tsm.configure_logging(debug=True) tsm.add_test(SampleTestCase) tsm.add_test(SampleOtherTestCase) results = tsm.run_all_tests([SampleOtherTestScenario]) self.assertNotIn(SampleTestScenario, results) self.assertIn(SampleOtherTestScenario, results) self.assertEqual(2, results[SampleOtherTestScenario].testsRun) self.assertEqual(1, len(results[SampleOtherTestScenario].failures)) self.assertEqual(1, len(results[SampleOtherTestScenario].successes)) self.assertEqual(0, len(results[SampleOtherTestScenario].errors))
def test_multi_case_multi_scenario_no_filter_no_topo(self): lm = LogManager(root_dir="test-logs") tsm = TestSystemManager(None, None, log_manager=lm) tsm.configure_logging(debug=True) tsm.add_test(SampleTestCase) tsm.add_test(SampleOtherTestCase) results = tsm.run_all_tests() self.assertIn(SampleTestScenario, results) self.assertIn(SampleOtherTestScenario, results) self.assertEqual(4, results[SampleTestScenario].testsRun) self.assertEqual(2, len(results[SampleTestScenario].failures)) self.assertEqual(2, len(results[SampleTestScenario].successes)) self.assertEqual(0, len(results[SampleTestScenario].errors)) self.assertEqual(2, results[SampleOtherTestScenario].testsRun) self.assertEqual(1, len(results[SampleOtherTestScenario].failures)) self.assertEqual(1, len(results[SampleOtherTestScenario].successes)) self.assertEqual(0, len(results[SampleOtherTestScenario].errors)) for s in results.iterkeys(): print "========================================" print "Scenario [" + s.__name__ + "]" print "Passed [{0}/{1}]".format(len(results[s].successes), results[s].testsRun) print "Failed [{0}/{1}]".format(len(results[s].failures), results[s].testsRun) print "Error [{0}/{1}]".format(len(results[s].errors), results[s].testsRun) print "" for tc, err in results[s].failures: print "------------------------------" print "Test Case FAILED: [" + tc._get_name() + "]" print "Failure Message:" print err for tc, err in results[s].errors: print "------------------------------" print "Test Case ERROR: [" + tc._get_name() + "]" print "Error Message:" print err
print 'Setting up log manager' log_manager = LogManager(root_dir=log_dir) console_log = log_manager.add_stdout_logger(name='tsm-run-console', log_level=logging.DEBUG if debug is True else logging.INFO) log_manager.rollover_logs_fresh(file_filter='*.log') console_log.debug('Setting up PTM') ptm = PhysicalTopologyManager(root_dir=root_dir, log_manager=log_manager) ptm.configure_logging(debug=debug) console_log.debug('Setting up VTM') vtm = VirtualTopologyManager(physical_topology_manager=ptm, client_api_impl=client_impl, log_manager=log_manager) console_log.debug('Setting up TSM') tsm = TestSystemManager(ptm, vtm, log_manager=log_manager) tsm.configure_logging(debug=debug) scenario_filters = [TestScenario.get_class(s) for s in scenario_filter_list] \ if len(scenario_filter_list) != 0 else None test_cases = map(TestCase.get_class, tests) console_log.debug('Test Case Classes = ' + str(test_cases)) # Run test cases, possibly filtered on scenarios tsm.load_tests(test_cases) console_log.debug('Running all tests with scenario filter: ' + str(scenario_filters)) results = tsm.run_all_tests(scenario_filters)