From 58a371f9d9fb1f6667bb0713c3e796492a5dcf16 Mon Sep 17 00:00:00 2001 From: Fran Lozano Date: Sun, 8 Dec 2019 01:09:28 +0100 Subject: [PATCH 1/5] Fix #1733 --- core/dbt/task/debug.py | 2 +- test/integration/049_dbt_debug_test/test_debug.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/dbt/task/debug.py b/core/dbt/task/debug.py index 748de5a38be..35f259c6ee4 100644 --- a/core/dbt/task/debug.py +++ b/core/dbt/task/debug.py @@ -69,7 +69,7 @@ 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(os.getcwd(), 'dbt_project.yml') + self.project_path = os.path.join(args.project_dir or os.getcwd(), 'dbt_project.yml') self.cli_vars = dbt.utils.parse_cli_vars( getattr(self.args, 'vars', '{}') ) diff --git a/test/integration/049_dbt_debug_test/test_debug.py b/test/integration/049_dbt_debug_test/test_debug.py index bdd4639e5bc..d2493eae152 100644 --- a/test/integration/049_dbt_debug_test/test_debug.py +++ b/test/integration/049_dbt_debug_test/test_debug.py @@ -103,3 +103,12 @@ def test_postgres_badproject(self): self.assertIn('ERROR invalid', line) elif line.strip().startswith('profiles.yml file'): self.assertNotIn('ERROR invalid', line) + + @use_profile('postgres') + def test_postgres_invalid_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) \ No newline at end of file From c1b3690671c797b31b019bd1c23c17af644e134e Mon Sep 17 00:00:00 2001 From: Fran Lozano Date: Sat, 21 Dec 2019 14:06:01 +0100 Subject: [PATCH 2/5] Use --project-dir outside current dir in debug when it exists #1733 --- core/dbt/task/debug.py | 5 +++-- .../049_dbt_debug_test/test_debug.py | 21 +++++++++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/core/dbt/task/debug.py b/core/dbt/task/debug.py index 35f259c6ee4..3c1a9095634 100644 --- a/core/dbt/task/debug.py +++ b/core/dbt/task/debug.py @@ -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', '{}') ) @@ -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') diff --git a/test/integration/049_dbt_debug_test/test_debug.py b/test/integration/049_dbt_debug_test/test_debug.py index d2493eae152..95b4dbfd451 100644 --- a/test/integration/049_dbt_debug_test/test_debug.py +++ b/test/integration/049_dbt_debug_test/test_debug.py @@ -1,3 +1,5 @@ +import yaml + from test.integration.base import DBTIntegrationTest, use_profile import os import re @@ -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) \ No newline at end of file + 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) \ No newline at end of file From 99e778b9b77b64395eb41c2439bfe3874bb64734 Mon Sep 17 00:00:00 2001 From: Fran Lozano Date: Sat, 21 Dec 2019 14:19:27 +0100 Subject: [PATCH 3/5] Update order of imports in test_debug --- test/integration/049_dbt_debug_test/test_debug.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/integration/049_dbt_debug_test/test_debug.py b/test/integration/049_dbt_debug_test/test_debug.py index 95b4dbfd451..35724305fbe 100644 --- a/test/integration/049_dbt_debug_test/test_debug.py +++ b/test/integration/049_dbt_debug_test/test_debug.py @@ -1,8 +1,7 @@ -import yaml - from test.integration.base import DBTIntegrationTest, use_profile import os import re +import yaml import pytest From 1085fb8cf49c8ee7011c82752534a08e89161fc6 Mon Sep 17 00:00:00 2001 From: Fran Lozano Date: Tue, 7 Jan 2020 23:46:05 +0100 Subject: [PATCH 4/5] Split line too long --- core/dbt/task/debug.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/dbt/task/debug.py b/core/dbt/task/debug.py index 3c1a9095634..d40bf9f1533 100644 --- a/core/dbt/task/debug.py +++ b/core/dbt/task/debug.py @@ -126,7 +126,8 @@ def _load_project(self): return red('ERROR not found') try: - self.project = Project.from_project_root(self.project_dir, 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') From 94ede834624aeef0c04b18945cc0288818785579 Mon Sep 17 00:00:00 2001 From: Fran Lozano Date: Wed, 8 Jan 2020 00:01:26 +0100 Subject: [PATCH 5/5] Remove unnecessary call to use_default_project call from test --- test/integration/049_dbt_debug_test/test_debug.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/integration/049_dbt_debug_test/test_debug.py b/test/integration/049_dbt_debug_test/test_debug.py index 35724305fbe..c76b2e0f544 100644 --- a/test/integration/049_dbt_debug_test/test_debug.py +++ b/test/integration/049_dbt_debug_test/test_debug.py @@ -107,7 +107,6 @@ def test_postgres_badproject(self): @use_profile('postgres') 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: @@ -127,4 +126,4 @@ def test_postgres_invalid_project_outside_current_dir(self): splitout = self.capsys.readouterr().out.split('\n') for line in splitout: if line.strip().startswith('dbt_project.yml file'): - self.assertIn('ERROR invalid', line) \ No newline at end of file + self.assertIn('ERROR invalid', line)