Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed error_id typo and added associated tests #4070

Merged
merged 2 commits into from
Oct 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
- Fix multiple disabled nodes ([#4013](https://github.com/dbt-labs/dbt/issues/4013), [#4018](https://github.com/dbt-labs/dbt/pull/4018))
- Fix multiple partial parsing errors ([#3996](https://github.com/dbt-labs/dbt/issues/3006), [#4020](https://github.com/dbt-labs/dbt/pull/4018))
- Return an error instead of a warning when runing with `--warn-error` and no models are selected ([#4006](https://github.com/dbt-labs/dbt/issues/4006), [#4019](https://github.com/dbt-labs/dbt/pull/4019))
- Fixed bug with `error_if` test option ([#4070](https://github.com/dbt-labs/dbt-core/pull/4070))

### Under the hood

Expand Down
4 changes: 1 addition & 3 deletions core/dbt/parser/generic_test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def get_static_config(self):
if self.warn_if is not None:
config['warn_if'] = self.warn_if
if self.error_if is not None:
config['error_id'] = self.error_if
config['error_if'] = self.error_if
if self.fail_calc is not None:
config['fail_calc'] = self.fail_calc
if self.store_failures is not None:
Expand All @@ -369,8 +369,6 @@ def get_static_config(self):
config['database'] = self.database
if self.schema is not None:
config['schema'] = self.schema
if self.alias is not None:
config['alias'] = self.alias
return config

def tags(self) -> List[str]:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
version: 2

models:
- name: table_limit_null
description: "The table has 1 null values, and we're okay with that, until it's more than 1."
columns:
- name: favorite_color_full_list
description: "The favorite color"
- name: count
description: "The number of responses for this favorite color - purple will be null"
tests:
- not_null:
error_if: '>1'
warn_if: '>1'

- name: table_warning_limit_null
description: "The table has 1 null value, and we're okay with 1, but want to know of any."
columns:
- name: favorite_color_full_list
description: "The favorite color"
- name: count
description: "The number of responses for this favorite color - purple will be null"
tests:
- not_null:
error_if: '>1'

- name: table_failure_limit_null
description: "The table has some 2 null values, and that's not ok. Warn and error."
columns:
- name: favorite_color_full_list
description: "The favorite color"
- name: count
description: "The number of responses for this favorite color - purple will be null"
tests:
- not_null:
error_if: '>1'

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{
config(
materialized='table'
)
}}

select * from {{ref('table_limit_null')}}

UNION ALL

select 'magenta' as favorite_color_full_list, null as count
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{
config(
materialized='table'
)
}}

select favorite_color as favorite_color_full_list, count(*) as count
from {{ this.schema }}.seed
group by 1

UNION ALL

select 'purple' as favorite_color_full_list, null as count
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{{
config(
materialized='table'
)
}}

select * from {{ref('table_limit_null')}}
63 changes: 63 additions & 0 deletions test/integration/008_schema_tests_test/test_schema_v2_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,69 @@ def test_postgres_schema_test_exclude_failures(self):
for result in test_results:
self.assertTestFailed(result)

class TestLimitedSchemaTests(DBTIntegrationTest):

def setUp(self):
DBTIntegrationTest.setUp(self)
self.run_sql_file("seed.sql")

@property
def schema(self):
return "schema_tests_008"

@property
def models(self):
return "models-v2/limit_null"

def run_schema_validations(self):
args = FakeArgs()
test_task = TestTask(args, self.config)
return test_task.run()

def assertTestFailed(self, result):
self.assertEqual(result.status, "fail")
self.assertFalse(result.skipped)
self.assertTrue(
result.failures > 0,
'test {} did not fail'.format(result.node.name)
)

def assertTestWarn(self, result):
self.assertEqual(result.status, "warn")
self.assertFalse(result.skipped)
self.assertTrue(
result.failures > 0,
'test {} passed without expected warning'.format(result.node.name)
)

def assertTestPassed(self, result):
self.assertEqual(result.status, "pass")
self.assertFalse(result.skipped)
self.assertEqual(
result.failures, 0,
'test {} failed'.format(result.node.name)
)

@use_profile('postgres')
def test_postgres_limit_schema_tests(self):
results = self.run_dbt()
self.assertEqual(len(results), 3)
test_results = self.run_schema_validations()
self.assertEqual(len(test_results), 3)

for result in test_results:
# assert that all deliberately failing tests actually fail
if 'failure' in result.node.name:
self.assertTestFailed(result)
# assert that tests with warnings have them
elif 'warning' in result.node.name:
self.assertTestWarn(result)
# assert that actual tests pass
else:
self.assertTestPassed(result)
# warnings are also marked as failures
self.assertEqual(sum(x.failures for x in test_results), 3)


class TestMalformedSchemaTests(DBTIntegrationTest):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
class BaseTestDeprecations(DBTIntegrationTest):
def setUp(self):
super().setUp()
# breakpoint()
deprecations.reset_deprecations()

@property
Expand Down