From 64525bccebd9cde45c67d5ab7185c5f0a615f897 Mon Sep 17 00:00:00 2001 From: Kshitij Aranke Date: Tue, 5 Sep 2023 14:05:34 +0100 Subject: [PATCH] Initial commit with updated breaking test case --- .../artifacts/test_previous_version_state.py | 91 ++++++++++--------- 1 file changed, 46 insertions(+), 45 deletions(-) diff --git a/tests/functional/artifacts/test_previous_version_state.py b/tests/functional/artifacts/test_previous_version_state.py index 5a15040bae1..8ba1cbd9b6c 100644 --- a/tests/functional/artifacts/test_previous_version_state.py +++ b/tests/functional/artifacts/test_previous_version_state.py @@ -228,6 +228,49 @@ # plus disabled versions for types that support it (everything except macros and docs). +# The actual test method. Run `dbt list --select state:modified --state ...` +# once for each past manifest version. They all have the same content, but different +# schema/structure, only some of which are forward-compatible with the +# current WritableManifest class. +def compare_previous_state( + project, + compare_manifest_version, + expect_pass, + num_results, +): + for resource_type in ["model", "metric"]: + state_path = os.path.join(project.test_data_dir, f"state/v{compare_manifest_version}") + cli_args = [ + "list", + "--select", + f"state:modified,resource_type:{resource_type}", + "--indirect-selection", + "empty", + "--state", + state_path, + ] + if expect_pass: + results = run_dbt(cli_args, expect_pass=expect_pass) + assert len(results) == num_results + else: + with pytest.raises(IncompatibleSchemaError): + run_dbt(cli_args, expect_pass=expect_pass) + + +# Use this method when generating a new manifest version for the first time. +# Once generated, we shouldn't need to re-generate or modify the manifest. +def generate_latest_manifest( + project, + current_manifest_version, +): + run_dbt(["list"]) + source_path = os.path.join(project.project_root, "target/manifest.json") + state_path = os.path.join(project.test_data_dir, f"state/v{current_manifest_version}") + target_path = os.path.join(state_path, "manifest.json") + os.makedirs(state_path, exist_ok=True) + shutil.copyfile(source_path, target_path) + + class TestPreviousVersionState: CURRENT_EXPECTED_MANIFEST_VERSION = 11 @@ -292,48 +335,6 @@ def test_project(self, project): assert len(manifest.disabled) == 9 assert "macro.test.do_nothing" in manifest.macros - # Use this method when generating a new manifest version for the first time. - # Once generated, we shouldn't need to re-generate or modify the manifest. - def generate_latest_manifest( - self, - project, - current_manifest_version, - ): - run_dbt(["list"]) - source_path = os.path.join(project.project_root, "target/manifest.json") - state_path = os.path.join(project.test_data_dir, f"state/v{current_manifest_version}") - target_path = os.path.join(state_path, "manifest.json") - os.makedirs(state_path, exist_ok=True) - shutil.copyfile(source_path, target_path) - - # The actual test method. Run `dbt list --select state:modified --state ...` - # once for each past manifest version. They all have the same content, but different - # schema/structure, only some of which are forward-compatible with the - # current WritableManifest class. - def compare_previous_state( - self, - project, - compare_manifest_version, - expect_pass, - num_results, - ): - state_path = os.path.join(project.test_data_dir, f"state/v{compare_manifest_version}") - cli_args = [ - "list", - "--resource-types", - "model", - "--select", - "state:modified", - "--state", - state_path, - ] - if expect_pass: - results = run_dbt(cli_args, expect_pass=expect_pass) - assert len(results) == num_results - else: - with pytest.raises(IncompatibleSchemaError): - run_dbt(cli_args, expect_pass=expect_pass) - def test_compare_state_current(self, project): current_schema_version = WritableManifest.dbt_schema_version.version assert ( @@ -341,14 +342,14 @@ def test_compare_state_current(self, project): ), "Sounds like you've bumped the manifest version and need to update this test!" # If we need a newly generated manifest, uncomment the following line and commit the result # self.generate_latest_manifest(project, current_schema_version) - self.compare_previous_state(project, current_schema_version, True, 0) + compare_previous_state(project, current_schema_version, True, 0) def test_backwards_compatible_versions(self, project): # manifest schema version 4 and greater should always be forward compatible for schema_version in range(4, self.CURRENT_EXPECTED_MANIFEST_VERSION): - self.compare_previous_state(project, schema_version, True, 1) + compare_previous_state(project, schema_version, True, 1) def test_nonbackwards_compatible_versions(self, project): # schema versions 1, 2, 3 are all not forward compatible for schema_version in range(1, 4): - self.compare_previous_state(project, schema_version, False, 0) + compare_previous_state(project, schema_version, False, 0)