Skip to content

Commit

Permalink
use block-style comments per PR feedback
Browse files Browse the repository at this point in the history
Fix the tests
  • Loading branch information
Jacob Beck committed Oct 30, 2019
1 parent 38788aa commit e6daba3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 31 deletions.
8 changes: 1 addition & 7 deletions core/dbt/adapters/base/query_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,7 @@ def __init__(self, initial):
self.query_comment: str = initial

def add(self, sql: str) -> str:
# Make sure there are no trailing newlines.
# For every newline, add a comment after it in case query_comment
# is multiple lines.
# Then add a comment to the first line of the query comment, and
# put the sql on a fresh line.
comment_split = self.query_comment.strip().replace('\n', '\n-- ')
return '-- {}\n{}'.format(comment_split, sql)
return '/* {} */\n{}'.format(self.query_comment.strip(), sql)

def set(self, comment: str):
self.query_comment = comment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def project_config(self):

def matches_comment(self, msg) -> bool:
self.assertTrue(
msg.startswith('-- dbt\n-- rules!\n'),
msg.startswith('/* dbt\nrules! */\n'),
f'{msg} did not start with query comment'
)

Expand All @@ -102,10 +102,10 @@ def test_bigquery_comments(self):

class TestDefaultQueryComments(QueryComments):
def matches_comment(self, msg):
if not msg.startswith('-- '):
if not msg.startswith('/* '):
return False
# our blob is the first line of the query comments, minus the '-- '
json_str = msg.split('\n')[0][3:]
# our blob is the first line of the query comments, minus the comment
json_str = msg.split('\n')[0][3:-3]
data = json.loads(json_str)
self.assertEqual(data['app'], 'dbt')
self.assertEqual(data['dbt_version'], dbt_version)
Expand Down
6 changes: 0 additions & 6 deletions test/integration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,12 +324,9 @@ def setUp(self):
os.chdir(self.initial_dir)
# before we go anywhere, collect the initial path info
self._logs_dir = os.path.join(self.initial_dir, 'logs', self.prefix)
print('initial_dir={}'.format(self.initial_dir))
_really_makedirs(self._logs_dir)
self.test_original_source_path = _pytest_get_test_root()
print('test_original_source_path={}'.format(self.test_original_source_path))
self.test_root_dir = normalize(tempfile.mkdtemp(prefix='dbt-int-test-'))
print('test_root_dir={}'.format(self.test_root_dir))
os.chdir(self.test_root_dir)
try:
self._symlink_test_folders()
Expand Down Expand Up @@ -397,9 +394,6 @@ def set_packages(self):
with open('packages.yml', 'w') as f:
yaml.safe_dump(self.packages_config, f, default_flow_style=True)

def test_only_config(self):
return None

def load_config(self):
# we've written our profile and project. Now we want to instantiate a
# fresh adapter for the tests.
Expand Down
12 changes: 6 additions & 6 deletions test/unit/test_postgres_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def test_quoting_on_drop_schema(self):
self.adapter.drop_schema(database='postgres', schema='test_schema')

self.mock_execute.assert_has_calls([
mock.call('-- dbt\ndrop schema if exists "test_schema" cascade', None)
mock.call('/* dbt */\ndrop schema if exists "test_schema" cascade', None)
])

def test_quoting_on_drop(self):
Expand All @@ -265,7 +265,7 @@ def test_quoting_on_drop(self):
)
self.adapter.drop_relation(relation)
self.mock_execute.assert_has_calls([
mock.call('-- dbt\ndrop table if exists "postgres"."test_schema".test_table cascade', None)
mock.call('/* dbt */\ndrop table if exists "postgres"."test_schema".test_table cascade', None)
])

def test_quoting_on_truncate(self):
Expand All @@ -278,7 +278,7 @@ def test_quoting_on_truncate(self):
)
self.adapter.truncate_relation(relation)
self.mock_execute.assert_has_calls([
mock.call('-- dbt\ntruncate table "postgres"."test_schema".test_table', None)
mock.call('/* dbt */\ntruncate table "postgres"."test_schema".test_table', None)
])

def test_quoting_on_rename(self):
Expand All @@ -302,13 +302,13 @@ def test_quoting_on_rename(self):
to_relation=to_relation
)
self.mock_execute.assert_has_calls([
mock.call('-- dbt\nalter table "postgres"."test_schema".table_a rename to table_b', None)
mock.call('/* dbt */\nalter table "postgres"."test_schema".table_a rename to table_b', None)
])

def test_debug_connection_ok(self):
DebugTask.validate_connection(self.target_dict)
self.mock_execute.assert_has_calls([
mock.call('-- dbt\nselect 1 as id', None)
mock.call('/* dbt */\nselect 1 as id', None)
])

def test_debug_connection_fail_nopass(self):
Expand All @@ -321,6 +321,6 @@ def test_connection_fail_select(self):
with self.assertRaises(DbtConfigError):
DebugTask.validate_connection(self.target_dict)
self.mock_execute.assert_has_calls([
mock.call('-- dbt\nselect 1 as id', None)
mock.call('/* dbt */\nselect 1 as id', None)
])

16 changes: 8 additions & 8 deletions test/unit/test_snowflake_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_quoting_on_drop_schema(self):
)

self.mock_execute.assert_has_calls([
mock.call('-- dbt\ndrop schema if exists test_database."test_schema" cascade', None)
mock.call('/* dbt */\ndrop schema if exists test_database."test_schema" cascade', None)
])

def test_quoting_on_drop(self):
Expand All @@ -92,7 +92,7 @@ def test_quoting_on_drop(self):

self.mock_execute.assert_has_calls([
mock.call(
'-- dbt\ndrop table if exists test_database."test_schema".test_table cascade',
'/* dbt */\ndrop table if exists test_database."test_schema".test_table cascade',
None
)
])
Expand All @@ -108,7 +108,7 @@ def test_quoting_on_truncate(self):
self.adapter.truncate_relation(relation)

self.mock_execute.assert_has_calls([
mock.call('-- dbt\ntruncate table test_database."test_schema".test_table', None)
mock.call('/* dbt */\ntruncate table test_database."test_schema".test_table', None)
])

def test_quoting_on_rename(self):
Expand All @@ -133,7 +133,7 @@ def test_quoting_on_rename(self):
)
self.mock_execute.assert_has_calls([
mock.call(
'-- dbt\nalter table test_database."test_schema".table_a rename to test_database."test_schema".table_b',
'/* dbt */\nalter table test_database."test_schema".table_a rename to test_database."test_schema".table_b',
None
)
])
Expand All @@ -145,7 +145,7 @@ def current_warehouse(self, response):
execute_side_effect = self.mock_execute.side_effect

def execute_effect(sql, *args, **kwargs):
if sql == '-- dbt\nselect current_warehouse() as warehouse':
if sql == '/* dbt */\nselect current_warehouse() as warehouse':
self.cursor.description = [['name']]
self.cursor.fetchall.return_value = [[response]]
else:
Expand Down Expand Up @@ -180,12 +180,12 @@ def test_pre_post_hooks_warehouse(self):
result = self.adapter.pre_model_hook(config)
self.assertIsNotNone(result)
calls = [
mock.call('-- dbt\nselect current_warehouse() as warehouse', None),
mock.call('-- dbt\nuse warehouse other_warehouse', None)
mock.call('/* dbt */\nselect current_warehouse() as warehouse', None),
mock.call('/* dbt */\nuse warehouse other_warehouse', None)
]
self.mock_execute.assert_has_calls(calls)
self.adapter.post_model_hook(config, result)
calls.append(mock.call('-- dbt\nuse warehouse warehouse', None))
calls.append(mock.call('/* dbt */\nuse warehouse warehouse', None))
self.mock_execute.assert_has_calls(calls)

def test_pre_post_hooks_no_warehouse(self):
Expand Down

0 comments on commit e6daba3

Please sign in to comment.