diff --git a/tests/test_examples.py b/tests/test_examples.py index 5d5d0d8..6163dd3 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -21,7 +21,7 @@ def test_jaffle_shop(): # Write .env file with open(env_path, "w") as f: f.write( - "LEA_USERNAME=max\n" "LEA_WAREHOUSE=duckdb\n" "LEA_DUCKDB_PATH=test_jaffle_shop.db\n" + "LEA_USERNAME=max\n" "LEA_WAREHOUSE=duckdb\n" "LEA_DUCKDB_PATH=tests/jaffle_shop.db\n" ) # Prepare @@ -33,7 +33,7 @@ def test_jaffle_shop(): assert result.exit_code == 0 # Check number of tables created - con = duckdb.connect("test_jaffle_shop_max.db") + con = duckdb.connect("tests/jaffle_shop_max.db") tables = con.sql("SELECT table_schema, table_name FROM information_schema.tables").df() assert tables.shape[0] == 7 @@ -72,3 +72,44 @@ def test_jaffle_shop(): assert (docs_path / "core" / "README.md").exists() assert (docs_path / "staging" / "README.md").exists() assert (docs_path / "analytics" / "README.md").exists() + + +def test_diff(): + app = make_app(make_client=make_client) + here = pathlib.Path(__file__).parent + env_path = str((here.parent / "examples" / "diff" / ".env").absolute()) + prod_views_path = str((here.parent / "examples" / "diff" / "views" / "prod").absolute()) + dev_views_path = str((here.parent / "examples" / "diff" / "views" / "dev").absolute()) + + prod_args = [prod_views_path, "--env", env_path, "--production"] + dev_args = [dev_views_path, "--env", env_path] + + # Write .env file + with open(env_path, "w") as f: + f.write("LEA_USERNAME=max\n" "LEA_WAREHOUSE=duckdb\n" "LEA_DUCKDB_PATH=tests/diff.db\n") + + # Prepare + assert runner.invoke(app, ["prepare", *prod_args]).exit_code == 0 + assert runner.invoke(app, ["prepare", *dev_args]).exit_code == 0 + + # Run + assert runner.invoke(app, ["run", *prod_args]).exit_code == 0 + assert runner.invoke(app, ["run", *dev_args]).exit_code == 0 + + prod_con = duckdb.connect("tests/diff.db") + dev_con = duckdb.connect("tests/diff_max.db") + + # Check number of tables created + prod_tables = prod_con.sql( + "SELECT table_schema, table_name FROM information_schema.tables" + ).df() + assert prod_tables.shape[0] == 5 + assert prod_tables.table_schema.nunique() == 2 + + dev_tables = prod_con.sql("SELECT table_schema, table_name FROM information_schema.tables").df() + assert dev_tables.shape[0] == 5 + assert dev_tables.table_schema.nunique() == 2 + + # Check number of rows in core__customers + assert prod_con.sql("SELECT * FROM core.orders").df().shape[0] == 99 + assert dev_con.sql("SELECT * FROM core.orders").df().shape[0] == 70