def test_add_test_names_status(self): """Tests add_test_names_status.""" test_names = ['test1', 'test2', 'test3'] collection = ResultCollection(test_results=[PASSED_RESULT]) collection.add_test_names_status(test_names, TestStatus.SKIP) disabled_test_names = ['test4', 'test5', 'test6'] collection.add_test_names_status(disabled_test_names, TestStatus.SKIP, expected_status=TestStatus.SKIP) self.assertEqual(collection.test_results[0], PASSED_RESULT) unexpected_skipped = collection.tests_by_expression( lambda t: not t.expected() and t.status == TestStatus.SKIP) self.assertEqual(unexpected_skipped, set(['test1', 'test2', 'test3'])) self.assertEqual(collection.disabled_tests(), set(['test4', 'test5', 'test6']))
def parse_passed_failed_tests_for_interrupted_run(output): """Parses xcode runner output to get passed & failed tests. Args: output: [str] An output of test run. Returns: test_result_util.ResultCollection: Results of tests parsed. """ result = ResultCollection() passed_tests = [] failed_tests = [] # Test has format: # [09:04:42:INFO] Test case '-[Test_class test_method]' passed. # [09:04:42:INFO] Test Case '-[Test_class test_method]' failed. passed_test_regex = re.compile( r'Test [Cc]ase \'\-\[(.+?)\s(.+?)\]\' passed') failed_test_regex = re.compile( r'Test [Cc]ase \'\-\[(.+?)\s(.+?)\]\' failed') def _find_list_of_tests(tests, regex): """Adds test names matched by regex to result list.""" for test_line in output: m_test = regex.search(test_line) if m_test: tests.append('%s/%s' % (m_test.group(1), m_test.group(2))) _find_list_of_tests(passed_tests, passed_test_regex) _find_list_of_tests(failed_tests, failed_test_regex) result.add_test_names_status(passed_tests, TestStatus.PASS) result.add_test_names_status( failed_tests, TestStatus.FAIL, test_log='Test failed in interrupted(timedout) run.') LOGGER.info('%d passed tests for interrupted build.' % len(passed_tests)) LOGGER.info('%d failed tests for interrupted build.' % len(failed_tests)) return result