Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missed PR feedback #7642

Merged
merged 3 commits into from
May 16, 2023
Merged
Changes from all commits
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
40 changes: 34 additions & 6 deletions tests/functional/dependencies/test_local_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from pathlib import Path
from unittest import mock
from contextlib import contextmanager

import dbt.semver
import dbt.config
Expand Down Expand Up @@ -82,6 +83,16 @@
"""


@contextmanager
def up_one():
current_path = Path.cwd()
os.chdir("../")
try:
yield
finally:
os.chdir(current_path)


class BaseDependencyTest(object):
@pytest.fixture(scope="class")
def macros(self):
Expand Down Expand Up @@ -152,16 +163,33 @@ def test_local_dependency(self, project):
[f"{project.test_schema}.dep_source_model", f"{project.test_schema}.seed"],
)

def test_no_dependency_paths(self, project):
run_dbt(["deps"])
run_dbt(["seed"])

# prove dependency does not exist as model in project
dep_path = os.path.join("models_local", "model_to_import.sql")
results = run_dbt(
["run", "--models", f"+{dep_path}"],
)
assert len(results) == 0

# prove model can run when importing that dependency
local_path = Path("models") / "my_model.sql"
results = run_dbt(
["run", "--models", f"+{local_path}"],
)
assert len(results) == 2


class TestSimpleDependencyRelativePath(BaseDependencyTest):
def test_local_dependency_relative_path(self, project):
last_dir = Path(project.project_root).name
os.chdir("../")
_, stdout = run_dbt_and_capture(["deps", "--project-dir", last_dir])
assert (
"Installed from <local @ local_dependency>" in stdout
), "Test output didn't contain expected string"
os.chdir(project.project_root)
with up_one():
_, stdout = run_dbt_and_capture(["deps", "--project-dir", last_dir])
assert (
"Installed from <local @ local_dependency>" in stdout
), "Test output didn't contain expected string"


class TestMissingDependency(object):
Expand Down