def test_filter_blacklist_files_for_windows(self): tests_runtimes = [ ("dir1/file1.js", 20.32), ("dir2/file2.js", 24.32), ("dir1/dir3/file3.js", 36.32), ] blacklisted_test = tests_runtimes[1][0] with patch("os.path.exists") as exists_mock, patch( ns("suitesconfig")) as suitesconfig_mock: exists_mock.return_value = True evg = Mock() suitesconfig_mock.get_suite.return_value.tests = [ runtime[0].replace("/", "\\") for runtime in tests_runtimes if runtime[0] != blacklisted_test ] main = grt.Main(evg) main.config_options = Mock() main.config_options.suite = "suite" filtered_list = main.filter_existing_tests(tests_runtimes) self.assertNotIn(blacklisted_test, filtered_list) self.assertIn(tests_runtimes[2], filtered_list) self.assertIn(tests_runtimes[0], filtered_list) self.assertEqual(2, len(filtered_list))
def test_filter_blacklist_files(self): tests_runtimes = [ teststats_utils.TestRuntime(test_name="dir1/file1.js", runtime=20.32), teststats_utils.TestRuntime(test_name="dir2/file2.js", runtime=24.32), teststats_utils.TestRuntime(test_name="dir1/file3.js", runtime=36.32), ] blacklisted_test = tests_runtimes[1][0] with patch("os.path.exists") as exists_mock, patch( ns("suitesconfig")) as suitesconfig_mock: exists_mock.return_value = True evg = Mock() suitesconfig_mock.get_suite.return_value.tests = \ [runtime[0] for runtime in tests_runtimes if runtime[0] != blacklisted_test] main = grt.Main(evg) main.config_options = Mock() main.config_options.suite = "suite" filtered_list = main.filter_existing_tests(tests_runtimes) self.assertEqual(2, len(filtered_list)) self.assertNotIn(blacklisted_test, filtered_list) self.assertIn(tests_runtimes[2], filtered_list) self.assertIn(tests_runtimes[0], filtered_list)
def test_calculate_suites_error(self): response = Mock() response.status_code = requests.codes.INTERNAL_SERVER_ERROR evg = Mock() evg.test_stats.side_effect = requests.HTTPError(response=response) main = grt.Main(evg) main.options = Mock() main.options.execution_time_minutes = 10 main.config_options = self.get_mock_options() main.list_tests = Mock(return_value=["test{}.js".format(i) for i in range(100)]) with self.assertRaises(requests.HTTPError): main.calculate_suites(_DATE, _DATE)
def test_calculate_suites_uses_fallback_for_no_results(self): n_tests = 100 evg = Mock() evg.test_stats.return_value = [] main = grt.Main(evg) main.options = Mock() main.config_options = self.get_mock_options() main.list_tests = Mock(return_value=["test{}.js".format(i) for i in range(n_tests)]) suites = main.calculate_suites(_DATE, _DATE) self.assertEqual(main.config_options.fallback_num_sub_suites, len(suites)) for suite in suites: self.assertEqual(50, len(suite.tests)) self.assertEqual(n_tests, len(main.test_list))
def test_calculate_suites_fallback(self): response = Mock() response.status_code = requests.codes.SERVICE_UNAVAILABLE evg = Mock() evg.test_stats.side_effect = requests.HTTPError(response=response) main = grt.Main(evg) main.options = Mock() main.options.execution_time_minutes = 10 main.config_options = self.get_mock_options() main.list_tests = Mock(return_value=["test{}.js".format(i) for i in range(100)]) suites = main.calculate_suites(_DATE, _DATE) self.assertEqual(main.config_options.fallback_num_sub_suites, len(suites)) for suite in suites: self.assertEqual(50, len(suite.tests))
def test_calculate_suites_error(self): response = Mock() response.status_code = requests.codes.INTERNAL_SERVER_ERROR evg = Mock() evg.test_stats.side_effect = requests.HTTPError(response=response) main = grt.Main(evg) main.options = Mock() main.options.execution_time_minutes = 10 main.config_options = grt.ConfigOptions(2, 15, "project", "", 1, 30, True, "task", "suite", "variant", False, "") main.list_tests = Mock( return_value=["test{}.js".format(i) for i in range(100)]) with self.assertRaises(requests.HTTPError): main.calculate_suites(_DATE, _DATE)
def test_calculate_suites(self): evg = Mock() evg.test_stats.return_value = [{ "test_file": "test{}.js".format(i), "avg_duration_pass": 60, "num_pass": 1 } for i in range(100)] main = grt.Main(evg) main.options = Mock() main.config_options = self.get_mock_options() with patch('os.path.exists') as exists_mock: exists_mock.return_value = True suites = main.calculate_suites(_DATE, _DATE) # There are 100 tests taking 1 minute, with a target of 10 min we expect 10 suites. self.assertEqual(10, len(suites)) for suite in suites: self.assertEqual(10, len(suite.tests))
def test_calculate_suites_uses_fallback_if_only_results_are_filtered(self): n_tests = 100 evg = Mock() evg.test_stats_by_project.return_value = [ Mock(test_file="test{}.js".format(i), avg_duration_pass=60, num_pass=1) for i in range(100) ] main = grt.Main(evg) main.options = Mock() main.config_options = self.get_mock_options() main.list_tests = Mock(return_value=["test{}.js".format(i) for i in range(n_tests)]) with patch("os.path.exists") as exists_mock: exists_mock.return_value = False suites = main.calculate_suites(_DATE, _DATE) self.assertEqual(main.config_options.fallback_num_sub_suites, len(suites)) for suite in suites: self.assertEqual(50, len(suite.tests)) self.assertEqual(n_tests, len(main.test_list))
def test_filter_missing_files(self): tests_runtimes = [ ("dir1/file1.js", 20.32), ("dir2/file2.js", 24.32), ("dir1/file3.js", 36.32), ] with patch("os.path.exists") as exists_mock, patch(ns("suitesconfig")) as suitesconfig_mock: exists_mock.side_effect = [False, True, True] evg = Mock() suitesconfig_mock.get_suite.return_value.tests = \ [runtime[0] for runtime in tests_runtimes] main = grt.Main(evg) main.config_options = Mock() main.config_options.suite = "suite" filtered_list = main.filter_existing_tests(tests_runtimes) self.assertEqual(2, len(filtered_list)) self.assertNotIn(tests_runtimes[0], filtered_list) self.assertIn(tests_runtimes[2], filtered_list) self.assertIn(tests_runtimes[1], filtered_list)
def test_calculate_suites(self): evg = Mock() evg.test_stats_by_project.return_value = [ Mock(test_file="test{}.js".format(i), avg_duration_pass=60, num_pass=1) for i in range(100) ] main = grt.Main(evg) main.options = Mock() main.options.max_sub_suites = 1000 main.config_options = self.get_mock_options() with patch("os.path.exists") as exists_mock, patch(ns("suitesconfig")) as suitesconfig_mock: exists_mock.return_value = True suitesconfig_mock.get_suite.return_value.tests = \ [stat.test_file for stat in evg.test_stats_by_project.return_value] suites = main.calculate_suites(_DATE, _DATE) # There are 100 tests taking 1 minute, with a target of 10 min we expect 10 suites. self.assertEqual(10, len(suites)) for suite in suites: self.assertEqual(10, len(suite.tests))