Skip to content

Commit ab93b98

Browse files
authored
Merge pull request elementary-data#496 from elementary-data/e2e-tests
E2e tests
2 parents 8412a12 + 63a0748 commit ab93b98

File tree

14 files changed

+97
-76
lines changed

14 files changed

+97
-76
lines changed

.github/workflows/run-unittest.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

.github/workflows/test-warehouse.yml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,12 @@ jobs:
104104
run: pip install dbt-core==${{ inputs.dbt-version }} dbt-${{ inputs.warehouse-type }}==${{ inputs.dbt-version }}
105105

106106
- name: Install Elementary
107-
run: pip install "./elementary[${{ inputs.warehouse-type }}]"
107+
run: |
108+
pip install -r ./elementary/dev-requirements.txt
109+
pip install "./elementary[${{ inputs.warehouse-type }}]"
108110
109-
- name: Upload build artifact
110-
uses: actions/upload-artifact@v3
111-
with:
112-
name: build
113-
path: elementary/build
111+
- name: Run Python package unit tests
112+
run: pytest -vv -k unit
114113

115114
- name: Install dbt package
116115
run: |
@@ -121,7 +120,7 @@ jobs:
121120
rm -rf "$DBT_PKGS_PATH/elementary"
122121
ln -vs "$GITHUB_WORKSPACE/dbt-data-reliability" "$DBT_PKGS_PATH/elementary"
123122
124-
- name: Run E2E tests
123+
- name: Run dbt package integration tests
125124
if: github.event_name != 'workflow_dispatch' || inputs.should-run-tests
126125
run: |
127126
dbt deps --project-dir ./dbt-data-reliability/integration_tests
@@ -171,3 +170,6 @@ jobs:
171170
with:
172171
name: edr.log
173172
path: edr.log
173+
174+
- name: Run Python package integration tests
175+
run: pytest -vv -k integration

pytest.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[pytest]
2+
addopts = --ignore=elementary/monitor/dbt_project
3+

tests/integration/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## Integration Tests
2+
3+
Those tests should only be run after running
4+
the [integration tests of the dbt package](https://github.com/elementary-data/dbt-data-reliability/tree/master/integration_tests)
5+
as the fixtures are based on their output data.

tests/integration/report/fixtures/elementary_output.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import json
2+
from pathlib import Path
3+
from typing import Dict
4+
5+
import pytest
6+
7+
_REPORT_DATA_FILENAME = "elementary_output.json"
8+
_REPORT_DATA_FIXTURE = Path(__file__).parent / "fixtures" / _REPORT_DATA_FILENAME
9+
_REPORT_DATA_PATH = Path(_REPORT_DATA_FILENAME)
10+
11+
TotalsEntry = Dict[str, int]
12+
Totals = Dict[str, TotalsEntry]
13+
14+
report_data = json.loads(_REPORT_DATA_PATH.read_text())
15+
16+
17+
def test_report_keys(report_data_fixture):
18+
assert report_data.keys() == report_data_fixture.keys()
19+
20+
21+
def test_totals(report_data_fixture):
22+
for key in report_data_fixture:
23+
if key.endswith("_totals"):
24+
assert_totals(report_data[key], report_data_fixture[key])
25+
26+
27+
def test_sidebar(report_data_fixture):
28+
assert (
29+
"model.elementary_integration_tests.error_model"
30+
in report_data["sidebars"]["dbt"]["elementary_integration_tests"]["models"][
31+
"__files__"
32+
]
33+
)
34+
assert (
35+
"model.elementary_integration_tests.nested"
36+
in report_data["sidebars"]["dbt"]["elementary_integration_tests"]["models"][
37+
"nested"
38+
]["models"]["tree"]["__files__"]
39+
)
40+
assert (
41+
"source.elementary_integration_tests.training.any_type_column_anomalies_training"
42+
in report_data["sidebars"]["dbt"]["elementary_integration_tests"]["sources"][
43+
"__files__"
44+
]
45+
)
46+
assert (
47+
"model.elementary_integration_tests.any_type_column_anomalies"
48+
in report_data["sidebars"]["owners"]["@edr"]
49+
)
50+
assert (
51+
"model.elementary_integration_tests.any_type_column_anomalies"
52+
not in report_data["sidebars"]["owners"]["No owners"]
53+
)
54+
assert (
55+
"model.elementary_integration_tests.string_column_anomalies"
56+
in report_data["sidebars"]["tags"]["marketing"]
57+
)
58+
assert (
59+
"model.elementary_integration_tests.string_column_anomalies"
60+
not in report_data["sidebars"]["tags"]["No tags"]
61+
)
62+
63+
64+
def assert_totals(data_totals: Totals, fixture_totals: Totals):
65+
assert data_totals.keys() == fixture_totals.keys()
66+
for total_key in fixture_totals:
67+
assert_totals_entry(data_totals[total_key], fixture_totals[total_key])
68+
69+
70+
def assert_totals_entry(
71+
data_total_entries: TotalsEntry, fixture_total_entries: TotalsEntry
72+
):
73+
for key in fixture_total_entries:
74+
assert data_total_entries[key] * fixture_total_entries[key] >= 0
75+
76+
77+
@pytest.fixture
78+
def report_data_fixture():
79+
return json.loads(_REPORT_DATA_FIXTURE.read_text())
File renamed without changes.

0 commit comments

Comments
 (0)