Skip to content

Commit

Permalink
bugfix: ignore commented-out schema tests (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmcarthur authored Mar 15, 2017
1 parent 26bddd3 commit a817c9f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fix ephemeral load order bug ([#292](https://github.com/fishtown-analytics/dbt/pull/292), [#285](https://github.com/fishtown-analytics/dbt/pull/285))
- Fix target paths ([#331](https://github.com/fishtown-analytics/dbt/pull/331), [#329](https://github.com/fishtown-analytics/dbt/issues/329))
- Ignore commented-out schema tests ([#330](https://github.com/fishtown-analytics/dbt/pull/330), [#328](https://github.com/fishtown-analytics/dbt/issues/328))

### Changes

Expand Down
9 changes: 8 additions & 1 deletion dbt/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,17 @@ def parse_schema_tests(tests, root_project, projects):
for test in tests:
test_yml = yaml.safe_load(test.get('raw_yml'))

# validate schema test yml structure
if test_yml is None:
continue

for model_name, test_spec in test_yml.items():
if test_spec is None or test_spec.get('constraints') is None:
continue

for test_type, configs in test_spec.get('constraints', {}).items():
if configs is None:
continue

for config in configs:
to_add = parse_schema_test(
test, model_name, config, test_type,
Expand Down
47 changes: 47 additions & 0 deletions test/unit/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,53 @@ def test__simple_schema_test(self):
}
)

def test__schema_test_with_comments(self):
tests = [{
'name': 'commented_test',
'resource_type': 'test',
'package_name': 'root',
'root_path': get_os_path('/usr/src/app'),
'path': 'commented_test.yml',
'raw_sql': None,
'raw_yml': '''
model:
constraints:
relationships:
# - {from: customer_id, to: accounts, field: id}
another_model:
constraints:
# unique:
# - id
'''
}]

self.assertEquals(
dbt.parser.parse_schema_tests(
tests,
self.root_project_config,
{'root': self.root_project_config,
'snowplow': self.snowplow_project_config}),
{})

def test__empty_schema_test(self):
tests = [{
'name': 'commented_test',
'resource_type': 'test',
'package_name': 'root',
'root_path': get_os_path('/usr/src/app'),
'path': 'commented_test.yml',
'raw_sql': None,
'raw_yml': ''
}]

self.assertEquals(
dbt.parser.parse_schema_tests(
tests,
self.root_project_config,
{'root': self.root_project_config,
'snowplow': self.snowplow_project_config}),
{})

def test__simple_data_test(self):
tests = [{
Expand Down

0 comments on commit a817c9f

Please sign in to comment.