Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add unit and integration tests for unmodified and old
  • Loading branch information
trouze committed Jun 3, 2023
commit ecb7d247fd3f5aff6445cf814a623122682f4306
76 changes: 75 additions & 1 deletion test/unit/test_graph_selector_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,6 @@ def test_select_state_no_change(manifest, previous_state):
method = statemethod(manifest, previous_state)
assert not search_manifest_using_method(manifest, method, "modified")
assert not search_manifest_using_method(manifest, method, "new")
assert not search_manifest_using_method(manifest, method, "new")
assert not search_manifest_using_method(manifest, method, "modified.configs")
assert not search_manifest_using_method(manifest, method, "modified.persisted_descriptions")
assert not search_manifest_using_method(manifest, method, "modified.relation")
Expand All @@ -1273,6 +1272,14 @@ def test_select_state_nothing(manifest, previous_state):
search_manifest_using_method(manifest, method, "new")
assert "no comparison manifest" in str(exc.value)

with pytest.raises(dbt.exceptions.DbtRuntimeError) as exc:
search_manifest_using_method(manifest, method, "unmodified")
assert "no comparison manifest" in str(exc.value)

with pytest.raises(dbt.exceptions.DbtRuntimeError) as exc:
search_manifest_using_method(manifest, method, "old")
assert "no comparison manifest" in str(exc.value)


def test_select_state_added_model(manifest, previous_state):
add_node(manifest, make_model("pkg", "another_model", "select 1 as id"))
Expand All @@ -1281,6 +1288,10 @@ def test_select_state_added_model(manifest, previous_state):
assert search_manifest_using_method(manifest, method, "new") == {"another_model"}
assert search_manifest_using_method(manifest, method, "modified.body") == {"another_model"}

# none of these
assert not {"another_model"} in search_manifest_using_method(manifest, method, "old")
assert not {"another_model"} in search_manifest_using_method(manifest, method, "unmodified")


def test_select_state_changed_model_sql(manifest, previous_state, view_model):
change_node(manifest, view_model.replace(raw_code="select 1 as id"))
Expand All @@ -1292,6 +1303,8 @@ def test_select_state_changed_model_sql(manifest, previous_state, view_model):

# none of these
assert not search_manifest_using_method(manifest, method, "new")
assert not {"view_model"} in search_manifest_using_method(manifest, method, "old")
assert not {"view_model"} in search_manifest_using_method(manifest, method, "unmodified")
assert not search_manifest_using_method(manifest, method, "modified.configs")
assert not search_manifest_using_method(manifest, method, "modified.persisted_descriptions")
assert not search_manifest_using_method(manifest, method, "modified.relation")
Expand All @@ -1306,19 +1319,28 @@ def test_select_state_changed_model_fqn(manifest, previous_state, view_model):
assert search_manifest_using_method(manifest, method, "modified") == {"view_model"}
assert not search_manifest_using_method(manifest, method, "new")

# none of these
assert not {"view_model"} in search_manifest_using_method(manifest, method, "old")
assert not {"view_model"} in search_manifest_using_method(manifest, method, "unmodified")


def test_select_state_added_seed(manifest, previous_state):
add_node(manifest, make_seed("pkg", "another_seed"))
method = statemethod(manifest, previous_state)
assert search_manifest_using_method(manifest, method, "modified") == {"another_seed"}
assert search_manifest_using_method(manifest, method, "new") == {"another_seed"}

# none of these
assert not {"another_seed"} in search_manifest_using_method(manifest, method, "old")
assert not {"another_seed"} in search_manifest_using_method(manifest, method, "unmodified")


def test_select_state_changed_seed_checksum_sha_to_sha(manifest, previous_state, seed):
change_node(manifest, seed.replace(checksum=FileHash.from_contents("changed")))
method = statemethod(manifest, previous_state)
assert search_manifest_using_method(manifest, method, "modified") == {"seed"}
assert not search_manifest_using_method(manifest, method, "new")
assert "seed" not in search_manifest_using_method(manifest, method, "unmodified")


def test_select_state_changed_seed_checksum_path_to_path(manifest, previous_state, seed):
Expand All @@ -1340,6 +1362,16 @@ def test_select_state_changed_seed_checksum_path_to_path(manifest, previous_stat
with mock.patch("dbt.contracts.graph.nodes.warn_or_error") as warn_or_error_patch:
assert not search_manifest_using_method(manifest, method, "new")
warn_or_error_patch.assert_not_called()
with mock.patch("dbt.contracts.graph.nodes.warn_or_error") as warn_or_error_patch:
assert search_manifest_using_method(manifest, method, "old")
warn_or_error_patch.assert_not_called()
with mock.patch("dbt.contracts.graph.nodes.warn_or_error") as warn_or_error_patch:
assert search_manifest_using_method(manifest, method, "unmodified")
warn_or_error_patch.assert_called_once()
event = warn_or_error_patch.call_args[0][0]
assert type(event).__name__ == "SeedExceedsLimitSamePath"
msg = event.message()
assert msg.startswith("Found a seed (pkg.seed) >1MB in size")


def test_select_state_changed_seed_checksum_sha_to_path(manifest, previous_state, seed):
Expand All @@ -1357,6 +1389,16 @@ def test_select_state_changed_seed_checksum_sha_to_path(manifest, previous_state
with mock.patch("dbt.contracts.graph.nodes.warn_or_error") as warn_or_error_patch:
assert not search_manifest_using_method(manifest, method, "new")
warn_or_error_patch.assert_not_called()
with mock.patch("dbt.contracts.graph.nodes.warn_or_error") as warn_or_error_patch:
assert search_manifest_using_method(manifest, method, "old")
warn_or_error_patch.assert_not_called()
with mock.patch("dbt.contracts.graph.nodes.warn_or_error") as warn_or_error_patch:
assert search_manifest_using_method(manifest, method, "unmodified")
warn_or_error_patch.assert_called_once()
event = warn_or_error_patch.call_args[0][0]
assert type(event).__name__ == "SeedIncreased"
msg = event.message()
assert msg.startswith("Found a seed (pkg.seed) >1MB in size")


def test_select_state_changed_seed_checksum_path_to_sha(manifest, previous_state, seed):
Expand All @@ -1371,13 +1413,21 @@ def test_select_state_changed_seed_checksum_path_to_sha(manifest, previous_state
with mock.patch("dbt.contracts.graph.nodes.warn_or_error") as warn_or_error_patch:
assert not search_manifest_using_method(manifest, method, "new")
warn_or_error_patch.assert_not_called()
with mock.patch("dbt.contracts.graph.nodes.warn_or_error") as warn_or_error_patch:
assert "seed" not in search_manifest_using_method(manifest, method, "unmodified")
warn_or_error_patch.assert_not_called()
with mock.patch("dbt.contracts.graph.nodes.warn_or_error") as warn_or_error_patch:
assert "seed" in search_manifest_using_method(manifest, method, "old")
warn_or_error_patch.assert_not_called()


def test_select_state_changed_seed_fqn(manifest, previous_state, seed):
change_node(manifest, seed.replace(fqn=seed.fqn[:-1] + ["nested"] + seed.fqn[-1:]))
method = statemethod(manifest, previous_state)
assert search_manifest_using_method(manifest, method, "modified") == {"seed"}
assert not search_manifest_using_method(manifest, method, "new")
assert "seed" not in search_manifest_using_method(manifest, method, "unmodified")
assert "seed" in search_manifest_using_method(manifest, method, "old")


def test_select_state_changed_seed_relation_documented(manifest, previous_state, seed):
Expand All @@ -1386,7 +1436,9 @@ def test_select_state_changed_seed_relation_documented(manifest, previous_state,
method = statemethod(manifest, previous_state)
assert search_manifest_using_method(manifest, method, "modified") == {"seed"}
assert search_manifest_using_method(manifest, method, "modified.configs") == {"seed"}
assert "seed" in search_manifest_using_method(manifest, method, "old")
assert not search_manifest_using_method(manifest, method, "new")
assert "seed" not in search_manifest_using_method(manifest, method, "unmodified")
assert not search_manifest_using_method(manifest, method, "modified.body")
assert not search_manifest_using_method(manifest, method, "modified.persisted_descriptions")

Expand All @@ -1401,7 +1453,9 @@ def test_select_state_changed_seed_relation_documented_nodocs(manifest, previous
assert search_manifest_using_method(manifest, method, "modified.persisted_descriptions") == {
"seed"
}
assert "seed" in search_manifest_using_method(manifest, method, "old")
assert not search_manifest_using_method(manifest, method, "new")
assert "seed" not in search_manifest_using_method(manifest, method, "unmodified")
assert not search_manifest_using_method(manifest, method, "modified.configs")


Expand All @@ -1415,7 +1469,9 @@ def test_select_state_changed_seed_relation_documented_withdocs(manifest, previo
assert search_manifest_using_method(manifest, method, "modified.persisted_descriptions") == {
"seed"
}
assert "seed" in search_manifest_using_method(manifest, method, "old")
assert not search_manifest_using_method(manifest, method, "new")
assert "seed" not in search_manifest_using_method(manifest, method, "unmodified")


def test_select_state_changed_seed_columns_documented(manifest, previous_state, seed):
Expand All @@ -1425,7 +1481,9 @@ def test_select_state_changed_seed_columns_documented(manifest, previous_state,
method = statemethod(manifest, previous_state)
assert search_manifest_using_method(manifest, method, "modified") == {"seed"}
assert search_manifest_using_method(manifest, method, "modified.configs") == {"seed"}
assert "seed" in search_manifest_using_method(manifest, method, "old")
assert not search_manifest_using_method(manifest, method, "new")
assert "seed" not in search_manifest_using_method(manifest, method, "unmodified")
assert not search_manifest_using_method(manifest, method, "modified.persisted_descriptions")


Expand All @@ -1443,7 +1501,9 @@ def test_select_state_changed_seed_columns_documented_nodocs(manifest, previous_
assert search_manifest_using_method(manifest, method, "modified.persisted_descriptions") == {
"seed"
}
assert "seed" in search_manifest_using_method(manifest, method, "old")
assert not search_manifest_using_method(manifest, method, "new")
assert "seed" not in search_manifest_using_method(manifest, method, "unmodified")
assert not search_manifest_using_method(manifest, method, "modified.configs")


Expand All @@ -1461,7 +1521,9 @@ def test_select_state_changed_seed_columns_documented_withdocs(manifest, previou
assert search_manifest_using_method(manifest, method, "modified.persisted_descriptions") == {
"seed"
}
assert "seed" in search_manifest_using_method(manifest, method, "old")
assert not search_manifest_using_method(manifest, method, "new")
assert "seed" not in search_manifest_using_method(manifest, method, "unmodified")
assert not search_manifest_using_method(manifest, method, "modified.configs")


Expand All @@ -1478,7 +1540,11 @@ def test_select_state_changed_test_macro_sql(
assert search_manifest_using_method(manifest, method, "modified.macros") == {
"not_null_table_model_id"
}
assert "not_null_table_model_id" in search_manifest_using_method(manifest, method, "old")
assert not search_manifest_using_method(manifest, method, "new")
assert "not_null_table_model_id" not in search_manifest_using_method(
manifest, method, "unmodified"
)


def test_select_state_changed_test_macros(manifest, previous_state):
Expand Down Expand Up @@ -1515,7 +1581,11 @@ def test_select_state_changed_test_macros(manifest, previous_state):
"model1",
"model2",
}
assert "model1" and "model2" in search_manifest_using_method(manifest, method, "old")
assert not search_manifest_using_method(manifest, method, "new")
assert "model1" and "model2" not in search_manifest_using_method(
manifest, method, "unmodified"
)


def test_select_state_changed_test_macros_with_upstream_change(manifest, previous_state):
Expand Down Expand Up @@ -1564,4 +1634,8 @@ def test_select_state_changed_test_macros_with_upstream_change(manifest, previou
"model1",
"model2",
}
assert "model1" and "model2" in search_manifest_using_method(manifest, method, "old")
assert not search_manifest_using_method(manifest, method, "new")
assert "model1" and "model2" not in search_manifest_using_method(
manifest, method, "unmodified"
)
Loading