Skip to content

Commit 47101e1

Browse files
committed
Undo unnecessary adjustments in tests
1 parent 06f38b0 commit 47101e1

File tree

6 files changed

+55
-103
lines changed

6 files changed

+55
-103
lines changed

dlt/destinations/decorators.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ def destination(
201201
def destination(
202202
func_or_name: Union[Optional[AnyFun], str] = None,
203203
/,
204+
*,
204205
loader_file_format: TLoaderFileFormat = None,
205206
batch_size: int = 10,
206207
name: str = None,

tests/destinations/test_custom_destination.py

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
from tests.load.utils import (
2626
assert_all_data_types_row,
2727
)
28-
from tests.utils import preserve_environ
29-
3028

3129
SUPPORTED_LOADER_FORMATS = ["parquet", "typed-jsonl"]
3230

@@ -160,22 +158,7 @@ def test_capabilities() -> None:
160158
assert dict(caps) == dict(client_caps)
161159

162160

163-
@pytest.mark.parametrize(
164-
"use_factory_method",
165-
[True, False],
166-
ids=["use_factory_method", "use_from_reference"],
167-
)
168-
def test_instantiation(use_factory_method: bool) -> None:
169-
"""
170-
Test custom destination instantiation.
171-
172-
Args:
173-
use_factory_method (bool): If True, uses `dlt.destination()` (which calls
174-
`Destination.from_reference()` internally). If False, calls
175-
`Destination.from_reference()` directly. Both should behave identically.
176-
"""
177-
dest_ref_func = dlt.destination if use_factory_method else Destination.from_reference
178-
161+
def test_instantiation() -> None:
179162
# also tests DESTINATIONS registry
180163
calls: List[Tuple[TDataItems, TTableSchema]] = []
181164

@@ -201,7 +184,7 @@ def local_sink_func(items: TDataItems, table: TTableSchema, my_val=dlt.config.va
201184
calls = []
202185
p = dlt.pipeline(
203186
"sink_test",
204-
destination=dest_ref_func("destination", destination_callable=local_sink_func),
187+
destination=Destination.from_reference("destination", destination_callable=local_sink_func),
205188
dev_mode=True,
206189
)
207190
p.run([1, 2, 3], table_name="items")
@@ -217,7 +200,9 @@ def local_sink_func_no_params(items: TDataItems, table: TTableSchema) -> None:
217200

218201
p = dlt.pipeline(
219202
"sink_test",
220-
destination=dest_ref_func("destination", destination_callable=local_sink_func_no_params),
203+
destination=Destination.from_reference(
204+
"destination", destination_callable=local_sink_func_no_params
205+
),
221206
dev_mode=True,
222207
)
223208
p.run([1, 2, 3], table_name="items")
@@ -226,11 +211,10 @@ def local_sink_func_no_params(items: TDataItems, table: TTableSchema) -> None:
226211
global global_calls
227212
global_calls = []
228213
# this is technically possible but should not be used
229-
dest_ref = dest_ref_func(
214+
dest_ref = Destination.from_reference(
230215
"destination",
231216
destination_callable="tests.destinations.test_custom_destination.global_sink_func",
232217
)
233-
234218
assert dest_ref.destination_name == "global_sink_func"
235219
# type comes from the "destination" wrapper destination
236220
assert dest_ref.destination_type == "dlt.destinations.destination"
@@ -260,11 +244,10 @@ def local_sink_func_no_params(items: TDataItems, table: TTableSchema) -> None:
260244
assert len(global_calls) == 2
261245

262246
# we can import type (it is not a ref)
263-
dest_ref = dest_ref_func(
247+
dest_ref = Destination.from_reference(
264248
"tests.destinations.test_custom_destination.GlobalSinkFuncDestination",
265249
destination_name="alt_name",
266250
)
267-
268251
assert dest_ref.destination_name == "alt_name"
269252
assert (
270253
dest_ref.destination_type
@@ -280,7 +263,9 @@ def local_sink_func_no_params(items: TDataItems, table: TTableSchema) -> None:
280263
assert len(global_calls) == 3
281264

282265
# now import by ref
283-
dest_ref = dest_ref_func("tests.destinations.test_custom_destination.global_sink_func")
266+
dest_ref = Destination.from_reference(
267+
"tests.destinations.test_custom_destination.global_sink_func"
268+
)
284269
assert dest_ref.destination_name == "global_sink_func"
285270
assert (
286271
dest_ref.destination_type
@@ -298,7 +283,7 @@ def local_sink_func_no_params(items: TDataItems, table: TTableSchema) -> None:
298283
# pass None as callable arg will fail on load
299284
p = dlt.pipeline(
300285
"sink_test",
301-
destination=dest_ref_func("destination", destination_callable=None),
286+
destination=Destination.from_reference("destination", destination_callable=None),
302287
dev_mode=True,
303288
)
304289
with pytest.raises(ConfigurationValueError):
@@ -308,7 +293,9 @@ def local_sink_func_no_params(items: TDataItems, table: TTableSchema) -> None:
308293
with pytest.raises(UnknownCustomDestinationCallable):
309294
p = dlt.pipeline(
310295
"sink_test",
311-
destination=dest_ref_func("destination", destination_callable="does.not.exist"),
296+
destination=Destination.from_reference(
297+
"destination", destination_callable="does.not.exist"
298+
),
312299
dev_mode=True,
313300
)
314301

tests/load/duckdb/test_duckdb_client.py

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -307,22 +307,7 @@ def test_credentials_wrong_config() -> None:
307307

308308

309309
@pytest.mark.no_load
310-
@pytest.mark.parametrize(
311-
"use_factory_method",
312-
[True, False],
313-
ids=["use_factory_method", "use_from_reference"],
314-
)
315-
def test_duckdb_in_memory_mode_via_factory(use_factory_method: bool):
316-
"""
317-
Tests duckdb in-memory mode validation (rejecting :memory: credentials).
318-
319-
Args:
320-
use_factory_method (bool): If True, uses `dlt.destination()` (which calls
321-
`Destination.from_reference()` internally). If False, calls
322-
`Destination.from_reference()` directly. Both should behave identically.
323-
"""
324-
dest_ref_func = dlt.destination if use_factory_method else Destination.from_reference
325-
310+
def test_duckdb_in_memory_mode_via_factory():
326311
import duckdb
327312

328313
# Check if passing external duckdb connection works fine
@@ -351,7 +336,7 @@ def test_duckdb_in_memory_mode_via_factory(use_factory_method: bool):
351336
with pytest.raises(PipelineStepFailed) as exc:
352337
p = dlt.pipeline(
353338
pipeline_name="booboo",
354-
destination=dest_ref_func("duckdb", credentials=":memory:"),
339+
destination=Destination.from_reference("duckdb", credentials=":memory:"),
355340
)
356341
p.run([1, 2, 3], table_name="numbers")
357342

tests/load/pipeline/test_pipelines.py

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,27 +1132,37 @@ def events_timezone_unset():
11321132
assert actual == expected
11331133

11341134

1135-
@pytest.mark.parametrize(
1136-
"use_factory_method",
1137-
[True, False],
1138-
ids=["use_factory_method", "use_from_reference"],
1139-
)
1140-
def test_pipeline_with_destination_name(use_factory_method: bool):
1141-
"""
1142-
Test configured destination name (tests/.dlt/config.toml).
1135+
def test_pipeline_with_destination_name() -> None:
1136+
# test configured destination name (tests/.dlt/config.toml)
1137+
pipeline = dlt.pipeline(destination="custom_name")
1138+
assert pipeline.destination.destination_type == "dlt.destinations.duckdb"
1139+
assert pipeline.destination.destination_name == "custom_name"
11431140

1144-
Args:
1145-
use_factory_method (bool): If True, uses `dlt.destination()` (which calls
1146-
`Destination.from_reference()` internally). If False, calls
1147-
`Destination.from_reference()` directly. Both should behave identically.
1148-
"""
1149-
# dlt.destination(name) if the factory method is enabled,
1150-
# or just using the plain name otherwise
1151-
dest_ref_func: Any = (
1152-
(lambda name: dlt.destination(name)) if use_factory_method else (lambda name: name)
1153-
)
1141+
@dlt.resource
1142+
def test_data():
1143+
yield [{"id": 1, "name": "test"}]
1144+
1145+
info = pipeline.run(test_data())
1146+
assert_load_info(info)
1147+
1148+
# test unconfigured destination name
1149+
with pytest.raises(UnknownDestinationModule) as py_exc:
1150+
dlt.pipeline(destination="another_custom_name")
1151+
assert py_exc.value.named_dest_attempted is True
1152+
assert not py_exc.value.destination_type
1153+
assert "no destination type was configured" in str(py_exc.value)
1154+
1155+
# if destination contains dots, no fallbacks must happen
1156+
with pytest.raises(UnknownDestinationModule) as py_exc:
1157+
dlt.pipeline(destination="dlt.destinations.unknown")
1158+
assert not py_exc.value.named_dest_attempted
1159+
assert not py_exc.value.destination_type
1160+
1161+
1162+
def test_pipeline_with_destination_name_via_factory_initializer() -> None:
1163+
# test configured destination name (tests/.dlt/config.toml) via dlt.destination()
11541164

1155-
pipeline = dlt.pipeline(destination=dest_ref_func("custom_name"))
1165+
pipeline = dlt.pipeline(destination=dlt.destination("custom_name"))
11561166
assert pipeline.destination.destination_type == "dlt.destinations.duckdb"
11571167
assert pipeline.destination.destination_name == "custom_name"
11581168

@@ -1165,13 +1175,13 @@ def test_data():
11651175

11661176
# test unconfigured destination name
11671177
with pytest.raises(UnknownDestinationModule) as py_exc:
1168-
dlt.pipeline(destination=dest_ref_func("another_custom_name"))
1178+
dlt.pipeline(destination=dlt.destination("another_custom_name"))
11691179
assert py_exc.value.named_dest_attempted is True
11701180
assert not py_exc.value.destination_type
11711181
assert "no destination type was configured" in str(py_exc.value)
11721182

11731183
# if destination contains dots, no fallbacks must happen
11741184
with pytest.raises(UnknownDestinationModule) as py_exc:
1175-
dlt.pipeline(destination=dest_ref_func("dlt.destinations.unknown"))
1185+
dlt.pipeline(destination=dlt.destination("dlt.destinations.unknown"))
11761186
assert not py_exc.value.named_dest_attempted
11771187
assert not py_exc.value.destination_type

tests/load/pipeline/test_postgres.py

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -56,39 +56,22 @@ def test_postgres_encoded_binary(
5656
assert data["table"][0]["hash"].tobytes() == blob
5757

5858

59+
# do not remove - it allows us to filter tests by destination
5960
@pytest.mark.no_load
60-
@pytest.mark.parametrize(
61-
"use_factory_method",
62-
[True, False],
63-
ids=["use_factory_method", "use_from_reference"],
64-
)
6561
@pytest.mark.parametrize(
6662
"destination_config",
6763
destinations_configs(default_sql_configs=True, subset=["postgres"]),
6864
ids=lambda x: x.name,
6965
)
7066
def test_pipeline_explicit_destination_credentials(
71-
use_factory_method: bool,
7267
destination_config: DestinationTestConfiguration,
7368
) -> None:
74-
"""
75-
Tests that explicit destination credentials.
76-
77-
Args:
78-
use_factory_method (bool): If True, uses `dlt.destination()` (which calls
79-
`Destination.from_reference()` internally). If False, calls
80-
`Destination.from_reference()` directly. Both should behave identically.
81-
destination_config (DestinationTestConfiguration): Test configuration for the destination.
82-
This allows filtering tests by destination type. Do not remove.
83-
"""
8469
from dlt.destinations import postgres
8570
from dlt.destinations.impl.postgres.configuration import PostgresCredentials
8671

87-
dest_ref_func = dlt.destination if use_factory_method else Destination.from_reference
88-
8972
# explicit credentials resolved
9073
p = dlt.pipeline(
91-
destination=dest_ref_func(
74+
destination=Destination.from_reference(
9275
"postgres",
9376
destination_name="mydest",
9477
credentials="postgresql://loader:loader@localhost:7777/dlt_data",
@@ -101,7 +84,7 @@ def test_pipeline_explicit_destination_credentials(
10184
# explicit credentials resolved ignoring the config providers
10285
os.environ["DESTINATION__MYDEST__CREDENTIALS__HOST"] = "HOST"
10386
p = dlt.pipeline(
104-
destination=dest_ref_func(
87+
destination=Destination.from_reference(
10588
"postgres",
10689
destination_name="mydest",
10790
credentials="postgresql://loader:loader@localhost:5432/dlt_data",
@@ -114,7 +97,7 @@ def test_pipeline_explicit_destination_credentials(
11497
os.environ["DESTINATION__MYDEST__CREDENTIALS__USERNAME"] = "UN"
11598
os.environ["DESTINATION__MYDEST__CREDENTIALS__PASSWORD"] = "PW"
11699
p = dlt.pipeline(
117-
destination=dest_ref_func(
100+
destination=Destination.from_reference(
118101
"postgres",
119102
destination_name="mydest",
120103
credentials="postgresql://localhost:5432/dlt_data",

tests/pipeline/test_pipeline_state.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -100,25 +100,11 @@ def test_state_repr() -> None:
100100
]
101101

102102

103-
@pytest.mark.parametrize(
104-
"use_factory_method",
105-
[True, False],
106-
ids=["use_factory_method", "use_from_reference"],
107-
)
108-
def test_restore_state_props(use_factory_method: bool) -> None:
109-
"""Test pipeline state persistence and restoration.
110-
111-
Args:
112-
use_factory_method (bool): If True, uses `dlt.destination()` (which calls
113-
`Destination.from_reference()` internally). If False, calls
114-
`Destination.from_reference()` directly. Both should behave identically.
115-
"""
116-
dest_ref_func = dlt.destination if use_factory_method else Destination.from_reference
117-
103+
def test_restore_state_props() -> None:
118104
p = dlt.pipeline(
119105
pipeline_name="restore_state_props",
120-
destination=dest_ref_func("redshift", destination_name="redshift_name"),
121-
staging=dest_ref_func("filesystem", destination_name="filesystem_name"),
106+
destination=Destination.from_reference("redshift", destination_name="redshift_name"),
107+
staging=Destination.from_reference("filesystem", destination_name="filesystem_name"),
122108
dataset_name="the_dataset",
123109
)
124110
print(get_dlt_pipelines_dir())

0 commit comments

Comments
 (0)