Skip to content
This repository was archived by the owner on May 17, 2024. It is now read-only.

Commit f406c0a

Browse files
authored
Merge pull request #443 from dlawin/issue_418_duckdb
adds a basic e2e test for --dbt using duckdb
2 parents a417702 + 22f0a92 commit f406c0a

7 files changed

Lines changed: 59 additions & 9 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ docs/_build/
7474
# PyBuilder
7575
target/
7676

77+
# Exception for dbt tests
78+
!tests/dbt_artifacts/target
79+
7780
# Jupyter Notebook
7881
.ipynb_checkpoints
7982

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: 'jaffle_shop'
2+
3+
config-version: 2
4+
version: '0.1'
5+
6+
profile: 'jaffle_shop'
7+
8+
model-paths: ["models"]
9+
seed-paths: ["seeds"]
10+
test-paths: ["tests"]
11+
analysis-paths: ["analysis"]
12+
macro-paths: ["macros"]
13+
14+
target-path: "target"
15+
clean-targets:
16+
- "target"
17+
- "dbt_modules"
18+
- "logs"
19+
20+
require-dbt-version: [">=1.0.0", "<2.0.0"]
21+
22+
vars:
23+
data_diff:
24+
prod_database: jaffle_shop
25+
prod_schema: prod
26+
27+
models:
28+
jaffle_shop:
29+
materialized: table
30+
staging:
31+
materialized: view
4.51 MB
Binary file not shown.

tests/dbt_artifacts/profiles.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
jaffle_shop:
2+
target: dev
3+
outputs:
4+
dev:
5+
type: duckdb
6+
path: "./tests/dbt_artifacts/jaffle_shop.duckdb"
7+
schema: dev

tests/dbt_artifacts/target/manifest.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"metadata": {"dbt_schema_version": "https://schemas.getdbt.com/dbt/run-results/v4.json", "dbt_version": "1.4.1", "generated_at": "2023-03-15T19:59:14.811639Z", "invocation_id": "ffabb889-60b0-4fcd-a4e6-456c549eb2c2", "env": {}}, "results": [{"status": "success", "timing": [{"name": "compile", "started_at": "2023-03-15T19:59:14.655050Z", "completed_at": "2023-03-15T19:59:14.657831Z"}, {"name": "execute", "started_at": "2023-03-15T19:59:14.658114Z", "completed_at": "2023-03-15T19:59:14.700161Z"}], "thread_id": "Thread-1 (worker)", "execution_time": 0.04775500297546387, "adapter_response": {"_message": "OK"}, "message": "OK", "failures": null, "unique_id": "model.jaffle_shop.stg_customers"}, {"status": "success", "timing": [{"name": "compile", "started_at": "2023-03-15T19:59:14.705294Z", "completed_at": "2023-03-15T19:59:14.706915Z"}, {"name": "execute", "started_at": "2023-03-15T19:59:14.707179Z", "completed_at": "2023-03-15T19:59:14.720823Z"}], "thread_id": "Thread-1 (worker)", "execution_time": 0.01781010627746582, "adapter_response": {"_message": "OK"}, "message": "OK", "failures": null, "unique_id": "model.jaffle_shop.stg_orders"}, {"status": "success", "timing": [{"name": "compile", "started_at": "2023-03-15T19:59:14.724207Z", "completed_at": "2023-03-15T19:59:14.725919Z"}, {"name": "execute", "started_at": "2023-03-15T19:59:14.726185Z", "completed_at": "2023-03-15T19:59:14.739744Z"}], "thread_id": "Thread-1 (worker)", "execution_time": 0.0189511775970459, "adapter_response": {"_message": "OK"}, "message": "OK", "failures": null, "unique_id": "model.jaffle_shop.stg_payments"}, {"status": "success", "timing": [{"name": "compile", "started_at": "2023-03-15T19:59:14.746471Z", "completed_at": "2023-03-15T19:59:14.750253Z"}, {"name": "execute", "started_at": "2023-03-15T19:59:14.750460Z", "completed_at": "2023-03-15T19:59:14.776306Z"}], "thread_id": "Thread-1 (worker)", "execution_time": 0.03409934043884277, "adapter_response": {"_message": "OK"}, "message": "OK", "failures": null, "unique_id": "model.jaffle_shop.customers"}, {"status": "success", "timing": [{"name": "compile", "started_at": "2023-03-15T19:59:14.781955Z", "completed_at": "2023-03-15T19:59:14.784545Z"}, {"name": "execute", "started_at": "2023-03-15T19:59:14.784765Z", "completed_at": "2023-03-15T19:59:14.799421Z"}], "thread_id": "Thread-1 (worker)", "execution_time": 0.021820068359375, "adapter_response": {"_message": "OK"}, "message": "OK", "failures": null, "unique_id": "model.jaffle_shop.orders"}], "elapsed_time": 0.20426106452941895, "args": {"write_json": true, "use_colors": true, "printer_width": 80, "version_check": true, "partial_parse": true, "static_parser": true, "profiles_dir": "/Users/dan/.dbt", "send_anonymous_usage_stats": true, "quiet": false, "no_print": false, "cache_selected_only": false, "which": "run", "rpc_method": "run", "indirect_selection": "eager"}}

tests/test_dbt.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -326,16 +326,23 @@ def test_get_connection_no_type(self, mock_open):
326326

327327

328328
class TestDbtDiffer(unittest.TestCase):
329-
# These two integration tests can be used to test a real diff
330-
# export DATA_DIFF_DBT_PROJ=/path/to/a/dbt/project
331-
# Expects a valid dbt project using a ~/.dbt/profiles.yml with run results
329+
# Set DATA_DIFF_DBT_PROJ to use your own dbt project, otherwise uses the duckdb project in tests/dbt_artifacts
332330
def test_integration_basic_dbt(self):
333-
project_dir = os.environ.get("DATA_DIFF_DBT_PROJ")
334-
if project_dir is not None:
335-
diff = run_datadiff_cli("--dbt", "--dbt-project-dir", project_dir)
336-
assert diff[-1].decode("utf-8") == "Diffs Complete!"
337-
else:
338-
pass
331+
artifacts_path = os.getcwd() + '/tests/dbt_artifacts'
332+
test_project_path = os.environ.get("DATA_DIFF_DBT_PROJ") or artifacts_path
333+
diff = run_datadiff_cli("--dbt", "--dbt-project-dir", test_project_path, "--dbt-profiles-dir", test_project_path)
334+
assert diff[-1].decode("utf-8") == "Diffs Complete!"
335+
336+
# assertions for the diff that exists in tests/dbt_artifacts/jaffle_shop.duckdb
337+
if test_project_path == artifacts_path:
338+
diff_string = b''.join(diff).decode('utf-8')
339+
# 5 diffs were ran
340+
assert diff_string.count('<>') == 5
341+
# 4 with no diffs
342+
assert diff_string.count('No row differences') == 4
343+
# 1 with a diff
344+
assert diff_string.count('| Rows Added | Rows Removed') == 1
345+
339346

340347
def test_integration_cloud_dbt(self):
341348
project_dir = os.environ.get("DATA_DIFF_DBT_PROJ")

0 commit comments

Comments
 (0)