diff --git a/tests/unit/contracts/graph/test_manifest.py b/tests/unit/contracts/graph/test_manifest.py index 7f53951bdeb..ba503acc85a 100644 --- a/tests/unit/contracts/graph/test_manifest.py +++ b/tests/unit/contracts/graph/test_manifest.py @@ -50,6 +50,7 @@ MockNode, MockSource, inject_plugin, + make_manifest, ) REQUIRED_PARSED_NODE_KEYS = frozenset( @@ -1090,20 +1091,6 @@ def setUp(self): ) -def make_manifest(nodes=[], sources=[], macros=[], docs=[]): - return Manifest( - nodes={n.unique_id: n for n in nodes}, - macros={m.unique_id: m for m in macros}, - sources={s.unique_id: s for s in sources}, - docs={d.unique_id: d for d in docs}, - disabled={}, - files={}, - exposures={}, - metrics={}, - selectors={}, - ) - - FindMacroSpec = namedtuple("FindMacroSpec", "macros,expected") macro_parameter_sets = [ diff --git a/tests/unit/graph/test_queue.py b/tests/unit/graph/test_queue.py new file mode 100644 index 00000000000..50671d03fb2 --- /dev/null +++ b/tests/unit/graph/test_queue.py @@ -0,0 +1,47 @@ +import networkx as nx +import pytest + +from dbt.contracts.graph.manifest import Manifest +from dbt.graph.queue import GraphQueue +from tests.unit.utils import MockNode, make_manifest + + +class TestGraphQueue: + @pytest.fixture(scope="class") + def manifest(self) -> Manifest: + return make_manifest( + nodes=[ + MockNode(package="test_package", name="upstream_model"), + MockNode(package="test_package", name="downstream_model"), + ] + ) + + @pytest.fixture(scope="class") + def graph(self) -> nx.DiGraph: + graph = nx.DiGraph() + graph.add_edge("model.test_package.upstream_model", "model.test_package.downstream_model") + return graph + + def test_init_graph_queue(self, manifest, graph): + graph_queue = GraphQueue(graph=graph, manifest=manifest, selected={}) + + assert graph_queue.manifest == manifest + assert graph_queue.graph == graph + assert graph_queue.inner.queue == [(0, "model.test_package.upstream_model")] + assert graph_queue.in_progress == set() + assert graph_queue.queued == {"model.test_package.upstream_model"} + assert graph_queue.lock + + def test_init_graph_queue_preserve_edges_false(self, manifest, graph): + graph_queue = GraphQueue(graph=graph, manifest=manifest, selected={}, preserve_edges=False) + + # when preserve_edges is set to false, dependencies between nodes are no longer tracked in the priority queue + assert list(graph_queue.graph.edges) == [] + assert graph_queue.inner.queue == [ + (0, "model.test_package.downstream_model"), + (0, "model.test_package.upstream_model"), + ] + assert graph_queue.queued == { + "model.test_package.upstream_model", + "model.test_package.downstream_model", + } diff --git a/tests/unit/utils/__init__.py b/tests/unit/utils/__init__.py index 7df68c949cc..411ad6ae756 100644 --- a/tests/unit/utils/__init__.py +++ b/tests/unit/utils/__init__.py @@ -11,6 +11,7 @@ import pytest from dbt.config.project import PartialProject +from dbt.contracts.graph.manifest import Manifest from dbt_common.dataclass_schema import ValidationError @@ -387,3 +388,17 @@ def replace_config(n, **kwargs): config=n.config.replace(**kwargs), unrendered_config=dict_replace(n.unrendered_config, **kwargs), ) + + +def make_manifest(nodes=[], sources=[], macros=[], docs=[]) -> Manifest: + return Manifest( + nodes={n.unique_id: n for n in nodes}, + macros={m.unique_id: m for m in macros}, + sources={s.unique_id: s for s in sources}, + docs={d.unique_id: d for d in docs}, + disabled={}, + files={}, + exposures={}, + metrics={}, + selectors={}, + )