Skip to content

Commit ee260ef

Browse files
committed
Remove a layer of test case nesting
1 parent 179fc59 commit ee260ef

File tree

4 files changed

+748
-746
lines changed

4 files changed

+748
-746
lines changed

tests/test_drop_tables.py

Lines changed: 58 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -19,74 +19,75 @@
1919

2020

2121
@dataclass(frozen=True)
22-
class DropTablesCase(MockedResponseTestCase):
22+
class DropTablesTC(MockedResponseTestCase):
2323
drop: str
2424
expected_tables: list[str]
2525

2626

27-
class DropTablesCases:
28-
@parametrize(keep_raw=[True, False])
29-
def case_one_table(self, keep_raw: bool) -> DropTablesCase:
30-
return DropTablesCase(
27+
@parametrize(keep_raw=[True, False])
28+
def case_one_table(keep_raw: bool) -> DropTablesTC:
29+
return DropTablesTC(
30+
Call(
31+
"prefix",
32+
returns={"purchaseOrders": [{"id": "1"}]},
33+
keep_raw=keep_raw,
34+
),
35+
drop="prefix",
36+
expected_tables=[],
37+
)
38+
39+
40+
@parametrize(keep_raw=[True, False])
41+
def case_two_tables(keep_raw: bool) -> DropTablesTC:
42+
return DropTablesTC(
43+
Call(
44+
"prefix",
45+
returns={
46+
"purchaseOrders": [
47+
{
48+
"id": "1",
49+
"subObjects": [{"id": "2"}, {"id": "3"}],
50+
},
51+
],
52+
},
53+
keep_raw=keep_raw,
54+
),
55+
drop="prefix",
56+
expected_tables=[],
57+
)
58+
59+
60+
@parametrize(keep_raw=[True, False])
61+
def case_separate_table(keep_raw: bool) -> DropTablesTC:
62+
expected_tables = [
63+
"notdropped__t",
64+
"notdropped__tcatalog",
65+
]
66+
if keep_raw:
67+
expected_tables = ["notdropped", *expected_tables]
68+
69+
return DropTablesTC(
70+
[
3171
Call(
3272
"prefix",
3373
returns={"purchaseOrders": [{"id": "1"}]},
3474
keep_raw=keep_raw,
3575
),
36-
drop="prefix",
37-
expected_tables=[],
38-
)
39-
40-
@parametrize(keep_raw=[True, False])
41-
def case_two_tables(self, keep_raw: bool) -> DropTablesCase:
42-
return DropTablesCase(
4376
Call(
44-
"prefix",
45-
returns={
46-
"purchaseOrders": [
47-
{
48-
"id": "1",
49-
"subObjects": [{"id": "2"}, {"id": "3"}],
50-
},
51-
],
52-
},
77+
"notdropped",
78+
returns={"purchaseOrders": [{"id": "1"}]},
5379
keep_raw=keep_raw,
5480
),
55-
drop="prefix",
56-
expected_tables=[],
57-
)
58-
59-
@parametrize(keep_raw=[True, False])
60-
def case_separate_table(self, keep_raw: bool) -> DropTablesCase:
61-
expected_tables = [
62-
"notdropped__t",
63-
"notdropped__tcatalog",
64-
]
65-
if keep_raw:
66-
expected_tables = ["notdropped", *expected_tables]
67-
68-
return DropTablesCase(
69-
[
70-
Call(
71-
"prefix",
72-
returns={"purchaseOrders": [{"id": "1"}]},
73-
keep_raw=keep_raw,
74-
),
75-
Call(
76-
"notdropped",
77-
returns={"purchaseOrders": [{"id": "1"}]},
78-
keep_raw=keep_raw,
79-
),
80-
],
81-
drop="prefix",
82-
expected_tables=expected_tables,
83-
)
81+
],
82+
drop="prefix",
83+
expected_tables=expected_tables,
84+
)
8485

8586

8687
def _arrange(
8788
client_get_mock: MagicMock,
8889
httpx_post_mock: MagicMock,
89-
tc: DropTablesCase,
90+
tc: DropTablesTC,
9091
) -> "ldlite.LDLite":
9192
from ldlite import LDLite
9293

@@ -96,7 +97,7 @@ def _arrange(
9697
return uut
9798

9899

99-
def _act(uut: "ldlite.LDLite", tc: DropTablesCase) -> None:
100+
def _act(uut: "ldlite.LDLite", tc: DropTablesTC) -> None:
100101
uut.drop_tables(tc.drop)
101102
for call in tc.calls_list:
102103
uut.query(table=call.prefix, path="/patched", keep_raw=call.keep_raw)
@@ -106,7 +107,7 @@ def _act(uut: "ldlite.LDLite", tc: DropTablesCase) -> None:
106107
def _assert(
107108
conn: "dbapi.DBAPIConnection",
108109
res_schema: str, # TODO: have schema be part of tc
109-
tc: DropTablesCase,
110+
tc: DropTablesTC,
110111
) -> None:
111112
with closing(conn.cursor()) as cur:
112113
cur.execute(
@@ -133,11 +134,11 @@ def _assert(
133134

134135
@mock.patch("httpx_folio.auth.httpx.post")
135136
@mock.patch("httpx_folio.factories.httpx.Client.get")
136-
@parametrize_with_cases("tc", cases=DropTablesCases)
137+
@parametrize_with_cases("tc", cases=".")
137138
def test_duckdb(
138139
client_get_mock: MagicMock,
139140
httpx_post_mock: MagicMock,
140-
tc: DropTablesCase,
141+
tc: DropTablesTC,
141142
) -> None:
142143
uut = _arrange(client_get_mock, httpx_post_mock, tc)
143144
dsn = f":memory:{tc.db}"
@@ -151,12 +152,12 @@ def test_duckdb(
151152

152153
@mock.patch("httpx_folio.auth.httpx.post")
153154
@mock.patch("httpx_folio.factories.httpx.Client.get")
154-
@parametrize_with_cases("tc", cases=DropTablesCases)
155+
@parametrize_with_cases("tc", cases=".")
155156
def test_postgres(
156157
client_get_mock: MagicMock,
157158
httpx_post_mock: MagicMock,
158159
pg_dsn: None | Callable[[str], str],
159-
tc: DropTablesCase,
160+
tc: DropTablesTC,
160161
) -> None:
161162
if pg_dsn is None:
162163
pytest.skip("Specify the pg host using --pg-host to run")

tests/test_export_csv.py

Lines changed: 77 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -18,85 +18,87 @@
1818

1919

2020
@dataclass(frozen=True)
21-
class ToCsvCase(MockedResponseTestCase):
21+
class ExportCsvTC(MockedResponseTestCase):
2222
expected_csvs: list[tuple[str, Path]]
2323

2424

25-
class ToCsvCases:
26-
def case_basic(self) -> ToCsvCase:
27-
return ToCsvCase(
28-
Call("prefix", returns={"purchaseOrders": [{"id": "id", "val": "value"}]}),
29-
expected_csvs=[("prefix__t", _SAMPLE_PATH / "basic.csv")],
30-
)
31-
32-
def case_datatypes(self) -> ToCsvCase:
33-
return ToCsvCase(
34-
Call(
35-
"prefix",
36-
returns={
37-
"purchaseOrders": [
38-
{
39-
"id": "id",
40-
"string": "string",
41-
"integer": 1,
42-
"numeric": 1.1,
43-
"boolean": True,
44-
"uuid": "6a31a12a-9570-405c-af20-6abf2992859c",
45-
},
46-
],
47-
},
48-
),
49-
expected_csvs=[("prefix__t", _SAMPLE_PATH / "datatypes.csv")],
50-
)
51-
52-
def case_escaped_chars(self) -> ToCsvCase:
53-
return ToCsvCase(
54-
Call(
55-
"prefix",
56-
returns={
57-
"purchaseOrders": [
58-
{
59-
"id": "id",
60-
"comma": "Double, double toil and trouble",
61-
"doubleQuote": 'Cry "Havoc!" a horse',
62-
"newLine": """To be
25+
def case_basic() -> ExportCsvTC:
26+
return ExportCsvTC(
27+
Call("prefix", returns={"purchaseOrders": [{"id": "id", "val": "value"}]}),
28+
expected_csvs=[("prefix__t", _SAMPLE_PATH / "basic.csv")],
29+
)
30+
31+
32+
def case_datatypes() -> ExportCsvTC:
33+
return ExportCsvTC(
34+
Call(
35+
"prefix",
36+
returns={
37+
"purchaseOrders": [
38+
{
39+
"id": "id",
40+
"string": "string",
41+
"integer": 1,
42+
"numeric": 1.1,
43+
"boolean": True,
44+
"uuid": "6a31a12a-9570-405c-af20-6abf2992859c",
45+
},
46+
],
47+
},
48+
),
49+
expected_csvs=[("prefix__t", _SAMPLE_PATH / "datatypes.csv")],
50+
)
51+
52+
53+
def case_escaped_chars() -> ExportCsvTC:
54+
return ExportCsvTC(
55+
Call(
56+
"prefix",
57+
returns={
58+
"purchaseOrders": [
59+
{
60+
"id": "id",
61+
"comma": "Double, double toil and trouble",
62+
"doubleQuote": 'Cry "Havoc!" a horse',
63+
"newLine": """To be
6364
or not
6465
to be""",
65-
"singleQuote": "Cry 'Havoc!' a horse",
66-
},
67-
{
68-
"id": "id",
69-
"comma": "Z",
70-
"doubleQuote": "Z",
71-
"newLine": "Z",
72-
"singleQuote": "Z",
73-
},
74-
],
75-
},
76-
),
77-
expected_csvs=[("prefix__t", _SAMPLE_PATH / "escaped_chars.csv")],
78-
)
79-
80-
def case_sorting(self) -> ToCsvCase:
81-
return ToCsvCase(
82-
Call(
83-
"prefix",
84-
returns={
85-
"purchaseOrders": [
86-
{"id": "id", "C": "YY", "B": "XX", "A": "ZZ"},
87-
{"id": "id", "C": "Y", "B": "XX", "A": "ZZ"},
88-
{"id": "id", "C": "Y", "B": "X", "A": "Z"},
89-
],
90-
},
91-
),
92-
expected_csvs=[("prefix__t", _SAMPLE_PATH / "sorting.csv")],
93-
)
66+
"singleQuote": "Cry 'Havoc!' a horse",
67+
},
68+
{
69+
"id": "id",
70+
"comma": "Z",
71+
"doubleQuote": "Z",
72+
"newLine": "Z",
73+
"singleQuote": "Z",
74+
},
75+
],
76+
},
77+
),
78+
expected_csvs=[("prefix__t", _SAMPLE_PATH / "escaped_chars.csv")],
79+
)
80+
81+
82+
def case_sorting() -> ExportCsvTC:
83+
return ExportCsvTC(
84+
Call(
85+
"prefix",
86+
returns={
87+
"purchaseOrders": [
88+
{"id": "id", "C": "YY", "B": "XX", "A": "ZZ"},
89+
{"id": "id", "C": "Y", "B": "XX", "A": "ZZ"},
90+
{"id": "id", "C": "Y", "B": "X", "A": "Z"},
91+
],
92+
},
93+
),
94+
expected_csvs=[("prefix__t", _SAMPLE_PATH / "sorting.csv")],
95+
)
9496

9597

9698
def _arrange(
9799
client_get_mock: MagicMock,
98100
httpx_post_mock: MagicMock,
99-
tc: ToCsvCase,
101+
tc: ExportCsvTC,
100102
) -> "ldlite.LDLite":
101103
from ldlite import LDLite
102104

@@ -106,14 +108,14 @@ def _arrange(
106108
return uut
107109

108110

109-
def _act(uut: "ldlite.LDLite", tc: ToCsvCase) -> None:
111+
def _act(uut: "ldlite.LDLite", tc: ExportCsvTC) -> None:
110112
for call in tc.calls_list:
111113
uut.query(table=call.prefix, path="/patched")
112114

113115

114116
def _assert(
115117
uut: "ldlite.LDLite",
116-
tc: ToCsvCase,
118+
tc: ExportCsvTC,
117119
tmpdir: str,
118120
) -> None:
119121
for table, expected in tc.expected_csvs:
@@ -133,11 +135,11 @@ def _assert(
133135

134136
@mock.patch("httpx_folio.auth.httpx.post")
135137
@mock.patch("httpx_folio.factories.httpx.Client.get")
136-
@parametrize_with_cases("tc", cases=ToCsvCases)
138+
@parametrize_with_cases("tc", cases=".")
137139
def test_duckdb(
138140
client_get_mock: MagicMock,
139141
httpx_post_mock: MagicMock,
140-
tc: ToCsvCase,
142+
tc: ExportCsvTC,
141143
tmpdir: str,
142144
) -> None:
143145
uut = _arrange(client_get_mock, httpx_post_mock, tc)
@@ -150,12 +152,12 @@ def test_duckdb(
150152

151153
@mock.patch("httpx_folio.auth.httpx.post")
152154
@mock.patch("httpx_folio.factories.httpx.Client.get")
153-
@parametrize_with_cases("tc", cases=ToCsvCases)
155+
@parametrize_with_cases("tc", cases=".")
154156
def test_postgres(
155157
client_get_mock: MagicMock,
156158
httpx_post_mock: MagicMock,
157159
pg_dsn: None | Callable[[str], str],
158-
tc: ToCsvCase,
160+
tc: ExportCsvTC,
159161
tmpdir: str,
160162
) -> None:
161163
if pg_dsn is None:

0 commit comments

Comments
 (0)