-
Notifications
You must be signed in to change notification settings - Fork 59
/
test_unit_testing.py
106 lines (85 loc) · 3.88 KB
/
test_unit_testing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import pytest
from dbt.artifacts.schemas.results import RunStatus
from dbt.tests.fixtures.project import write_project_files
from dbt.tests.util import run_dbt
from dbt.tests.adapter.unit_testing.test_types import BaseUnitTestingTypes
from dbt.tests.adapter.unit_testing.test_case_insensitivity import BaseUnitTestCaseInsensivity
from dbt.tests.adapter.unit_testing.test_invalid_input import BaseUnitTestInvalidInput
from tests.functional.adapter.unit_testing.fixtures import (
model_none_value_base,
model_none_value_model,
test_none_column_value_doesnt_throw_error_csv,
test_none_column_value_doesnt_throw_error_dct,
test_none_column_value_will_throw_error,
)
from dbt_common.exceptions import CompilationError
class TestRedshiftUnitTestingTypes(BaseUnitTestingTypes):
@pytest.fixture
def data_types(self):
# sql_value, yaml_value
return [
["1", "1"],
["1.0", "1.0"],
["'1'", "1"],
["'1'::numeric", "1"],
["'string'", "string"],
["true", "true"],
["DATE '2020-01-02'", "2020-01-02"],
["TIMESTAMP '2013-11-03 00:00:00-0'", "2013-11-03 00:00:00-0"],
["TIMESTAMPTZ '2013-11-03 00:00:00-0'", "2013-11-03 00:00:00-0"],
[
"""JSON_PARSE('{"bar": "baz", "balance": 7.77, "active": false}')""",
"""'{"bar": "baz", "balance": 7.77, "active": false}'""",
],
# TODO: array types
# ["ARRAY[1,2,3]", """'{1, 2, 3}'"""],
# ["ARRAY[1.0,2.0,3.0]", """'{1.0, 2.0, 3.0}'"""],
# ["ARRAY[1::numeric,2::numeric,3::numeric]", """'{1.0, 2.0, 3.0}'"""],
# ["ARRAY['a','b','c']", """'{"a", "b", "c"}'"""],
# ["ARRAY[true,true,false]", """'{true, true, false}'"""],
# ["ARRAY[DATE '2020-01-02']", """'{"2020-01-02"}'"""],
# ["ARRAY[TIMESTAMP '2013-11-03 00:00:00-0']", """'{"2013-11-03 00:00:00-0"}'"""],
# ["ARRAY[TIMESTAMPTZ '2013-11-03 00:00:00-0']", """'{"2013-11-03 00:00:00-0"}'"""],
]
class RedshiftUnitTestingNone:
def test_nones_handled_dict(self, project):
run_dbt(["build"])
class TestRedshiftUnitTestCsvNone(RedshiftUnitTestingNone):
@pytest.fixture(scope="class")
def models(self):
return {
"none_value_base.sql": model_none_value_base,
"none_value_model.sql": model_none_value_model,
"__properties.yml": test_none_column_value_doesnt_throw_error_csv,
}
class TestRedshiftUnitTestDictNone(RedshiftUnitTestingNone):
@pytest.fixture(scope="class")
def models(self):
return {
"none_value_base.sql": model_none_value_base,
"none_value_model.sql": model_none_value_model,
"__properties.yml": test_none_column_value_doesnt_throw_error_dct,
}
class TestRedshiftUnitTestingTooManyNonesFails:
@pytest.fixture(scope="class")
def models(self):
return {
"__properties.yml": test_none_column_value_will_throw_error,
"none_value_base.sql": model_none_value_base,
"none_value_model.sql": model_none_value_model,
}
def test_invalid_input(self, project):
"""This is a user-facing exception, so we can't pytest.raise(CompilationError)"""
def _find_first_error(items):
return next((item for item in items if item.status == RunStatus.Error), None)
run_result = run_dbt(["build"], expect_pass=False)
first_item = _find_first_error(run_result)
assert first_item is not None
assert (
"does not have any row free of null values, which may cause type mismatch errors during unit test execution"
in str(first_item.message)
)
class TestRedshiftUnitTestCaseInsensitivity(BaseUnitTestCaseInsensivity):
pass
class TestRedshiftUnitTestInvalidInput(BaseUnitTestInvalidInput):
pass