From 3507a0e256db3819ea96fd109122cc5d95ba8bdf Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Wed, 13 Mar 2024 08:51:42 -0700 Subject: [PATCH 1/2] generalize test_console --- tests/cli/test_console.py | 162 +++++++++++++++++++------------------- 1 file changed, 83 insertions(+), 79 deletions(-) diff --git a/tests/cli/test_console.py b/tests/cli/test_console.py index 3c208c0ab1..50ce20ef7e 100644 --- a/tests/cli/test_console.py +++ b/tests/cli/test_console.py @@ -24,6 +24,7 @@ from click.testing import CliRunner from pytest_mock import MockFixture +from pyiceberg.catalog import WAREHOUSE_LOCATION, Catalog from pyiceberg.cli.console import run from pyiceberg.io import WAREHOUSE from pyiceberg.partitioning import PartitionField, PartitionSpec @@ -53,7 +54,7 @@ def env_vars(mocker: MockFixture) -> None: @pytest.fixture(name="catalog") -def fixture_catalog(mocker: MockFixture, tmp_path: PosixPath) -> InMemoryCatalog: +def fixture_catalog(mocker: MockFixture, tmp_path: PosixPath) -> Catalog: in_memory_catalog = InMemoryCatalog( "test.in_memory.catalog", **{WAREHOUSE: tmp_path.absolute().as_posix(), "test.key": "test.value"} ) @@ -73,6 +74,11 @@ def mock_datetime_now(monkeypatch: pytest.MonkeyPatch) -> None: monkeypatch.setattr(datetime, "datetime", datetime_mock) +@pytest.fixture() +def mock_uuids(mocker: MockFixture) -> None: + return mocker.patch('uuid.uuid4', return_value=TEST_TABLE_UUID) + + TEST_TABLE_IDENTIFIER = ("default", "my_table") TEST_TABLE_NAMESPACE = "default" TEST_NAMESPACE_PROPERTIES = {"location": "s3://warehouse/database/location"} @@ -89,7 +95,7 @@ def mock_datetime_now(monkeypatch: pytest.MonkeyPatch) -> None: MOCK_ENVIRONMENT = {"PYICEBERG_CATALOG__PRODUCTION__URI": "test://doesnotexist"} -def test_list_root(catalog: InMemoryCatalog) -> None: +def test_list_root(catalog: Catalog) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE) runner = CliRunner() @@ -99,7 +105,7 @@ def test_list_root(catalog: InMemoryCatalog) -> None: assert TEST_TABLE_NAMESPACE in result.output -def test_list_namespace(catalog: InMemoryCatalog) -> None: +def test_list_namespace(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -114,7 +120,7 @@ def test_list_namespace(catalog: InMemoryCatalog) -> None: assert result.output == "default.my_table\n" -def test_describe_namespace(catalog: InMemoryCatalog, namespace_properties: Properties) -> None: +def test_describe_namespace(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) runner = CliRunner() @@ -124,7 +130,7 @@ def test_describe_namespace(catalog: InMemoryCatalog, namespace_properties: Prop assert result.output == "location s3://warehouse/database/location\n" -def test_describe_namespace_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_describe_namespace_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -135,12 +141,11 @@ def test_describe_namespace_does_not_exists(catalog: InMemoryCatalog) -> None: @pytest.fixture() -def test_describe_table(catalog: InMemoryCatalog, mock_datetime_now: None) -> None: +def test_describe_table(catalog: Catalog, mock_datetime_now: None) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, partition_spec=TEST_TABLE_PARTITION_SPEC, - table_uuid=TEST_TABLE_UUID, ) runner = CliRunner() @@ -169,7 +174,7 @@ def test_describe_table(catalog: InMemoryCatalog, mock_datetime_now: None) -> No ) -def test_describe_table_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_describe_table_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -178,7 +183,7 @@ def test_describe_table_does_not_exists(catalog: InMemoryCatalog) -> None: assert result.output == "Table or namespace does not exist: default.doesnotexist\n" -def test_schema(catalog: InMemoryCatalog) -> None: +def test_schema(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -197,7 +202,7 @@ def test_schema(catalog: InMemoryCatalog) -> None: ) -def test_schema_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_schema_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -206,7 +211,7 @@ def test_schema_does_not_exists(catalog: InMemoryCatalog) -> None: assert result.output == "Table does not exist: ('default', 'doesnotexist')\n" -def test_spec(catalog: InMemoryCatalog) -> None: +def test_spec(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -225,7 +230,7 @@ def test_spec(catalog: InMemoryCatalog) -> None: ) -def test_spec_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_spec_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -234,12 +239,12 @@ def test_spec_does_not_exists(catalog: InMemoryCatalog) -> None: assert result.output == "Table does not exist: ('default', 'doesnotexist')\n" -def test_uuid(catalog: InMemoryCatalog) -> None: +@pytest.fixture() +def test_uuid(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, partition_spec=TEST_TABLE_PARTITION_SPEC, - table_uuid=TEST_TABLE_UUID, ) runner = CliRunner() @@ -248,7 +253,7 @@ def test_uuid(catalog: InMemoryCatalog) -> None: assert result.output == """d20125c8-7284-442c-9aea-15fee620737c\n""" -def test_uuid_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_uuid_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -257,7 +262,7 @@ def test_uuid_does_not_exists(catalog: InMemoryCatalog) -> None: assert result.output == "Table does not exist: ('default', 'doesnotexist')\n" -def test_location(catalog: InMemoryCatalog) -> None: +def test_location(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -266,10 +271,10 @@ def test_location(catalog: InMemoryCatalog) -> None: runner = CliRunner() result = runner.invoke(run, ["location", "default.my_table"]) assert result.exit_code == 0 - assert result.output == f"""{catalog._warehouse_location}/default/my_table\n""" + assert result.output == f"""{catalog.properties.get(WAREHOUSE_LOCATION)}/default/my_table\n""" -def test_location_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_location_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -278,7 +283,7 @@ def test_location_does_not_exists(catalog: InMemoryCatalog) -> None: assert result.output == "Table does not exist: ('default', 'doesnotexist')\n" -def test_drop_table(catalog: InMemoryCatalog) -> None: +def test_drop_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -291,7 +296,7 @@ def test_drop_table(catalog: InMemoryCatalog) -> None: assert result.output == """Dropped table: default.my_table\n""" -def test_drop_table_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_drop_table_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -300,7 +305,7 @@ def test_drop_table_does_not_exists(catalog: InMemoryCatalog) -> None: assert result.output == "Table does not exist: ('default', 'doesnotexist')\n" -def test_drop_namespace(catalog: InMemoryCatalog) -> None: +def test_drop_namespace(catalog: Catalog) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE) runner = CliRunner() @@ -309,7 +314,7 @@ def test_drop_namespace(catalog: InMemoryCatalog) -> None: assert result.output == """Dropped namespace: default\n""" -def test_drop_namespace_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_drop_namespace_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -334,7 +339,7 @@ def test_create_namespace_already_exists(catalog: InMemoryCatalog) -> None: assert result.output == "Namespace already exists: ('default',)\n" -def test_rename_table(catalog: InMemoryCatalog) -> None: +def test_rename_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -347,7 +352,7 @@ def test_rename_table(catalog: InMemoryCatalog) -> None: assert result.output == """Renamed table from default.my_table to default.my_new_table\n""" -def test_rename_table_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_rename_table_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -356,7 +361,7 @@ def test_rename_table_does_not_exists(catalog: InMemoryCatalog) -> None: assert result.output == "Table does not exist: ('default', 'doesnotexist')\n" -def test_properties_get_table(catalog: InMemoryCatalog) -> None: +def test_properties_get_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -370,7 +375,7 @@ def test_properties_get_table(catalog: InMemoryCatalog) -> None: assert result.output == "read.split.target.size 134217728\n" -def test_properties_get_table_specific_property(catalog: InMemoryCatalog) -> None: +def test_properties_get_table_specific_property(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -384,7 +389,7 @@ def test_properties_get_table_specific_property(catalog: InMemoryCatalog) -> Non assert result.output == "134217728\n" -def test_properties_get_table_specific_property_that_doesnt_exist(catalog: InMemoryCatalog) -> None: +def test_properties_get_table_specific_property_that_doesnt_exist(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -398,7 +403,7 @@ def test_properties_get_table_specific_property_that_doesnt_exist(catalog: InMem assert result.output == "Could not find property doesnotexist on table default.my_table\n" -def test_properties_get_table_does_not_exist(catalog: InMemoryCatalog) -> None: +def test_properties_get_table_does_not_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -407,7 +412,7 @@ def test_properties_get_table_does_not_exist(catalog: InMemoryCatalog) -> None: assert result.output == "Table does not exist: ('doesnotexist',)\n" -def test_properties_get_namespace(catalog: InMemoryCatalog, namespace_properties: Properties) -> None: +def test_properties_get_namespace(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) runner = CliRunner() @@ -416,7 +421,7 @@ def test_properties_get_namespace(catalog: InMemoryCatalog, namespace_properties assert result.output == "location s3://warehouse/database/location\n" -def test_properties_get_namespace_specific_property(catalog: InMemoryCatalog, namespace_properties: Properties) -> None: +def test_properties_get_namespace_specific_property(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) runner = CliRunner() @@ -425,7 +430,7 @@ def test_properties_get_namespace_specific_property(catalog: InMemoryCatalog, na assert result.output == "s3://warehouse/database/location\n" -def test_properties_get_namespace_does_not_exist(catalog: InMemoryCatalog, namespace_properties: Properties) -> None: +def test_properties_get_namespace_does_not_exist(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) runner = CliRunner() @@ -434,7 +439,7 @@ def test_properties_get_namespace_does_not_exist(catalog: InMemoryCatalog, names assert result.output == "Namespace does not exist: ('doesnotexist',)\n" -def test_properties_set_namespace(catalog: InMemoryCatalog, namespace_properties: Properties) -> None: +def test_properties_set_namespace(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) runner = CliRunner() @@ -443,7 +448,7 @@ def test_properties_set_namespace(catalog: InMemoryCatalog, namespace_properties assert result.output == "Updated location on default\n" -def test_properties_set_namespace_that_doesnt_exist(catalog: InMemoryCatalog) -> None: +def test_properties_set_namespace_that_doesnt_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -452,7 +457,7 @@ def test_properties_set_namespace_that_doesnt_exist(catalog: InMemoryCatalog) -> assert result.output == "Namespace does not exist: ('doesnotexist',)\n" -def test_properties_set_table(catalog: InMemoryCatalog) -> None: +def test_properties_set_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -465,7 +470,7 @@ def test_properties_set_table(catalog: InMemoryCatalog) -> None: assert "Writing is WIP" in result.output -def test_properties_set_table_does_not_exist(catalog: InMemoryCatalog) -> None: +def test_properties_set_table_does_not_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -474,7 +479,7 @@ def test_properties_set_table_does_not_exist(catalog: InMemoryCatalog) -> None: assert result.output == "Table does not exist: ('default', 'doesnotexist')\n" -def test_properties_remove_namespace(catalog: InMemoryCatalog, namespace_properties: Properties) -> None: +def test_properties_remove_namespace(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) runner = CliRunner() @@ -483,7 +488,7 @@ def test_properties_remove_namespace(catalog: InMemoryCatalog, namespace_propert assert result.output == "Property location removed from default\n" -def test_properties_remove_namespace_that_doesnt_exist(catalog: InMemoryCatalog) -> None: +def test_properties_remove_namespace_that_doesnt_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -492,7 +497,7 @@ def test_properties_remove_namespace_that_doesnt_exist(catalog: InMemoryCatalog) assert result.output == "Namespace does not exist: ('doesnotexist',)\n" -def test_properties_remove_table(catalog: InMemoryCatalog) -> None: +def test_properties_remove_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -506,7 +511,7 @@ def test_properties_remove_table(catalog: InMemoryCatalog) -> None: assert "Writing is WIP" in result.output -def test_properties_remove_table_property_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_properties_remove_table_property_does_not_exists(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -519,7 +524,7 @@ def test_properties_remove_table_property_does_not_exists(catalog: InMemoryCatal assert result.output == "Property doesnotexist does not exist on default.my_table\n" -def test_properties_remove_table_does_not_exist(catalog: InMemoryCatalog) -> None: +def test_properties_remove_table_does_not_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -528,7 +533,7 @@ def test_properties_remove_table_does_not_exist(catalog: InMemoryCatalog) -> Non assert result.output == "Table does not exist: ('default', 'doesnotexist')\n" -def test_json_list_root(catalog: InMemoryCatalog) -> None: +def test_json_list_root(catalog: Catalog) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE) runner = CliRunner() @@ -537,7 +542,7 @@ def test_json_list_root(catalog: InMemoryCatalog) -> None: assert result.output == """["default"]\n""" -def test_json_list_namespace(catalog: InMemoryCatalog) -> None: +def test_json_list_namespace(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -550,7 +555,7 @@ def test_json_list_namespace(catalog: InMemoryCatalog) -> None: assert result.output == """["default.my_table"]\n""" -def test_json_describe_namespace(catalog: InMemoryCatalog, namespace_properties: Properties) -> None: +def test_json_describe_namespace(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) runner = CliRunner() @@ -559,7 +564,7 @@ def test_json_describe_namespace(catalog: InMemoryCatalog, namespace_properties: assert result.output == """{"location": "s3://warehouse/database/location"}\n""" -def test_json_describe_namespace_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_json_describe_namespace_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -569,12 +574,11 @@ def test_json_describe_namespace_does_not_exists(catalog: InMemoryCatalog) -> No @pytest.fixture() -def test_json_describe_table(catalog: InMemoryCatalog, mock_datetime_now: None) -> None: +def test_json_describe_table(catalog: Catalog, mock_datetime_now: None) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, partition_spec=TEST_TABLE_PARTITION_SPEC, - table_uuid=TEST_TABLE_UUID, ) runner = CliRunner() @@ -586,7 +590,7 @@ def test_json_describe_table(catalog: InMemoryCatalog, mock_datetime_now: None) ) -def test_json_describe_table_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_json_describe_table_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -598,7 +602,7 @@ def test_json_describe_table_does_not_exists(catalog: InMemoryCatalog) -> None: ) -def test_json_schema(catalog: InMemoryCatalog) -> None: +def test_json_schema(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -614,7 +618,7 @@ def test_json_schema(catalog: InMemoryCatalog) -> None: ) -def test_json_schema_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_json_schema_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -623,7 +627,7 @@ def test_json_schema_does_not_exists(catalog: InMemoryCatalog) -> None: assert result.output == """{"type": "NoSuchTableError", "message": "Table does not exist: ('default', 'doesnotexist')"}\n""" -def test_json_spec(catalog: InMemoryCatalog) -> None: +def test_json_spec(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -636,7 +640,7 @@ def test_json_spec(catalog: InMemoryCatalog) -> None: assert result.output == """{"spec-id":0,"fields":[{"source-id":1,"field-id":1000,"transform":"identity","name":"x"}]}\n""" -def test_json_spec_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_json_spec_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -645,12 +649,12 @@ def test_json_spec_does_not_exists(catalog: InMemoryCatalog) -> None: assert result.output == """{"type": "NoSuchTableError", "message": "Table does not exist: ('default', 'doesnotexist')"}\n""" -def test_json_uuid(catalog: InMemoryCatalog) -> None: +@pytest.fixture() +def test_json_uuid(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, partition_spec=TEST_TABLE_PARTITION_SPEC, - table_uuid=TEST_TABLE_UUID, ) runner = CliRunner() @@ -659,7 +663,7 @@ def test_json_uuid(catalog: InMemoryCatalog) -> None: assert result.output == """{"uuid": "d20125c8-7284-442c-9aea-15fee620737c"}\n""" -def test_json_uuid_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_json_uuid_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -668,7 +672,7 @@ def test_json_uuid_does_not_exists(catalog: InMemoryCatalog) -> None: assert result.output == """{"type": "NoSuchTableError", "message": "Table does not exist: ('default', 'doesnotexist')"}\n""" -def test_json_location(catalog: InMemoryCatalog) -> None: +def test_json_location(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -678,10 +682,10 @@ def test_json_location(catalog: InMemoryCatalog) -> None: runner = CliRunner() result = runner.invoke(run, ["--output=json", "location", "default.my_table"]) assert result.exit_code == 0 - assert result.output == f'"{catalog._warehouse_location}/default/my_table"\n' + assert result.output == f'"{catalog.properties.get(WAREHOUSE_LOCATION)}/default/my_table"\n' -def test_json_location_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_json_location_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -690,7 +694,7 @@ def test_json_location_does_not_exists(catalog: InMemoryCatalog) -> None: assert result.output == """{"type": "NoSuchTableError", "message": "Table does not exist: ('default', 'doesnotexist')"}\n""" -def test_json_drop_table(catalog: InMemoryCatalog) -> None: +def test_json_drop_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -703,7 +707,7 @@ def test_json_drop_table(catalog: InMemoryCatalog) -> None: assert result.output == """"Dropped table: default.my_table"\n""" -def test_json_drop_table_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_json_drop_table_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -712,7 +716,7 @@ def test_json_drop_table_does_not_exists(catalog: InMemoryCatalog) -> None: assert result.output == """{"type": "NoSuchTableError", "message": "Table does not exist: ('default', 'doesnotexist')"}\n""" -def test_json_drop_namespace(catalog: InMemoryCatalog) -> None: +def test_json_drop_namespace(catalog: Catalog) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE) runner = CliRunner() @@ -721,7 +725,7 @@ def test_json_drop_namespace(catalog: InMemoryCatalog) -> None: assert result.output == """"Dropped namespace: default"\n""" -def test_json_drop_namespace_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_json_drop_namespace_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -730,7 +734,7 @@ def test_json_drop_namespace_does_not_exists(catalog: InMemoryCatalog) -> None: assert result.output == """{"type": "NoSuchNamespaceError", "message": "Namespace does not exist: ('doesnotexist',)"}\n""" -def test_json_rename_table(catalog: InMemoryCatalog) -> None: +def test_json_rename_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -743,7 +747,7 @@ def test_json_rename_table(catalog: InMemoryCatalog) -> None: assert result.output == """"Renamed table from default.my_table to default.my_new_table"\n""" -def test_json_rename_table_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_json_rename_table_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -752,7 +756,7 @@ def test_json_rename_table_does_not_exists(catalog: InMemoryCatalog) -> None: assert result.output == """{"type": "NoSuchTableError", "message": "Table does not exist: ('default', 'doesnotexist')"}\n""" -def test_json_properties_get_table(catalog: InMemoryCatalog) -> None: +def test_json_properties_get_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -766,7 +770,7 @@ def test_json_properties_get_table(catalog: InMemoryCatalog) -> None: assert result.output == """{"read.split.target.size": "134217728"}\n""" -def test_json_properties_get_table_specific_property(catalog: InMemoryCatalog) -> None: +def test_json_properties_get_table_specific_property(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -780,7 +784,7 @@ def test_json_properties_get_table_specific_property(catalog: InMemoryCatalog) - assert result.output == """"134217728"\n""" -def test_json_properties_get_table_specific_property_that_doesnt_exist(catalog: InMemoryCatalog) -> None: +def test_json_properties_get_table_specific_property_that_doesnt_exist(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -797,7 +801,7 @@ def test_json_properties_get_table_specific_property_that_doesnt_exist(catalog: ) -def test_json_properties_get_table_does_not_exist(catalog: InMemoryCatalog) -> None: +def test_json_properties_get_table_does_not_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -806,7 +810,7 @@ def test_json_properties_get_table_does_not_exist(catalog: InMemoryCatalog) -> N assert result.output == """{"type": "NoSuchTableError", "message": "Table does not exist: ('doesnotexist',)"}\n""" -def test_json_properties_get_namespace(catalog: InMemoryCatalog, namespace_properties: Properties) -> None: +def test_json_properties_get_namespace(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) runner = CliRunner() @@ -815,7 +819,7 @@ def test_json_properties_get_namespace(catalog: InMemoryCatalog, namespace_prope assert result.output == """{"location": "s3://warehouse/database/location"}\n""" -def test_json_properties_get_namespace_specific_property(catalog: InMemoryCatalog, namespace_properties: Properties) -> None: +def test_json_properties_get_namespace_specific_property(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) runner = CliRunner() @@ -824,7 +828,7 @@ def test_json_properties_get_namespace_specific_property(catalog: InMemoryCatalo assert result.output == """"s3://warehouse/database/location"\n""" -def test_json_properties_get_namespace_does_not_exist(catalog: InMemoryCatalog) -> None: +def test_json_properties_get_namespace_does_not_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -833,7 +837,7 @@ def test_json_properties_get_namespace_does_not_exist(catalog: InMemoryCatalog) assert result.output == """{"type": "NoSuchNamespaceError", "message": "Namespace does not exist: ('doesnotexist',)"}\n""" -def test_json_properties_set_namespace(catalog: InMemoryCatalog, namespace_properties: Properties) -> None: +def test_json_properties_set_namespace(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) runner = CliRunner() @@ -842,7 +846,7 @@ def test_json_properties_set_namespace(catalog: InMemoryCatalog, namespace_prope assert result.output == """"Updated location on default"\n""" -def test_json_properties_set_namespace_that_doesnt_exist(catalog: InMemoryCatalog) -> None: +def test_json_properties_set_namespace_that_doesnt_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -853,7 +857,7 @@ def test_json_properties_set_namespace_that_doesnt_exist(catalog: InMemoryCatalo assert result.output == """{"type": "NoSuchNamespaceError", "message": "Namespace does not exist: ('doesnotexist',)"}\n""" -def test_json_properties_set_table(catalog: InMemoryCatalog) -> None: +def test_json_properties_set_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -869,7 +873,7 @@ def test_json_properties_set_table(catalog: InMemoryCatalog) -> None: assert "Writing is WIP" in result.output -def test_json_properties_set_table_does_not_exist(catalog: InMemoryCatalog) -> None: +def test_json_properties_set_table_does_not_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -880,7 +884,7 @@ def test_json_properties_set_table_does_not_exist(catalog: InMemoryCatalog) -> N assert result.output == """{"type": "NoSuchTableError", "message": "Table does not exist: ('default', 'doesnotexist')"}\n""" -def test_json_properties_remove_namespace(catalog: InMemoryCatalog, namespace_properties: Properties) -> None: +def test_json_properties_remove_namespace(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) runner = CliRunner() @@ -889,7 +893,7 @@ def test_json_properties_remove_namespace(catalog: InMemoryCatalog, namespace_pr assert result.output == """"Property location removed from default"\n""" -def test_json_properties_remove_namespace_that_doesnt_exist(catalog: InMemoryCatalog) -> None: +def test_json_properties_remove_namespace_that_doesnt_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() @@ -898,7 +902,7 @@ def test_json_properties_remove_namespace_that_doesnt_exist(catalog: InMemoryCat assert result.output == """{"type": "NoSuchNamespaceError", "message": "Namespace does not exist: ('doesnotexist',)"}\n""" -def test_json_properties_remove_table(catalog: InMemoryCatalog) -> None: +def test_json_properties_remove_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -912,7 +916,7 @@ def test_json_properties_remove_table(catalog: InMemoryCatalog) -> None: assert "Writing is WIP" in result.output -def test_json_properties_remove_table_property_does_not_exists(catalog: InMemoryCatalog) -> None: +def test_json_properties_remove_table_property_does_not_exists(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, schema=TEST_TABLE_SCHEMA, @@ -929,7 +933,7 @@ def test_json_properties_remove_table_property_does_not_exists(catalog: InMemory ) -def test_json_properties_remove_table_does_not_exist(catalog: InMemoryCatalog) -> None: +def test_json_properties_remove_table_does_not_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument runner = CliRunner() From 9271031cfd15369a3bde77136351859e2c6b81e9 Mon Sep 17 00:00:00 2001 From: Kevin Liu Date: Wed, 13 Mar 2024 08:43:59 -0700 Subject: [PATCH 2/2] parameterize test_console --- tests/cli/test_console.py | 546 +++++++++++++++++++++++++++++++++++++- 1 file changed, 538 insertions(+), 8 deletions(-) diff --git a/tests/cli/test_console.py b/tests/cli/test_console.py index 50ce20ef7e..e1a541f2c1 100644 --- a/tests/cli/test_console.py +++ b/tests/cli/test_console.py @@ -17,14 +17,17 @@ import datetime import os import uuid -from pathlib import PosixPath +from pathlib import Path +from typing import Generator from unittest.mock import MagicMock import pytest from click.testing import CliRunner +from pytest_lazyfixture import lazy_fixture from pytest_mock import MockFixture from pyiceberg.catalog import WAREHOUSE_LOCATION, Catalog +from pyiceberg.catalog.sql import SqlCatalog from pyiceberg.cli.console import run from pyiceberg.io import WAREHOUSE from pyiceberg.partitioning import PartitionField, PartitionSpec @@ -53,13 +56,22 @@ def env_vars(mocker: MockFixture) -> None: mocker.patch.dict(os.environ, MOCK_ENVIRONMENT) -@pytest.fixture(name="catalog") -def fixture_catalog(mocker: MockFixture, tmp_path: PosixPath) -> Catalog: - in_memory_catalog = InMemoryCatalog( - "test.in_memory.catalog", **{WAREHOUSE: tmp_path.absolute().as_posix(), "test.key": "test.value"} - ) - mocker.patch("pyiceberg.cli.console.load_catalog", return_value=in_memory_catalog) - return in_memory_catalog +@pytest.fixture(scope="function") +def catalog_memory(mocker: MockFixture, warehouse: Path) -> Generator[SqlCatalog, None, None]: + catalog = InMemoryCatalog("test.in_memory.catalog", **{WAREHOUSE: str(warehouse)}) + mocker.patch("pyiceberg.cli.console.load_catalog", return_value=catalog) + yield catalog + + +@pytest.fixture(scope="function") +def catalog_sqlite(mocker: MockFixture, warehouse: Path) -> Generator[SqlCatalog, None, None]: + props = { + "uri": "sqlite:///:memory:", + "warehouse": f"file://{warehouse}", + } + catalog = SqlCatalog("test_sql_catalog", **props) + mocker.patch("pyiceberg.cli.console.load_catalog", return_value=catalog) + yield catalog @pytest.fixture(name="namespace_properties") @@ -95,6 +107,13 @@ def mock_uuids(mocker: MockFixture) -> None: MOCK_ENVIRONMENT = {"PYICEBERG_CATALOG__PRODUCTION__URI": "test://doesnotexist"} +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_list_root(catalog: Catalog) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE) @@ -105,6 +124,13 @@ def test_list_root(catalog: Catalog) -> None: assert TEST_TABLE_NAMESPACE in result.output +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_list_namespace(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -120,6 +146,13 @@ def test_list_namespace(catalog: Catalog) -> None: assert result.output == "default.my_table\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_describe_namespace(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) @@ -130,6 +163,13 @@ def test_describe_namespace(catalog: Catalog, namespace_properties: Properties) assert result.output == "location s3://warehouse/database/location\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_describe_namespace_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -141,6 +181,13 @@ def test_describe_namespace_does_not_exists(catalog: Catalog) -> None: @pytest.fixture() +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_describe_table(catalog: Catalog, mock_datetime_now: None) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -174,6 +221,13 @@ def test_describe_table(catalog: Catalog, mock_datetime_now: None) -> None: ) +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_describe_table_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -183,6 +237,13 @@ def test_describe_table_does_not_exists(catalog: Catalog) -> None: assert result.output == "Table or namespace does not exist: default.doesnotexist\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_schema(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -202,6 +263,13 @@ def test_schema(catalog: Catalog) -> None: ) +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_schema_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -211,6 +279,13 @@ def test_schema_does_not_exists(catalog: Catalog) -> None: assert result.output == "Table does not exist: ('default', 'doesnotexist')\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_spec(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -230,6 +305,13 @@ def test_spec(catalog: Catalog) -> None: ) +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_spec_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -240,6 +322,13 @@ def test_spec_does_not_exists(catalog: Catalog) -> None: @pytest.fixture() +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_uuid(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -253,6 +342,13 @@ def test_uuid(catalog: Catalog) -> None: assert result.output == """d20125c8-7284-442c-9aea-15fee620737c\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_uuid_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -262,6 +358,13 @@ def test_uuid_does_not_exists(catalog: Catalog) -> None: assert result.output == "Table does not exist: ('default', 'doesnotexist')\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_location(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -274,6 +377,13 @@ def test_location(catalog: Catalog) -> None: assert result.output == f"""{catalog.properties.get(WAREHOUSE_LOCATION)}/default/my_table\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_location_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -283,6 +393,13 @@ def test_location_does_not_exists(catalog: Catalog) -> None: assert result.output == "Table does not exist: ('default', 'doesnotexist')\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_drop_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -296,6 +413,13 @@ def test_drop_table(catalog: Catalog) -> None: assert result.output == """Dropped table: default.my_table\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_drop_table_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -305,6 +429,13 @@ def test_drop_table_does_not_exists(catalog: Catalog) -> None: assert result.output == "Table does not exist: ('default', 'doesnotexist')\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_drop_namespace(catalog: Catalog) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE) @@ -314,6 +445,13 @@ def test_drop_namespace(catalog: Catalog) -> None: assert result.output == """Dropped namespace: default\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_drop_namespace_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -323,6 +461,13 @@ def test_drop_namespace_does_not_exists(catalog: Catalog) -> None: assert result.output == "Namespace does not exist: ('doesnotexist',)\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_create_namespace(catalog: InMemoryCatalog) -> None: runner = CliRunner() result = runner.invoke(run, ["create", "namespace", TEST_TABLE_NAMESPACE]) @@ -330,6 +475,13 @@ def test_create_namespace(catalog: InMemoryCatalog) -> None: assert result.output == """Created namespace: default\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_create_namespace_already_exists(catalog: InMemoryCatalog) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE) @@ -339,6 +491,13 @@ def test_create_namespace_already_exists(catalog: InMemoryCatalog) -> None: assert result.output == "Namespace already exists: ('default',)\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_rename_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -352,6 +511,13 @@ def test_rename_table(catalog: Catalog) -> None: assert result.output == """Renamed table from default.my_table to default.my_new_table\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_rename_table_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -361,6 +527,13 @@ def test_rename_table_does_not_exists(catalog: Catalog) -> None: assert result.output == "Table does not exist: ('default', 'doesnotexist')\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_properties_get_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -375,6 +548,13 @@ def test_properties_get_table(catalog: Catalog) -> None: assert result.output == "read.split.target.size 134217728\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_properties_get_table_specific_property(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -389,6 +569,13 @@ def test_properties_get_table_specific_property(catalog: Catalog) -> None: assert result.output == "134217728\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_properties_get_table_specific_property_that_doesnt_exist(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -403,6 +590,13 @@ def test_properties_get_table_specific_property_that_doesnt_exist(catalog: Catal assert result.output == "Could not find property doesnotexist on table default.my_table\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_properties_get_table_does_not_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -412,6 +606,13 @@ def test_properties_get_table_does_not_exist(catalog: Catalog) -> None: assert result.output == "Table does not exist: ('doesnotexist',)\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_properties_get_namespace(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) @@ -421,6 +622,13 @@ def test_properties_get_namespace(catalog: Catalog, namespace_properties: Proper assert result.output == "location s3://warehouse/database/location\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_properties_get_namespace_specific_property(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) @@ -430,6 +638,13 @@ def test_properties_get_namespace_specific_property(catalog: Catalog, namespace_ assert result.output == "s3://warehouse/database/location\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_properties_get_namespace_does_not_exist(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) @@ -439,6 +654,13 @@ def test_properties_get_namespace_does_not_exist(catalog: Catalog, namespace_pro assert result.output == "Namespace does not exist: ('doesnotexist',)\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_properties_set_namespace(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) @@ -448,6 +670,13 @@ def test_properties_set_namespace(catalog: Catalog, namespace_properties: Proper assert result.output == "Updated location on default\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_properties_set_namespace_that_doesnt_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -457,6 +686,13 @@ def test_properties_set_namespace_that_doesnt_exist(catalog: Catalog) -> None: assert result.output == "Namespace does not exist: ('doesnotexist',)\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_properties_set_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -470,6 +706,13 @@ def test_properties_set_table(catalog: Catalog) -> None: assert "Writing is WIP" in result.output +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_properties_set_table_does_not_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -479,6 +722,13 @@ def test_properties_set_table_does_not_exist(catalog: Catalog) -> None: assert result.output == "Table does not exist: ('default', 'doesnotexist')\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_properties_remove_namespace(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) @@ -488,6 +738,13 @@ def test_properties_remove_namespace(catalog: Catalog, namespace_properties: Pro assert result.output == "Property location removed from default\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_properties_remove_namespace_that_doesnt_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -497,6 +754,13 @@ def test_properties_remove_namespace_that_doesnt_exist(catalog: Catalog) -> None assert result.output == "Namespace does not exist: ('doesnotexist',)\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_properties_remove_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -511,6 +775,13 @@ def test_properties_remove_table(catalog: Catalog) -> None: assert "Writing is WIP" in result.output +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_properties_remove_table_property_does_not_exists(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -524,6 +795,13 @@ def test_properties_remove_table_property_does_not_exists(catalog: Catalog) -> N assert result.output == "Property doesnotexist does not exist on default.my_table\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_properties_remove_table_does_not_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -533,6 +811,13 @@ def test_properties_remove_table_does_not_exist(catalog: Catalog) -> None: assert result.output == "Table does not exist: ('default', 'doesnotexist')\n" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_list_root(catalog: Catalog) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE) @@ -542,6 +827,13 @@ def test_json_list_root(catalog: Catalog) -> None: assert result.output == """["default"]\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_list_namespace(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -555,6 +847,13 @@ def test_json_list_namespace(catalog: Catalog) -> None: assert result.output == """["default.my_table"]\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_describe_namespace(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) @@ -564,6 +863,13 @@ def test_json_describe_namespace(catalog: Catalog, namespace_properties: Propert assert result.output == """{"location": "s3://warehouse/database/location"}\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_describe_namespace_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -574,6 +880,13 @@ def test_json_describe_namespace_does_not_exists(catalog: Catalog) -> None: @pytest.fixture() +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_describe_table(catalog: Catalog, mock_datetime_now: None) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -590,6 +903,13 @@ def test_json_describe_table(catalog: Catalog, mock_datetime_now: None) -> None: ) +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_describe_table_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -602,6 +922,13 @@ def test_json_describe_table_does_not_exists(catalog: Catalog) -> None: ) +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_schema(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -618,6 +945,13 @@ def test_json_schema(catalog: Catalog) -> None: ) +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_schema_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -627,6 +961,13 @@ def test_json_schema_does_not_exists(catalog: Catalog) -> None: assert result.output == """{"type": "NoSuchTableError", "message": "Table does not exist: ('default', 'doesnotexist')"}\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_spec(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -640,6 +981,13 @@ def test_json_spec(catalog: Catalog) -> None: assert result.output == """{"spec-id":0,"fields":[{"source-id":1,"field-id":1000,"transform":"identity","name":"x"}]}\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_spec_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -650,6 +998,13 @@ def test_json_spec_does_not_exists(catalog: Catalog) -> None: @pytest.fixture() +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_uuid(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -663,6 +1018,13 @@ def test_json_uuid(catalog: Catalog) -> None: assert result.output == """{"uuid": "d20125c8-7284-442c-9aea-15fee620737c"}\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_uuid_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -672,6 +1034,13 @@ def test_json_uuid_does_not_exists(catalog: Catalog) -> None: assert result.output == """{"type": "NoSuchTableError", "message": "Table does not exist: ('default', 'doesnotexist')"}\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_location(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -685,6 +1054,13 @@ def test_json_location(catalog: Catalog) -> None: assert result.output == f'"{catalog.properties.get(WAREHOUSE_LOCATION)}/default/my_table"\n' +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_location_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -694,6 +1070,13 @@ def test_json_location_does_not_exists(catalog: Catalog) -> None: assert result.output == """{"type": "NoSuchTableError", "message": "Table does not exist: ('default', 'doesnotexist')"}\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_drop_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -707,6 +1090,13 @@ def test_json_drop_table(catalog: Catalog) -> None: assert result.output == """"Dropped table: default.my_table"\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_drop_table_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -716,6 +1106,13 @@ def test_json_drop_table_does_not_exists(catalog: Catalog) -> None: assert result.output == """{"type": "NoSuchTableError", "message": "Table does not exist: ('default', 'doesnotexist')"}\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_drop_namespace(catalog: Catalog) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE) @@ -725,6 +1122,13 @@ def test_json_drop_namespace(catalog: Catalog) -> None: assert result.output == """"Dropped namespace: default"\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_drop_namespace_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -734,6 +1138,13 @@ def test_json_drop_namespace_does_not_exists(catalog: Catalog) -> None: assert result.output == """{"type": "NoSuchNamespaceError", "message": "Namespace does not exist: ('doesnotexist',)"}\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_rename_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -747,6 +1158,13 @@ def test_json_rename_table(catalog: Catalog) -> None: assert result.output == """"Renamed table from default.my_table to default.my_new_table"\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_rename_table_does_not_exists(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -756,6 +1174,13 @@ def test_json_rename_table_does_not_exists(catalog: Catalog) -> None: assert result.output == """{"type": "NoSuchTableError", "message": "Table does not exist: ('default', 'doesnotexist')"}\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_properties_get_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -770,6 +1195,13 @@ def test_json_properties_get_table(catalog: Catalog) -> None: assert result.output == """{"read.split.target.size": "134217728"}\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_properties_get_table_specific_property(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -784,6 +1216,13 @@ def test_json_properties_get_table_specific_property(catalog: Catalog) -> None: assert result.output == """"134217728"\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_properties_get_table_specific_property_that_doesnt_exist(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -801,6 +1240,13 @@ def test_json_properties_get_table_specific_property_that_doesnt_exist(catalog: ) +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_properties_get_table_does_not_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -810,6 +1256,13 @@ def test_json_properties_get_table_does_not_exist(catalog: Catalog) -> None: assert result.output == """{"type": "NoSuchTableError", "message": "Table does not exist: ('doesnotexist',)"}\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_properties_get_namespace(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) @@ -819,6 +1272,13 @@ def test_json_properties_get_namespace(catalog: Catalog, namespace_properties: P assert result.output == """{"location": "s3://warehouse/database/location"}\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_properties_get_namespace_specific_property(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) @@ -828,6 +1288,13 @@ def test_json_properties_get_namespace_specific_property(catalog: Catalog, names assert result.output == """"s3://warehouse/database/location"\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_properties_get_namespace_does_not_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -837,6 +1304,13 @@ def test_json_properties_get_namespace_does_not_exist(catalog: Catalog) -> None: assert result.output == """{"type": "NoSuchNamespaceError", "message": "Namespace does not exist: ('doesnotexist',)"}\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_properties_set_namespace(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) @@ -846,6 +1320,13 @@ def test_json_properties_set_namespace(catalog: Catalog, namespace_properties: P assert result.output == """"Updated location on default"\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_properties_set_namespace_that_doesnt_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -857,6 +1338,13 @@ def test_json_properties_set_namespace_that_doesnt_exist(catalog: Catalog) -> No assert result.output == """{"type": "NoSuchNamespaceError", "message": "Namespace does not exist: ('doesnotexist',)"}\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_properties_set_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -873,6 +1361,13 @@ def test_json_properties_set_table(catalog: Catalog) -> None: assert "Writing is WIP" in result.output +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_properties_set_table_does_not_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -884,6 +1379,13 @@ def test_json_properties_set_table_does_not_exist(catalog: Catalog) -> None: assert result.output == """{"type": "NoSuchTableError", "message": "Table does not exist: ('default', 'doesnotexist')"}\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_properties_remove_namespace(catalog: Catalog, namespace_properties: Properties) -> None: catalog.create_namespace(TEST_TABLE_NAMESPACE, namespace_properties) @@ -893,6 +1395,13 @@ def test_json_properties_remove_namespace(catalog: Catalog, namespace_properties assert result.output == """"Property location removed from default"\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_properties_remove_namespace_that_doesnt_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument @@ -902,6 +1411,13 @@ def test_json_properties_remove_namespace_that_doesnt_exist(catalog: Catalog) -> assert result.output == """{"type": "NoSuchNamespaceError", "message": "Namespace does not exist: ('doesnotexist',)"}\n""" +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_properties_remove_table(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -916,6 +1432,13 @@ def test_json_properties_remove_table(catalog: Catalog) -> None: assert "Writing is WIP" in result.output +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_properties_remove_table_property_does_not_exists(catalog: Catalog) -> None: catalog.create_table( identifier=TEST_TABLE_IDENTIFIER, @@ -933,6 +1456,13 @@ def test_json_properties_remove_table_property_does_not_exists(catalog: Catalog) ) +@pytest.mark.parametrize( + 'catalog', + [ + lazy_fixture('catalog_memory'), + lazy_fixture('catalog_sqlite'), + ], +) def test_json_properties_remove_table_does_not_exist(catalog: Catalog) -> None: # pylint: disable=unused-argument