Skip to content

Commit d04e962

Browse files
committed
re-order interface tests and fix playground dataset access
1 parent 44ae438 commit d04e962

File tree

2 files changed

+54
-54
lines changed

2 files changed

+54
-54
lines changed

docs/notebooks/playground/playground.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def foo():
5050
@app.cell
5151
def view(pipeline):
5252
# NOTE: This line displays the data of the items table in a marimo table
53-
pipeline.dataset(dataset_type="default").items.df()
53+
pipeline.dataset().items.df()
5454
return
5555

5656

tests/load/test_read_interfaces.py

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,59 @@ def populated_pipeline(
179179
)
180180

181181

182+
@pytest.mark.no_load
183+
@pytest.mark.essential
184+
@pytest.mark.parametrize(
185+
"populated_pipeline",
186+
configs,
187+
indirect=True,
188+
ids=lambda x: x.name,
189+
)
190+
def test_str_and_repr_on_dataset_and_relation(populated_pipeline: Pipeline) -> None:
191+
# no need to test on all destinations
192+
if populated_pipeline.destination.destination_type != "dlt.destinations.duckdb":
193+
pytest.skip("Only duckdb is supported for this test")
194+
195+
dataset_ = cast(ReadableDBAPIDataset, populated_pipeline.dataset())
196+
197+
def _replace_variable_content(s: str) -> str:
198+
# replace dataset name
199+
s = s.replace(dataset_.dataset_name, "dataset_name")
200+
# replace destination config
201+
dest_config = str(
202+
cast(ReadableDBAPIDataset, populated_pipeline.dataset()).destination_client.config
203+
)
204+
s = s.replace(dest_config, "<destination_config>")
205+
return s
206+
207+
# dataset
208+
assert (
209+
_replace_variable_content(str(dataset_))
210+
== "Dataset `dataset_name` at `duckdb[<destination_config>]` with tables in dlt schema"
211+
" `source`:\nitems, double_items, orderable_in_chain, items__children"
212+
)
213+
214+
dataset_repr = _replace_variable_content(repr(dataset_))
215+
assert dataset_repr.startswith("<dlt.dataset(dataset_name='dataset_name',")
216+
217+
# relation
218+
relation = dataset_("SELECT id, decimal FROM items")
219+
assert _replace_variable_content(str(relation)) == """Relation query:
220+
SELECT
221+
"items"."id" AS "id",
222+
"items"."decimal" AS "decimal"
223+
FROM "dataset_name"."items" AS "items"
224+
Columns:
225+
id bigint
226+
decimal decimal
227+
"""
228+
relation_repr = _replace_variable_content(repr(relation))
229+
assert relation_repr.startswith(
230+
"<dlt.Relation(dataset='<dlt.dataset(dataset_name=\\'dataset_name\\'"
231+
)
232+
assert '"items"."decimal" AS "decimal"' in relation_repr
233+
234+
182235
@pytest.mark.no_load
183236
@pytest.mark.parametrize(
184237
"populated_pipeline",
@@ -1433,56 +1486,3 @@ def test_naming_convention_propagation(destination_config: DestinationTestConfig
14331486
assert client.dataset_name.startswith("Read_test")
14341487
tables = client.native_connection.sql("SHOW TABLES;")
14351488
assert "ItemS" in str(tables)
1436-
1437-
1438-
@pytest.mark.no_load
1439-
@pytest.mark.essential
1440-
@pytest.mark.parametrize(
1441-
"populated_pipeline",
1442-
configs,
1443-
indirect=True,
1444-
ids=lambda x: x.name,
1445-
)
1446-
def test_str_and_repr_on_dataset_and_relation(populated_pipeline: Pipeline) -> None:
1447-
# no need to test on all destinations
1448-
if populated_pipeline.destination.destination_type != "dlt.destinations.duckdb":
1449-
pytest.skip("Only duckdb is supported for this test")
1450-
1451-
dataset_ = cast(ReadableDBAPIDataset, populated_pipeline.dataset())
1452-
1453-
def _replace_variable_content(s: str) -> str:
1454-
# replace dataset name
1455-
s = s.replace(dataset_.dataset_name, "dataset_name")
1456-
# replace destination config
1457-
dest_config = str(
1458-
cast(ReadableDBAPIDataset, populated_pipeline.dataset()).destination_client.config
1459-
)
1460-
s = s.replace(dest_config, "<destination_config>")
1461-
return s
1462-
1463-
# dataset
1464-
assert (
1465-
_replace_variable_content(str(dataset_))
1466-
== "Dataset `dataset_name` at `duckdb[<destination_config>]` with tables in dlt schema"
1467-
" `source`:\nitems, double_items, orderable_in_chain, items__children"
1468-
)
1469-
1470-
dataset_repr = _replace_variable_content(repr(dataset_))
1471-
assert dataset_repr.startswith("<dlt.dataset(dataset_name='dataset_name',")
1472-
1473-
# relation
1474-
relation = dataset_("SELECT id, decimal FROM items")
1475-
assert _replace_variable_content(str(relation)) == """Relation query:
1476-
SELECT
1477-
"items"."id" AS "id",
1478-
"items"."decimal" AS "decimal"
1479-
FROM "dataset_name"."items" AS "items"
1480-
Columns:
1481-
id bigint
1482-
decimal decimal
1483-
"""
1484-
relation_repr = _replace_variable_content(repr(relation))
1485-
assert relation_repr.startswith(
1486-
"<dlt.Relation(dataset='<dlt.dataset(dataset_name=\\'dataset_name\\'"
1487-
)
1488-
assert '"items"."decimal" AS "decimal"' in relation_repr

0 commit comments

Comments
 (0)