Skip to content

Commit 0a1eb8e

Browse files
committed
Simplify some fixtures
1 parent 36ad191 commit 0a1eb8e

File tree

2 files changed

+40
-95
lines changed

2 files changed

+40
-95
lines changed

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import time
55
from collections.abc import AsyncGenerator, Callable
6+
from contextlib import suppress
67
from pathlib import Path
78
from unittest.mock import AsyncMock, Mock
89

@@ -104,10 +105,9 @@ def alembic_config(settings: Settings) -> AlembicConfig:
104105
@pytest_asyncio.fixture(scope="session")
105106
async def async_engine(settings: Settings, alembic_config: AlembicConfig):
106107
await prepare_new_database(settings=settings)
107-
try:
108+
with suppress(Exception):
108109
await run_async_migrations(alembic_config, Base.metadata, "-1", "down")
109-
except Exception:
110-
pass
110+
111111
await run_async_migrations(alembic_config, Base.metadata, "head")
112112
engine = create_async_engine(settings.database.url)
113113
yield engine

tests/test_integration/test_run_transfer/connection_fixtures/file_storage_fixtures.py

Lines changed: 37 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import pytest
44
from onetl.file.format import CSV, JSON, ORC, XML, Excel, JSONLine, Parquet
5-
from pytest import FixtureRequest
65

76

87
@pytest.fixture(scope="session")
@@ -13,99 +12,45 @@ def resource_path():
1312

1413

1514
@pytest.fixture(params=[""])
16-
def file_format_flavor(request: FixtureRequest):
15+
def file_format_flavor(request: pytest.FixtureRequest):
1716
return request.param
1817

1918

20-
@pytest.fixture()
21-
def source_file_format(request: FixtureRequest):
19+
@pytest.fixture
20+
def source_file_format(request: pytest.FixtureRequest):
2221
name, params = request.param
23-
if name == "csv":
24-
return "csv", CSV(
25-
lineSep="\n",
26-
header=True,
27-
**params,
28-
)
29-
30-
if name == "jsonline":
31-
return "jsonline", JSONLine(
32-
encoding="utf-8",
33-
lineSep="\n",
34-
**params,
35-
)
36-
37-
if name == "json":
38-
return "json", JSON(
39-
lineSep="\n",
40-
encoding="utf-8",
41-
**params,
42-
)
43-
44-
if name == "excel":
45-
return "excel", Excel(
46-
header=True,
47-
inferSchema=True,
48-
**params,
49-
)
50-
51-
if name == "orc":
52-
return "orc", ORC(
53-
**params,
54-
)
55-
56-
if name == "parquet":
57-
return "parquet", Parquet(
58-
**params,
59-
)
60-
61-
if name == "xml":
62-
return "xml", XML(
63-
row_tag="item",
64-
**params,
65-
)
66-
67-
raise ValueError(f"Unsupported file format: {name}")
68-
69-
70-
@pytest.fixture()
71-
def target_file_format(request: FixtureRequest):
22+
result_map = {
23+
"csv": CSV(lineSep="\n", header=True, **params),
24+
"jsonline": JSONLine(encoding="utf-8", lineSep="\n", **params),
25+
"json": JSON(lineSep="\n", encoding="utf-8", **params),
26+
"excel": Excel(header=True, inferSchema=True, **params),
27+
"orc": ORC(**params),
28+
"parquet": Parquet(**params),
29+
"xml": XML(rowTag="item", **params),
30+
}
31+
32+
try:
33+
return name, result_map[name]
34+
except KeyError as e:
35+
msg = f"Unsupported file format: {name}"
36+
raise ValueError(msg) from e
37+
38+
39+
@pytest.fixture
40+
def target_file_format(request: pytest.FixtureRequest):
7241
name, params = request.param
73-
if name == "csv":
74-
return "csv", CSV(
75-
lineSep="\n",
76-
header=True,
77-
timestampFormat="yyyy-MM-dd'T'HH:mm:ss.SSSSSS+00:00",
78-
**params,
79-
)
80-
81-
if name == "jsonline":
82-
return "jsonline", JSONLine(
83-
encoding="utf-8",
84-
lineSep="\n",
85-
timestampFormat="yyyy-MM-dd'T'HH:mm:ss.SSSSSS+00:00",
86-
**params,
87-
)
88-
89-
if name == "excel":
90-
return "excel", Excel(
91-
header=False,
92-
**params,
93-
)
94-
95-
if name == "orc":
96-
return "orc", ORC(
97-
**params,
98-
)
99-
100-
if name == "parquet":
101-
return "parquet", Parquet(
102-
**params,
103-
)
104-
105-
if name == "xml":
106-
return "xml", XML(
107-
row_tag="item",
108-
**params,
109-
)
110-
111-
raise ValueError(f"Unsupported file format: {name}")
42+
timestamp_format = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS+00:00"
43+
result_map = {
44+
"csv": CSV(lineSep="\n", header=True, timestampFormat=timestamp_format, **params),
45+
"jsonline": JSONLine(encoding="utf-8", lineSep="\n", timestampFormat=timestamp_format, **params),
46+
"excel": Excel(header=True, inferSchema=True, **params),
47+
"orc": ORC(**params),
48+
"parquet": Parquet(**params),
49+
"xml": XML(rowTag="item", **params),
50+
}
51+
52+
try:
53+
return name, result_map[name]
54+
except KeyError as e:
55+
msg = f"Unsupported file format: {name}"
56+
raise ValueError(msg) from e

0 commit comments

Comments
 (0)