-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1ec9771
commit 9062071
Showing
7 changed files
with
61 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1 @@ | ||
"""Init dbt_score package.""" | ||
|
||
import os | ||
from pathlib import Path | ||
|
||
MANIFEST_PATH = ( | ||
Path() | ||
/ os.getenv("DBT_PROJECT_DIR", "") | ||
/ os.getenv("DBT_TARGET_DIR", "target") | ||
/ "manifest.json" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
"""Lint dbt models metadata.""" | ||
|
||
import logging | ||
from pathlib import Path | ||
|
||
from dbt_score.dbt_utils import dbt_parse | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def lint_manifest(manifest_path: Path) -> None: | ||
"""Lint dbt manifest.""" | ||
if not manifest_path.exists(): | ||
logger.info("Executing dbt parse.") | ||
dbt_parse() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,31 @@ | ||
"""Test the CLI.""" | ||
|
||
from pathlib import Path | ||
from unittest.mock import patch | ||
|
||
from click.testing import CliRunner | ||
from dbt_score.cli import lint | ||
|
||
|
||
@patch("dbt_score.cli.dbt_parse") | ||
def test_parse(dbt_parse, manifest_path): | ||
@patch("dbt_score.lint.dbt_parse") | ||
def test_parse_not_called(dbt_parse, manifest_path): | ||
"""Test to ensure dbt parse is not called when the manifest exists.""" | ||
with patch("dbt_score.cli.MANIFEST_PATH", manifest_path): | ||
runner = CliRunner() | ||
runner = CliRunner() | ||
with patch("dbt_score.cli.get_manifest_path", return_value=manifest_path): | ||
result1 = runner.invoke(lint) | ||
result2 = runner.invoke(lint, ["--manifest", manifest_path]) | ||
result2 = runner.invoke(lint, ["--manifest", manifest_path]) | ||
|
||
assert result1.exit_code == 0 | ||
assert result2.exit_code == 0 | ||
dbt_parse.assert_not_called() | ||
|
||
|
||
@patch("dbt_score.lint.dbt_parse") | ||
def test_parse_called(dbt_parse): | ||
"""Test to ensure dbt parse is called when the manifest does not exist.""" | ||
runner = CliRunner() | ||
with patch( | ||
"dbt_score.cli.get_manifest_path", return_value=Path("fake_manifest.json") | ||
): | ||
runner.invoke(lint) | ||
|
||
assert result1.exit_code == 0 | ||
assert result2.exit_code == 0 | ||
dbt_parse.assert_not_called() | ||
dbt_parse.assert_called_once() |