iceberg-python
iceberg-python copied to clipboard
Add test to ensure every table update has corresponding `_apply_table_update` function
Pre-req: #822. This test will fail until #822 is merged
While looking at #864 and #950, I noticed that some TableUpdate classes do not have corresponding _apply_table_update function.
I think we should enforce this in tests so that any future TableUpdate have the necessary _apply_table_update to process the update.
Example
This test currently fails since RemoveSnapshotRefUpdate and RemoveSnapshotsUpdate both are missing corresponding _apply_table_update function.
Run:
poetry run pytest tests/table/test_init.py::test_table_update_have_corresponding_dispatch
================================================================== FAILURES ==================================================================
_______________________________________________ test_table_update_have_corresponding_dispatch ________________________________________________
def test_table_update_have_corresponding_dispatch() -> None:
from pyiceberg.table import TableUpdate, _apply_table_update
# every TableUpdate class should have corresponding `_apply_table_update` dispatch function
table_update_class = set(TableUpdate.__origin__.__args__) # type: ignore
dispatch_function_class = set(_apply_table_update.registry.keys())
missing_dispatch_function = table_update_class - dispatch_function_class
> assert len(missing_dispatch_function) == 0, f"Missing dispatch function for {missing_dispatch_function}"
E AssertionError: Missing dispatch function for {<class 'pyiceberg.table.RemoveSnapshotRefUpdate'>, <class 'pyiceberg.table.RemoveSnapshotsUpdate'>}
E assert 2 == 0
E + where 2 = len({<class 'pyiceberg.table.RemoveSnapshotRefUpdate'>, <class 'pyiceberg.table.RemoveSnapshotsUpdate'>})
tests/table/test_init.py:1166: AssertionError
========================================================== short test summary info ===========================================================
FAILED tests/table/test_init.py::test_table_update_have_corresponding_dispatch - AssertionError: Missing dispatch function for {<class 'pyiceberg.table.RemoveSnapshotRefUpdate'>, <class 'pyiceberg.table.RemoveSnapshots...