Skip to content

Commit

Permalink
Use --project-dir outside current dir in debug when it exists dbt-lab…
Browse files Browse the repository at this point in the history
  • Loading branch information
Fran Lozano committed Dec 21, 2019
1 parent 58a371f commit c1b3690
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
5 changes: 3 additions & 2 deletions core/dbt/task/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ def __init__(self, args, config):
self.profiles_dir = getattr(self.args, 'profiles_dir',
dbt.config.PROFILES_DIR)
self.profile_path = os.path.join(self.profiles_dir, 'profiles.yml')
self.project_path = os.path.join(args.project_dir or os.getcwd(), 'dbt_project.yml')
self.project_dir = args.project_dir or os.getcwd()
self.project_path = os.path.join(self.project_dir, 'dbt_project.yml')
self.cli_vars = dbt.utils.parse_cli_vars(
getattr(self.args, 'vars', '{}')
)
Expand Down Expand Up @@ -125,7 +126,7 @@ def _load_project(self):
return red('ERROR not found')

try:
self.project = Project.from_current_directory(self.cli_vars)
self.project = Project.from_project_root(self.project_dir, self.cli_vars)
except dbt.exceptions.DbtConfigError as exc:
self.project_fail_details = str(exc)
return red('ERROR invalid')
Expand Down
21 changes: 19 additions & 2 deletions test/integration/049_dbt_debug_test/test_debug.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import yaml

from test.integration.base import DBTIntegrationTest, use_profile
import os
import re
Expand Down Expand Up @@ -105,10 +107,25 @@ def test_postgres_badproject(self):
self.assertNotIn('ERROR invalid', line)

@use_profile('postgres')
def test_postgres_invalid_project_dir(self):
def test_postgres_not_found_project_dir(self):
self.use_default_project()
self.run_dbt(['debug', '--project-dir', 'nopass'])
splitout = self.capsys.readouterr().out.split('\n')
for line in splitout:
if line.strip().startswith('dbt_project.yml file'):
self.assertIn('ERROR not found', line)
self.assertIn('ERROR not found', line)

@use_profile('postgres')
def test_postgres_invalid_project_outside_current_dir(self):
# create a dbt_project.yml
project_config = {
'invalid-key': 'not a valid key in this project'
}
os.makedirs('custom', exist_ok=True)
with open("custom/dbt_project.yml", 'w') as f:
yaml.safe_dump(project_config, f, default_flow_style=True)
self.run_dbt(['debug', '--project-dir', 'custom'])
splitout = self.capsys.readouterr().out.split('\n')
for line in splitout:
if line.strip().startswith('dbt_project.yml file'):
self.assertIn('ERROR invalid', line)

0 comments on commit c1b3690

Please sign in to comment.