Skip to content

Commit

Permalink
Missed PR fedback (#7642) (#7691)
Browse files Browse the repository at this point in the history
(cherry picked from commit df23f68)

Co-authored-by: Ian Knox <81931810+iknox-fa@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and iknox-fa authored May 24, 2023
1 parent 8887c0c commit a3e6a48
Showing 1 changed file with 34 additions and 6 deletions.
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

0 comments on commit a3e6a48

Please sign in to comment.