|
@@ -42,7 +42,8 @@ class ConcreteBaseTestImpact(BaseTestImpact):
|
|
|
|
|
|
class TestTiafDriver():
|
|
|
|
|
|
- def test_run_Tiaf_mars_index_prefix_is_supplied(self, caplog, main_args, mock_runtime, mocker):
|
|
|
+
|
|
|
+ def test_run_Tiaf_mars_index_prefix_is_supplied(self, caplog, main_args, skip_if_test_targets_disabled, mock_runtime, mocker):
|
|
|
# given:
|
|
|
# Default args + mars_index_prefix being provided,
|
|
|
# and transmit_report_to_mars is patched to intercept the call.
|
|
@@ -58,7 +59,7 @@ class TestTiafDriver():
|
|
|
# Tiaf should call the transmit function.
|
|
|
mock_mars.assert_called()
|
|
|
|
|
|
- def test_run_Tiaf_mars_index_prefix_is_not_supplied(self, caplog, main_args, mock_runtime, mocker):
|
|
|
+ def test_run_Tiaf_mars_index_prefix_is_not_supplied(self, caplog, main_args, skip_if_test_targets_disabled, mock_runtime, mocker):
|
|
|
# given:
|
|
|
# Default_args - mars index is not supplied.
|
|
|
mock_mars = mocker.patch("mars_utils.transmit_report_to_mars")
|
|
@@ -73,7 +74,7 @@ class TestTiafDriver():
|
|
|
mock_mars.assert_not_called()
|
|
|
|
|
|
@pytest.mark.parametrize("runtime_type,mock_type", [("native", "test_impact.native_test_impact.NativeTestImpact.__init__"), ("python", "test_impact.python_test_impact.PythonTestImpact.__init__")])
|
|
|
- def test_run_Tiaf_driver_runtime_type_selection(self, caplog, tiaf_args, mock_runtime, mocker, runtime_type, mock_type):
|
|
|
+ def test_run_Tiaf_driver_runtime_type_selection(self, caplog, tiaf_args, skip_if_test_targets_disabled, mock_runtime, mocker, runtime_type, mock_type):
|
|
|
# given:
|
|
|
# Default args + runtime_type
|
|
|
tiaf_args['runtime_type'] = runtime_type
|
|
@@ -92,6 +93,10 @@ class TestTiafDriver():
|
|
|
|
|
|
class TestTiafInitialiseStorage():
|
|
|
|
|
|
+ def skip_if_test_targets_disabled(skip_if_test_targets_disabled):
|
|
|
+ if not skip_if_test_targets_disabled:
|
|
|
+ pytest.skip("Test targets are disabled for this runtime, test will be skipped.")
|
|
|
+
|
|
|
@pytest.fixture
|
|
|
def runtime_type(self):
|
|
|
"""
|
|
@@ -105,10 +110,10 @@ class TestTiafInitialiseStorage():
|
|
|
output.append(entry)
|
|
|
return output
|
|
|
|
|
|
- def test_create_TestImpact_no_s3_bucket_name(self, caplog, tiaf_args, config_data, mocker, storage_config):
|
|
|
+ def test_create_TestImpact_no_s3_bucket_name(self, caplog, tiaf_args, skip_if_test_targets_disabled, config_data, mocker, storage_config):
|
|
|
# given:
|
|
|
# Default args.
|
|
|
- expected_storage_args = config_data, tiaf_args['suite'], tiaf_args[
|
|
|
+ expected_storage_args = config_data, tiaf_args['suites'], tiaf_args[
|
|
|
'commit'], storage_config['active_workspace'], storage_config['unpacked_coverage_data_file'], storage_config['previous_test_run_data_file'], storage_config['historic_workspace'], storage_config['historic_data_file'], storage_config['temp_workspace']
|
|
|
mock_local = mocker.patch(
|
|
|
"persistent_storage.PersistentStorageLocal.__init__", side_effect=SystemError(), return_value=None)
|
|
@@ -117,11 +122,11 @@ class TestTiafInitialiseStorage():
|
|
|
tiaf = ConcreteBaseTestImpact(tiaf_args)
|
|
|
|
|
|
# then:
|
|
|
- # PersistentStorageLocal should be called with suite, commit and config data as arguments.
|
|
|
+ # PersistentStorageLocal should be called with suites, commit and config data as arguments.
|
|
|
assert_list_content_equal(self.to_list(mock_local.call_args[0]).pop(), self.to_list(expected_storage_args).pop())
|
|
|
|
|
|
@pytest.mark.parametrize("bucket_name,top_level_dir,expected_top_level_dir", [("test_bucket", "test_dir", "test_dir/native")])
|
|
|
- def test_create_TestImpact_s3_bucket_name_supplied(self, caplog, tiaf_args, mocker, bucket_name, top_level_dir, config_data, expected_top_level_dir, storage_config):
|
|
|
+ def test_create_TestImpact_s3_bucket_name_supplied(self, caplog, tiaf_args, skip_if_test_targets_disabled, mocker, bucket_name, top_level_dir, config_data, expected_top_level_dir, storage_config):
|
|
|
# given:
|
|
|
# Default arguments + s3_bucket and s3_top_level_dir being set to the above parameters,
|
|
|
# and we patch PersistentStorageS3 to intercept the constructor call.
|
|
@@ -130,7 +135,7 @@ class TestTiafInitialiseStorage():
|
|
|
mock_storage = mocker.patch(
|
|
|
"persistent_storage.PersistentStorageS3.__init__", side_effect=SystemError())
|
|
|
|
|
|
- expected_storage_args = config_data, tiaf_args['suite'], tiaf_args[
|
|
|
+ expected_storage_args = config_data, tiaf_args['suites'], tiaf_args[
|
|
|
'commit'], bucket_name, expected_top_level_dir, tiaf_args['src_branch'], storage_config['active_workspace'], storage_config['unpacked_coverage_data_file'], storage_config['previous_test_run_data_file'], storage_config['temp_workspace']
|
|
|
|
|
|
# when:
|
|
@@ -141,7 +146,7 @@ class TestTiafInitialiseStorage():
|
|
|
# PersistentStorageS3 should be called with config data, commit, bucket_name, top_level_dir and src branch as arguments.
|
|
|
mock_storage.assert_called_with(*expected_storage_args)
|
|
|
|
|
|
- def test_create_TestImpact_s3_bucket_name_not_supplied(self, caplog, tiaf_args, mock_runtime, default_runtime_args, mocker, config_data):
|
|
|
+ def test_create_TestImpact_s3_bucket_name_not_supplied(self, caplog, tiaf_args, skip_if_test_targets_disabled, mock_runtime, default_runtime_args, mocker, config_data):
|
|
|
# given:
|
|
|
# Default arguments + s3_bucket and s3_top_level_dir arguments set to none.
|
|
|
tiaf_args['s3_bucket'] = None
|
|
@@ -157,7 +162,7 @@ class TestTiafInitialiseStorage():
|
|
|
# PersistentStorageS3 should not be called.
|
|
|
mock_storage.assert_not_called()
|
|
|
|
|
|
- def test_create_TestImpact_s3_top_level_dir_bucket_name_not_supplied(self, caplog, tiaf_args, mock_runtime, default_runtime_args, mocker, config_data):
|
|
|
+ def test_create_TestImpact_s3_top_level_dir_bucket_name_not_supplied(self, caplog, tiaf_args, skip_if_test_targets_disabled, mock_runtime, default_runtime_args, mocker, config_data):
|
|
|
# given:
|
|
|
# Default arguments + s3_bucket set to none and s3_top_level_dir is defined.
|
|
|
tiaf_args['s3_bucket'] = None
|
|
@@ -176,6 +181,10 @@ class TestTiafInitialiseStorage():
|
|
|
|
|
|
class TestTIAFNativeUnitTests():
|
|
|
|
|
|
+ def skip_if_test_targets_disabled(skip_if_test_targets_disabled):
|
|
|
+ if not skip_if_test_targets_disabled:
|
|
|
+ pytest.skip("Test targets are disabled for this runtime, test will be skipped.")
|
|
|
+
|
|
|
@pytest.fixture
|
|
|
def runtime_type(self):
|
|
|
"""
|
|
@@ -184,7 +193,7 @@ class TestTIAFNativeUnitTests():
|
|
|
return "native"
|
|
|
|
|
|
@pytest.mark.parametrize("safemode, arg_val", [("on", "on")])
|
|
|
- def test_create_NativeTestImpact_safe_mode_arguments(self, caplog, tiaf_args, mock_runtime, cpp_default_runtime_args, safemode, arg_val):
|
|
|
+ def test_create_NativeTestImpact_safe_mode_arguments(self, caplog, tiaf_args, skip_if_test_targets_disabled, mock_runtime, cpp_default_runtime_args, safemode, arg_val):
|
|
|
# given:
|
|
|
# Default args + safe_mode set.
|
|
|
tiaf_args['safe_mode'] = safemode
|
|
@@ -199,7 +208,7 @@ class TestTIAFNativeUnitTests():
|
|
|
assert_list_content_equal(
|
|
|
tiaf.runtime_args, cpp_default_runtime_args.values())
|
|
|
|
|
|
- def test_create_NativeTestImpact_no_safe_mode(self, caplog, tiaf_args, mock_runtime, cpp_default_runtime_args):
|
|
|
+ def test_create_NativeTestImpact_no_safe_mode(self, caplog, tiaf_args, skip_if_test_targets_disabled, mock_runtime, cpp_default_runtime_args):
|
|
|
# given:
|
|
|
# Default args + safe_mode set.
|
|
|
|
|
@@ -213,14 +222,14 @@ class TestTIAFNativeUnitTests():
|
|
|
tiaf.runtime_args, cpp_default_runtime_args.values())
|
|
|
|
|
|
@pytest.mark.parametrize("bucket_name,top_level_dir,expected_top_level_dir", [("test_bucket", "test_dir", "test_dir/native")])
|
|
|
- def test_create_NativeTestImpact_correct_s3_dir_runtime_type(self, config_data, caplog, tiaf_args, mock_runtime, cpp_default_runtime_args, mocker, bucket_name, storage_config, top_level_dir, expected_top_level_dir):
|
|
|
+ def test_create_NativeTestImpact_correct_s3_dir_runtime_type(self, config_data, caplog, tiaf_args, skip_if_test_targets_disabled, mock_runtime, cpp_default_runtime_args, mocker, bucket_name, storage_config, top_level_dir, expected_top_level_dir):
|
|
|
# given:
|
|
|
# Default args + s3_bucket and s3_top_level_dir set
|
|
|
tiaf_args['s3_bucket'] = bucket_name
|
|
|
tiaf_args['s3_top_level_dir'] = top_level_dir
|
|
|
mock_storage = mocker.patch(
|
|
|
"persistent_storage.PersistentStorageS3.__init__", side_effect=SystemError())
|
|
|
- expected_storage_args = config_data, tiaf_args['suite'], tiaf_args[
|
|
|
+ expected_storage_args = config_data, tiaf_args['suites'], tiaf_args[
|
|
|
'commit'], bucket_name, expected_top_level_dir, tiaf_args['src_branch'], storage_config['active_workspace'], storage_config['unpacked_coverage_data_file'], storage_config['previous_test_run_data_file'], storage_config['temp_workspace']
|
|
|
|
|
|
# when:
|
|
@@ -228,12 +237,16 @@ class TestTIAFNativeUnitTests():
|
|
|
tiaf = NativeTestImpact(tiaf_args)
|
|
|
|
|
|
# then:
|
|
|
- # PersistentStorageS3.__init__ should be called with config data, suite, commit, bucket_name, modified top level dir and src_branch as arguments
|
|
|
+ # PersistentStorageS3.__init__ should be called with config data, suites, commit, bucket_name, modified top level dir and src_branch as arguments
|
|
|
mock_storage.assert_called_with(*expected_storage_args)
|
|
|
|
|
|
|
|
|
class TestTIAFPythonUnitTests():
|
|
|
|
|
|
+ def skip_if_test_targets_disabled(skip_if_test_targets_disabled):
|
|
|
+ if not skip_if_test_targets_disabled:
|
|
|
+ pytest.skip("Test targets are disabled for this runtime, test will be skipped.")
|
|
|
+
|
|
|
@pytest.fixture
|
|
|
def runtime_type(self):
|
|
|
"""
|
|
@@ -243,14 +256,14 @@ class TestTIAFPythonUnitTests():
|
|
|
|
|
|
#@pytest.mark.skip(reason="To fix before PR")
|
|
|
@pytest.mark.parametrize("bucket_name,top_level_dir,expected_top_level_dir", [("test_bucket", "test_dir", "test_dir/python")])
|
|
|
- def test_create_PythonTestImpact_correct_s3_dir_runtime_type(self, config_data, caplog, tiaf_args, mock_runtime, mocker, bucket_name, top_level_dir, expected_top_level_dir, storage_config):
|
|
|
+ def test_create_PythonTestImpact_correct_s3_dir_runtime_type(self, config_data, caplog, tiaf_args, skip_if_test_targets_disabled, mock_runtime, mocker, bucket_name, top_level_dir, expected_top_level_dir, storage_config):
|
|
|
# given:
|
|
|
# Default args + s3_bucket and s3_top_level_dir set
|
|
|
tiaf_args['s3_bucket'] = bucket_name
|
|
|
tiaf_args['s3_top_level_dir'] = top_level_dir
|
|
|
mock_storage = mocker.patch(
|
|
|
"persistent_storage.PersistentStorageS3.__init__", side_effect=SystemError())
|
|
|
- expected_storage_args = config_data, tiaf_args['suite'], tiaf_args[
|
|
|
+ expected_storage_args = config_data, tiaf_args['suites'], tiaf_args[
|
|
|
'commit'], bucket_name, expected_top_level_dir, tiaf_args['src_branch'], storage_config['active_workspace'], storage_config['unpacked_coverage_data_file'], storage_config['previous_test_run_data_file'], storage_config['temp_workspace']
|
|
|
|
|
|
# when:
|
|
@@ -258,7 +271,7 @@ class TestTIAFPythonUnitTests():
|
|
|
tiaf = PythonTestImpact(tiaf_args)
|
|
|
|
|
|
# then:
|
|
|
- # PersistentStorageS3.__init__ should be called with config data, suite, commit, bucket_name, modified top level dir and src_branch as arguments
|
|
|
+ # PersistentStorageS3.__init__ should be called with config data, suites, commit, bucket_name, modified top level dir and src_branch as arguments
|
|
|
mock_storage.assert_called_with(*expected_storage_args)
|
|
|
|
|
|
|
|
@@ -271,10 +284,11 @@ class TestTIAFBaseUnitTests():
|
|
|
"""
|
|
|
return "native"
|
|
|
|
|
|
- def test_create_TestImpact_valid_config(self, caplog, tiaf_args, mock_runtime, mocker, default_runtime_args):
|
|
|
+ def test_create_TestImpact_valid_config(self, caplog, tiaf_args, skip_if_test_targets_disabled, mock_runtime, mocker, default_runtime_args):
|
|
|
"""
|
|
|
Given default arguments, when we create a TestImpact object, tiaf.runtime_args should be eqaul
|
|
|
"""
|
|
|
+
|
|
|
# given:
|
|
|
# Default arguments.
|
|
|
|
|
@@ -287,7 +301,7 @@ class TestTIAFBaseUnitTests():
|
|
|
assert_list_content_equal(
|
|
|
tiaf.runtime_args, default_runtime_args.values())
|
|
|
|
|
|
- def test_create_TestImpact_invalid_config(self, caplog, tiaf_args, mock_runtime, tmp_path_factory, default_runtime_args):
|
|
|
+ def test_create_TestImpact_invalid_config(self, caplog, tiaf_args, skip_if_test_targets_disabled, mock_runtime, tmp_path_factory, default_runtime_args):
|
|
|
# given:
|
|
|
# Invalid config file at invalid_file,
|
|
|
# and setting tiaf_args.config to that path.
|
|
@@ -304,7 +318,7 @@ class TestTIAFBaseUnitTests():
|
|
|
tiaf = ConcreteBaseTestImpact(tiaf_args)
|
|
|
|
|
|
@ pytest.mark.parametrize("branch_name", ["development", "not_a_real_branch"])
|
|
|
- def test_create_TestImpact_src_branch(self, caplog, tiaf_args, mock_runtime, default_runtime_args, branch_name):
|
|
|
+ def test_create_TestImpact_src_branch(self, caplog, tiaf_args, skip_if_test_targets_disabled, mock_runtime, default_runtime_args, branch_name):
|
|
|
# given:
|
|
|
# Default args + src_branch set to branch_name.
|
|
|
tiaf_args['src_branch'] = branch_name
|
|
@@ -318,7 +332,7 @@ class TestTIAFBaseUnitTests():
|
|
|
assert tiaf.source_branch == branch_name
|
|
|
|
|
|
@ pytest.mark.parametrize("branch_name", ["development", "not_a_real_branch"])
|
|
|
- def test_create_TestImpact_dst_branch(self, caplog, tiaf_args, mock_runtime, default_runtime_args, branch_name):
|
|
|
+ def test_create_TestImpact_dst_branch(self, caplog, tiaf_args, skip_if_test_targets_disabled, mock_runtime, default_runtime_args, branch_name):
|
|
|
# given:
|
|
|
# Default args + dst_branch set to branch_name.
|
|
|
tiaf_args['dst_branch'] = branch_name
|
|
@@ -332,7 +346,7 @@ class TestTIAFBaseUnitTests():
|
|
|
assert tiaf.destination_branch == branch_name
|
|
|
|
|
|
@ pytest.mark.parametrize("commit", ["9a15f038807ba8b987c9e689952d9271ef7fd086", "foobar"])
|
|
|
- def test_create_TestImpact_commit(self, caplog, tiaf_args, mock_runtime, default_runtime_args, commit):
|
|
|
+ def test_create_TestImpact_commit(self, caplog, tiaf_args, skip_if_test_targets_disabled, mock_runtime, default_runtime_args, commit):
|
|
|
# given:
|
|
|
# Default args + commit set to commit.
|
|
|
tiaf_args['commit'] = commit
|
|
@@ -345,7 +359,7 @@ class TestTIAFBaseUnitTests():
|
|
|
# tiaf.destination_commit should equal our commit parameter.
|
|
|
assert tiaf.destination_commit == commit
|
|
|
|
|
|
- def test_create_TestImpact_valid_test_suite_name(self, caplog, tiaf_args, mock_runtime, default_runtime_args):
|
|
|
+ def test_create_TestImpact_valid_test_suite_name(self, caplog, tiaf_args, skip_if_test_targets_disabled, mock_runtime, default_runtime_args):
|
|
|
# given:
|
|
|
# Default args
|
|
|
|
|
@@ -358,11 +372,11 @@ class TestTIAFBaseUnitTests():
|
|
|
assert_list_content_equal(
|
|
|
tiaf.runtime_args, default_runtime_args.values())
|
|
|
|
|
|
- def test_create_TestImpact_invalid_test_suite_name(self, caplog, tiaf_args, mock_runtime, default_runtime_args):
|
|
|
+ def test_create_TestImpact_invalid_test_suite_name(self, caplog, tiaf_args, skip_if_test_targets_disabled, mock_runtime, default_runtime_args):
|
|
|
# given:
|
|
|
- # Default args + suite defined as "foobar" in given args and expected args.
|
|
|
- tiaf_args['suite'] = "foobar"
|
|
|
- default_runtime_args['suite'] = "--suite=foobar"
|
|
|
+ # Default args + suites defined as "foobar" in given args and expected args.
|
|
|
+ tiaf_args['suites'] = "foobar"
|
|
|
+ default_runtime_args['suites'] = "--suites=foobar"
|
|
|
|
|
|
# when:
|
|
|
# We create a TestImpact object.
|
|
@@ -374,7 +388,7 @@ class TestTIAFBaseUnitTests():
|
|
|
tiaf.runtime_args, default_runtime_args.values())
|
|
|
|
|
|
@ pytest.mark.parametrize("policy", ["continue", "abort", "ignore"])
|
|
|
- def test_create_TestImpact_valid_failure_policy(self, caplog, tiaf_args, mock_runtime, default_runtime_args, policy):
|
|
|
+ def test_create_TestImpact_valid_failure_policy(self, caplog, tiaf_args, skip_if_test_targets_disabled, mock_runtime, default_runtime_args, policy):
|
|
|
# given:
|
|
|
# Default args + test_failure_policy set to policy parameter.
|
|
|
tiaf_args['test_failure_policy'] = policy
|
|
@@ -394,7 +408,7 @@ class TestTIAFBaseUnitTests():
|
|
|
assert_list_content_equal(
|
|
|
tiaf.runtime_args, default_runtime_args.values())
|
|
|
|
|
|
- def test_create_TestImpact_exclude_file_not_supplied(self, caplog, tiaf_args, mock_runtime, default_runtime_args):
|
|
|
+ def test_create_TestImpact_exclude_file_not_supplied(self, caplog, tiaf_args, skip_if_test_targets_disabled, mock_runtime, default_runtime_args):
|
|
|
# given:
|
|
|
# Default args.
|
|
|
|
|
@@ -407,7 +421,7 @@ class TestTIAFBaseUnitTests():
|
|
|
assert_list_content_equal(
|
|
|
tiaf.runtime_args, default_runtime_args.values())
|
|
|
|
|
|
- def test_create_TestImpact_exclude_file_supplied(self, caplog, tiaf_args, mock_runtime, default_runtime_args):
|
|
|
+ def test_create_TestImpact_exclude_file_supplied(self, caplog, tiaf_args, skip_if_test_targets_disabled, mock_runtime, default_runtime_args):
|
|
|
# given:
|
|
|
# Default args + exclude_file set.
|
|
|
tiaf_args['exclude_file'] = "testpath"
|