Skip to content

Commit

Permalink
unit test unparsed version lt
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelleArk committed Sep 6, 2023
1 parent 874ee1c commit b6f9298
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
25 changes: 24 additions & 1 deletion tests/unit/test_contracts_graph_unparsed.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pickle
from datetime import timedelta
import pickle
import pytest

from dbt.contracts.graph.unparsed import (
UnparsedNode,
Expand Down Expand Up @@ -928,3 +929,25 @@ def test_bad_version_no_v(self):
version = self.get_ok_dict()
del version["v"]
self.assert_fails_validation(version)


@pytest.mark.parametrize(
"left,right,expected_lt",
[
# same types
(2, 12, True),
(12, 2, False),
("a", "b", True),
("b", "a", False),
# mismatched types - numeric
(2, 12.0, True),
(12.0, 2, False),
(2, "12", True),
("12", 2, False),
# mismatched types
(1, "test", True),
("test", 1, False),
],
)
def test_unparsed_version_lt(left, right, expected_lt):
assert (UnparsedVersion(left) < UnparsedVersion(right)) == expected_lt
22 changes: 22 additions & 0 deletions tests/unit/test_graph_selector_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,21 @@ def versioned_model_v3(seed):
)


@pytest.fixture
def versioned_model_v12_string(seed):
return make_model(
"pkg",
"versioned_model",
'select * from {{ ref("seed") }}',
config_kwargs={"materialized": "table"},
refs=[seed],
sources=[],
path="subdirectory/versioned_model_v12.sql",
version="12",
latest_version=2,
)


@pytest.fixture
def versioned_model_v4_nested_dir(seed):
return make_model(
Expand Down Expand Up @@ -732,6 +747,7 @@ def manifest(
versioned_model_v2,
versioned_model_v3,
versioned_model_v4_nested_dir,
versioned_model_v12_string,
ext_source_2,
ext_source_other,
ext_source_other_2,
Expand Down Expand Up @@ -760,6 +776,7 @@ def manifest(
versioned_model_v2,
versioned_model_v3,
versioned_model_v4_nested_dir,
versioned_model_v12_string,
ext_model,
table_id_unique,
table_id_not_null,
Expand Down Expand Up @@ -823,6 +840,7 @@ def test_select_fqn(manifest):
"versioned_model.v2",
"versioned_model.v3",
"versioned_model.v4",
"versioned_model.v12",
"table_model",
"table_model_py",
"table_model_csv",
Expand All @@ -840,6 +858,7 @@ def test_select_fqn(manifest):
"versioned_model.v2",
"versioned_model.v3",
"versioned_model.v4",
"versioned_model.v12",
}
assert search_manifest_using_method(manifest, method, "versioned_model.v1") == {
"versioned_model.v1"
Expand Down Expand Up @@ -1051,6 +1070,7 @@ def test_select_package(manifest):
"versioned_model.v2",
"versioned_model.v3",
"versioned_model.v4",
"versioned_model.v12",
"table_model",
"table_model_py",
"table_model_csv",
Expand Down Expand Up @@ -1103,6 +1123,7 @@ def test_select_config_materialized(manifest):
"versioned_model.v2",
"versioned_model.v3",
"versioned_model.v4",
"versioned_model.v12",
"mynamespace.union_model",
}

Expand Down Expand Up @@ -1189,6 +1210,7 @@ def test_select_version(manifest):
assert search_manifest_using_method(manifest, method, "prerelease") == {
"versioned_model.v3",
"versioned_model.v4",
"versioned_model.v12",
}
assert search_manifest_using_method(manifest, method, "none") == {
"table_model_py",
Expand Down

0 comments on commit b6f9298

Please sign in to comment.