6666 NamespaceNotEmptyError ,
6767 NoSuchNamespaceError ,
6868 NoSuchTableError ,
69+ TableAlreadyExistsError ,
6970 WaitingForLockException ,
7071)
7172from pyiceberg .partitioning import PartitionField , PartitionSpec
@@ -890,6 +891,7 @@ def test_load_table_from_self_identifier(hive_table: HiveTable) -> None:
890891
891892def test_rename_table (hive_table : HiveTable ) -> None :
892893 catalog = HiveCatalog (HIVE_CATALOG_NAME , uri = HIVE_METASTORE_FAKE_URL )
894+ catalog .table_exists = MagicMock (return_value = False ) # type: ignore[method-assign]
893895
894896 renamed_table = copy .deepcopy (hive_table )
895897 renamed_table .dbName = "default"
@@ -920,6 +922,7 @@ def test_rename_table(hive_table: HiveTable) -> None:
920922
921923def test_rename_table_from_self_identifier (hive_table : HiveTable ) -> None :
922924 catalog = HiveCatalog (HIVE_CATALOG_NAME , uri = HIVE_METASTORE_FAKE_URL )
925+ catalog .table_exists = MagicMock (return_value = False ) # type: ignore[method-assign]
923926
924927 catalog ._client = MagicMock ()
925928 catalog ._get_hive_table = MagicMock (return_value = hive_table ) # type: ignore
@@ -954,6 +957,7 @@ def test_rename_table_from_self_identifier(hive_table: HiveTable) -> None:
954957
955958def test_rename_table_from_does_not_exists () -> None :
956959 catalog = HiveCatalog (HIVE_CATALOG_NAME , uri = HIVE_METASTORE_FAKE_URL )
960+ catalog .table_exists = MagicMock (return_value = False ) # type: ignore[method-assign]
957961
958962 catalog ._client = MagicMock ()
959963 catalog ._client ._hive_version = HiveVersion (4 , 0 , 0 )
@@ -967,8 +971,19 @@ def test_rename_table_from_does_not_exists() -> None:
967971 assert "Table does not exist: does_not_exists" in str (exc_info .value )
968972
969973
974+ def test_rename_table_to_table_already_exists (hive_table : HiveTable ) -> None :
975+ catalog = HiveCatalog (HIVE_CATALOG_NAME , uri = HIVE_METASTORE_FAKE_URL )
976+ catalog .load_table = MagicMock (return_value = hive_table ) # type: ignore[method-assign]
977+
978+ with pytest .raises (TableAlreadyExistsError ) as exc_info :
979+ catalog .rename_table (("default" , "some_table" ), ("default" , "new_tabl2e" ))
980+
981+ assert "Table already exists: new_tabl2e" in str (exc_info .value )
982+
983+
970984def test_rename_table_to_namespace_does_not_exists () -> None :
971985 catalog = HiveCatalog (HIVE_CATALOG_NAME , uri = HIVE_METASTORE_FAKE_URL )
986+ catalog .table_exists = MagicMock (return_value = False ) # type: ignore[method-assign]
972987
973988 catalog ._client = MagicMock ()
974989 catalog ._client ._hive_version = HiveVersion (4 , 0 , 0 )
@@ -1172,7 +1187,7 @@ def test_update_namespace_properties(hive_database: HiveDatabase) -> None:
11721187 name = "default" ,
11731188 description = None ,
11741189 locationUri = hive_database .locationUri ,
1175- parameters = {"test" : None , " label" : "core" },
1190+ parameters = {"label" : "core" },
11761191 privileges = None ,
11771192 ownerName = None ,
11781193 ownerType = 1 ,
0 commit comments