Skip to content

Commit

Permalink
Initial commit with updated breaking test case
Browse files Browse the repository at this point in the history
  • Loading branch information
aranke committed Sep 5, 2023
1 parent 7eedfcd commit 64525bc
Showing 1 changed file with 46 additions and 45 deletions.
91 changes: 46 additions & 45 deletions tests/functional/artifacts/test_previous_version_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -292,63 +335,21 @@ 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 (
current_schema_version == self.CURRENT_EXPECTED_MANIFEST_VERSION
), "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)

0 comments on commit 64525bc

Please sign in to comment.