Skip to content

Commit

Permalink
add test_diff
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxHalford committed Oct 30, 2023
1 parent 37c7436 commit fa5db06
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

0 comments on commit fa5db06

Please sign in to comment.