Skip to content

Commit ef60e3b

Browse files
committed
DRY
1 parent 98109e8 commit ef60e3b

File tree

1 file changed

+30
-180
lines changed

1 file changed

+30
-180
lines changed

tests/integration/test_catalog.py

Lines changed: 30 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,17 @@ def hive_catalog() -> Generator[Catalog, None, None]:
8989
clean_up(test_catalog)
9090

9191

92+
CATALOGS = [
93+
pytest.lazy_fixture("memory_catalog"),
94+
pytest.lazy_fixture("sqlite_catalog_memory"),
95+
pytest.lazy_fixture("sqlite_catalog_file"),
96+
pytest.lazy_fixture("rest_catalog"),
97+
pytest.lazy_fixture("hive_catalog"),
98+
]
99+
100+
92101
@pytest.mark.integration
93-
@pytest.mark.parametrize(
94-
"test_catalog",
95-
[
96-
pytest.lazy_fixture("memory_catalog"),
97-
pytest.lazy_fixture("sqlite_catalog_memory"),
98-
pytest.lazy_fixture("sqlite_catalog_file"),
99-
pytest.lazy_fixture("rest_catalog"),
100-
pytest.lazy_fixture("hive_catalog"),
101-
],
102-
)
102+
@pytest.mark.parametrize("test_catalog", CATALOGS)
103103
def test_create_table_with_default_location(
104104
test_catalog: Catalog, table_schema_nested: Schema, table_name: str, database_name: str
105105
) -> None:
@@ -112,33 +112,15 @@ def test_create_table_with_default_location(
112112

113113

114114
@pytest.mark.integration
115-
@pytest.mark.parametrize(
116-
"test_catalog",
117-
[
118-
pytest.lazy_fixture("memory_catalog"),
119-
pytest.lazy_fixture("sqlite_catalog_memory"),
120-
pytest.lazy_fixture("sqlite_catalog_file"),
121-
pytest.lazy_fixture("rest_catalog"),
122-
pytest.lazy_fixture("hive_catalog"),
123-
],
124-
)
115+
@pytest.mark.parametrize("test_catalog", CATALOGS)
125116
def test_create_table_with_invalid_database(test_catalog: Catalog, table_schema_nested: Schema, table_name: str) -> None:
126117
identifier = ("invalid", table_name)
127118
with pytest.raises(NoSuchNamespaceError):
128119
test_catalog.create_table(identifier, table_schema_nested)
129120

130121

131122
@pytest.mark.integration
132-
@pytest.mark.parametrize(
133-
"test_catalog",
134-
[
135-
pytest.lazy_fixture("memory_catalog"),
136-
pytest.lazy_fixture("sqlite_catalog_memory"),
137-
pytest.lazy_fixture("sqlite_catalog_file"),
138-
pytest.lazy_fixture("rest_catalog"),
139-
pytest.lazy_fixture("hive_catalog"),
140-
],
141-
)
123+
@pytest.mark.parametrize("test_catalog", CATALOGS)
142124
def test_create_duplicated_table(test_catalog: Catalog, table_schema_nested: Schema, database_name: str, table_name: str) -> None:
143125
test_catalog.create_namespace(database_name)
144126
test_catalog.create_table((database_name, table_name), table_schema_nested)
@@ -147,16 +129,7 @@ def test_create_duplicated_table(test_catalog: Catalog, table_schema_nested: Sch
147129

148130

149131
@pytest.mark.integration
150-
@pytest.mark.parametrize(
151-
"test_catalog",
152-
[
153-
pytest.lazy_fixture("memory_catalog"),
154-
pytest.lazy_fixture("sqlite_catalog_memory"),
155-
pytest.lazy_fixture("sqlite_catalog_file"),
156-
pytest.lazy_fixture("rest_catalog"),
157-
pytest.lazy_fixture("hive_catalog"),
158-
],
159-
)
132+
@pytest.mark.parametrize("test_catalog", CATALOGS)
160133
def test_create_table_if_not_exists_duplicated_table(
161134
test_catalog: Catalog, table_schema_nested: Schema, database_name: str, table_name: str
162135
) -> None:
@@ -167,16 +140,7 @@ def test_create_table_if_not_exists_duplicated_table(
167140

168141

169142
@pytest.mark.integration
170-
@pytest.mark.parametrize(
171-
"test_catalog",
172-
[
173-
pytest.lazy_fixture("memory_catalog"),
174-
pytest.lazy_fixture("sqlite_catalog_memory"),
175-
pytest.lazy_fixture("sqlite_catalog_file"),
176-
pytest.lazy_fixture("rest_catalog"),
177-
pytest.lazy_fixture("hive_catalog"),
178-
],
179-
)
143+
@pytest.mark.parametrize("test_catalog", CATALOGS)
180144
def test_load_table(test_catalog: Catalog, table_schema_nested: Schema, database_name: str, table_name: str) -> None:
181145
identifier = (database_name, table_name)
182146
test_catalog.create_namespace(database_name)
@@ -188,16 +152,7 @@ def test_load_table(test_catalog: Catalog, table_schema_nested: Schema, database
188152

189153

190154
@pytest.mark.integration
191-
@pytest.mark.parametrize(
192-
"test_catalog",
193-
[
194-
pytest.lazy_fixture("memory_catalog"),
195-
pytest.lazy_fixture("sqlite_catalog_memory"),
196-
pytest.lazy_fixture("sqlite_catalog_file"),
197-
pytest.lazy_fixture("rest_catalog"),
198-
pytest.lazy_fixture("hive_catalog"),
199-
],
200-
)
155+
@pytest.mark.parametrize("test_catalog", CATALOGS)
201156
def test_list_tables(test_catalog: Catalog, table_schema_nested: Schema, database_name: str, table_list: List[str]) -> None:
202157
test_catalog.create_namespace(database_name)
203158
for table_name in table_list:
@@ -209,16 +164,7 @@ def test_list_tables(test_catalog: Catalog, table_schema_nested: Schema, databas
209164

210165

211166
@pytest.mark.integration
212-
@pytest.mark.parametrize(
213-
"test_catalog",
214-
[
215-
pytest.lazy_fixture("memory_catalog"),
216-
pytest.lazy_fixture("sqlite_catalog_memory"),
217-
pytest.lazy_fixture("sqlite_catalog_file"),
218-
pytest.lazy_fixture("rest_catalog"),
219-
pytest.lazy_fixture("hive_catalog"),
220-
],
221-
)
167+
@pytest.mark.parametrize("test_catalog", CATALOGS)
222168
def test_rename_table(test_catalog: Catalog, table_schema_nested: Schema, table_name: str, database_name: str) -> None:
223169
new_database_name = f"{database_name}_new"
224170
test_catalog.create_namespace(database_name)
@@ -237,16 +183,7 @@ def test_rename_table(test_catalog: Catalog, table_schema_nested: Schema, table_
237183

238184

239185
@pytest.mark.integration
240-
@pytest.mark.parametrize(
241-
"test_catalog",
242-
[
243-
pytest.lazy_fixture("memory_catalog"),
244-
pytest.lazy_fixture("sqlite_catalog_memory"),
245-
pytest.lazy_fixture("sqlite_catalog_file"),
246-
pytest.lazy_fixture("rest_catalog"),
247-
pytest.lazy_fixture("hive_catalog"),
248-
],
249-
)
186+
@pytest.mark.parametrize("test_catalog", CATALOGS)
250187
def test_drop_table(test_catalog: Catalog, table_schema_nested: Schema, table_name: str, database_name: str) -> None:
251188
identifier = (database_name, table_name)
252189
test_catalog.create_namespace(database_name)
@@ -258,17 +195,11 @@ def test_drop_table(test_catalog: Catalog, table_schema_nested: Schema, table_na
258195

259196

260197
@pytest.mark.integration
261-
@pytest.mark.parametrize(
262-
"test_catalog",
263-
[
264-
pytest.lazy_fixture("memory_catalog"),
265-
pytest.lazy_fixture("sqlite_catalog_memory"),
266-
pytest.lazy_fixture("sqlite_catalog_file"),
267-
pytest.lazy_fixture("rest_catalog"),
268-
# NOTE: HiveCatalog does not support purge_table
269-
],
270-
)
198+
@pytest.mark.parametrize("test_catalog", CATALOGS)
271199
def test_purge_table(test_catalog: Catalog, table_schema_nested: Schema, table_name: str, database_name: str) -> None:
200+
if isinstance(test_catalog, HiveCatalog):
201+
pytest.skip("HiveCatalog does not support purge_table operation yet")
202+
272203
identifier = (database_name, table_name)
273204
test_catalog.create_namespace(database_name)
274205
test_catalog.create_table(identifier, table_schema_nested)
@@ -280,83 +211,38 @@ def test_purge_table(test_catalog: Catalog, table_schema_nested: Schema, table_n
280211

281212

282213
@pytest.mark.integration
283-
@pytest.mark.parametrize(
284-
"test_catalog",
285-
[
286-
pytest.lazy_fixture("memory_catalog"),
287-
pytest.lazy_fixture("sqlite_catalog_memory"),
288-
pytest.lazy_fixture("sqlite_catalog_file"),
289-
pytest.lazy_fixture("rest_catalog"),
290-
pytest.lazy_fixture("hive_catalog"),
291-
],
292-
)
214+
@pytest.mark.parametrize("test_catalog", CATALOGS)
293215
def test_table_exists(test_catalog: Catalog, table_schema_nested: Schema, database_name: str, table_name: str) -> None:
294216
test_catalog.create_namespace(database_name)
295217
test_catalog.create_table((database_name, table_name), table_schema_nested)
296218
assert test_catalog.table_exists((database_name, table_name)) is True
297219

298220

299221
@pytest.mark.integration
300-
@pytest.mark.parametrize(
301-
"test_catalog",
302-
[
303-
pytest.lazy_fixture("memory_catalog"),
304-
pytest.lazy_fixture("sqlite_catalog_memory"),
305-
pytest.lazy_fixture("sqlite_catalog_file"),
306-
pytest.lazy_fixture("rest_catalog"),
307-
pytest.lazy_fixture("hive_catalog"),
308-
],
309-
)
222+
@pytest.mark.parametrize("test_catalog", CATALOGS)
310223
def test_create_namespace(test_catalog: Catalog, database_name: str) -> None:
311224
test_catalog.create_namespace(database_name)
312225
assert (database_name,) in test_catalog.list_namespaces()
313226

314227

315228
@pytest.mark.integration
316-
@pytest.mark.parametrize(
317-
"test_catalog",
318-
[
319-
pytest.lazy_fixture("memory_catalog"),
320-
pytest.lazy_fixture("sqlite_catalog_memory"),
321-
pytest.lazy_fixture("sqlite_catalog_file"),
322-
pytest.lazy_fixture("rest_catalog"),
323-
pytest.lazy_fixture("hive_catalog"),
324-
],
325-
)
229+
@pytest.mark.parametrize("test_catalog", CATALOGS)
326230
def test_create_duplicate_namespace(test_catalog: Catalog, database_name: str) -> None:
327231
test_catalog.create_namespace(database_name)
328232
with pytest.raises(NamespaceAlreadyExistsError):
329233
test_catalog.create_namespace(database_name)
330234

331235

332236
@pytest.mark.integration
333-
@pytest.mark.parametrize(
334-
"test_catalog",
335-
[
336-
pytest.lazy_fixture("memory_catalog"),
337-
pytest.lazy_fixture("sqlite_catalog_memory"),
338-
pytest.lazy_fixture("sqlite_catalog_file"),
339-
pytest.lazy_fixture("rest_catalog"),
340-
pytest.lazy_fixture("hive_catalog"),
341-
],
342-
)
237+
@pytest.mark.parametrize("test_catalog", CATALOGS)
343238
def test_create_namepsace_if_not_exists(test_catalog: Catalog, database_name: str) -> None:
344239
test_catalog.create_namespace(database_name)
345240
test_catalog.create_namespace_if_not_exists(database_name)
346241
assert (database_name,) in test_catalog.list_namespaces()
347242

348243

349244
@pytest.mark.integration
350-
@pytest.mark.parametrize(
351-
"test_catalog",
352-
[
353-
pytest.lazy_fixture("memory_catalog"),
354-
pytest.lazy_fixture("sqlite_catalog_memory"),
355-
pytest.lazy_fixture("sqlite_catalog_file"),
356-
pytest.lazy_fixture("rest_catalog"),
357-
pytest.lazy_fixture("hive_catalog"),
358-
],
359-
)
245+
@pytest.mark.parametrize("test_catalog", CATALOGS)
360246
def test_create_namespace_with_comment(test_catalog: Catalog, database_name: str) -> None:
361247
test_properties = {
362248
"comment": "this is a test description",
@@ -369,16 +255,7 @@ def test_create_namespace_with_comment(test_catalog: Catalog, database_name: str
369255

370256

371257
@pytest.mark.integration
372-
@pytest.mark.parametrize(
373-
"test_catalog",
374-
[
375-
pytest.lazy_fixture("memory_catalog"),
376-
pytest.lazy_fixture("sqlite_catalog_memory"),
377-
pytest.lazy_fixture("sqlite_catalog_file"),
378-
pytest.lazy_fixture("rest_catalog"),
379-
pytest.lazy_fixture("hive_catalog"),
380-
],
381-
)
258+
@pytest.mark.parametrize("test_catalog", CATALOGS)
382259
def test_list_namespaces(test_catalog: Catalog, database_list: List[str]) -> None:
383260
for database_name in database_list:
384261
test_catalog.create_namespace(database_name)
@@ -389,16 +266,7 @@ def test_list_namespaces(test_catalog: Catalog, database_list: List[str]) -> Non
389266

390267

391268
@pytest.mark.integration
392-
@pytest.mark.parametrize(
393-
"test_catalog",
394-
[
395-
pytest.lazy_fixture("memory_catalog"),
396-
pytest.lazy_fixture("sqlite_catalog_memory"),
397-
pytest.lazy_fixture("sqlite_catalog_file"),
398-
pytest.lazy_fixture("rest_catalog"),
399-
pytest.lazy_fixture("hive_catalog"),
400-
],
401-
)
269+
@pytest.mark.parametrize("test_catalog", CATALOGS)
402270
def test_drop_namespace(test_catalog: Catalog, table_schema_nested: Schema, table_name: str, database_name: str) -> None:
403271
test_catalog.create_namespace(database_name)
404272
assert (database_name,) in test_catalog.list_namespaces()
@@ -411,16 +279,7 @@ def test_drop_namespace(test_catalog: Catalog, table_schema_nested: Schema, tabl
411279

412280

413281
@pytest.mark.integration
414-
@pytest.mark.parametrize(
415-
"test_catalog",
416-
[
417-
pytest.lazy_fixture("memory_catalog"),
418-
pytest.lazy_fixture("sqlite_catalog_memory"),
419-
pytest.lazy_fixture("sqlite_catalog_file"),
420-
pytest.lazy_fixture("rest_catalog"),
421-
pytest.lazy_fixture("hive_catalog"),
422-
],
423-
)
282+
@pytest.mark.parametrize("test_catalog", CATALOGS)
424283
def test_load_namespace_properties(test_catalog: Catalog, database_name: str) -> None:
425284
test_properties = {
426285
"comment": "this is a test description",
@@ -435,16 +294,7 @@ def test_load_namespace_properties(test_catalog: Catalog, database_name: str) ->
435294

436295

437296
@pytest.mark.integration
438-
@pytest.mark.parametrize(
439-
"test_catalog",
440-
[
441-
pytest.lazy_fixture("memory_catalog"),
442-
pytest.lazy_fixture("sqlite_catalog_memory"),
443-
pytest.lazy_fixture("sqlite_catalog_file"),
444-
pytest.lazy_fixture("rest_catalog"),
445-
pytest.lazy_fixture("hive_catalog"),
446-
],
447-
)
297+
@pytest.mark.parametrize("test_catalog", CATALOGS)
448298
def test_update_namespace_properties(test_catalog: Catalog, database_name: str) -> None:
449299
test_properties = {
450300
"comment": "this is a test description",

0 commit comments

Comments
 (0)