2121import datafusion .substrait
2222import pytest
2323
24-
2524IGNORED_EXPORTS = {"TableProvider" }
2625
2726# EnumType introduced in 3.11. 3.10 and prior it was called EnumMeta.
3130 from enum import EnumMeta as EnumType
3231
3332
34- def missing_exports (internal_obj , wrapped_obj ) -> None : # noqa: C901
33+ def _check_enum_exports (internal_obj , wrapped_obj ) -> None :
34+ """Check that all enum values are present in wrapped object."""
35+ expected_values = [v for v in dir (internal_obj ) if not v .startswith ("__" )]
36+ for value in expected_values :
37+ assert value in dir (wrapped_obj )
38+
39+
40+ def _check_list_attribute (internal_attr , wrapped_attr ) -> None :
41+ """Check that list attributes match between internal and wrapped objects."""
42+ assert isinstance (wrapped_attr , list )
43+
44+ # We have cases like __all__ that are a list and we want to be certain that
45+ # every value in the list in the internal object is also in the wrapper list
46+ for val in internal_attr :
47+ if isinstance (val , str ) and val in IGNORED_EXPORTS :
48+ continue
49+ if isinstance (val , str ) and val .startswith ("Raw" ):
50+ assert val [3 :] in wrapped_attr
51+ else :
52+ assert val in wrapped_attr
53+
54+
55+ def missing_exports (internal_obj , wrapped_obj ) -> None :
3556 """
3657 Identify if any of the rust exposted structs or functions do not have wrappers.
3758
@@ -44,9 +65,7 @@ def missing_exports(internal_obj, wrapped_obj) -> None: # noqa: C901
4465 # Special case enums - EnumType overrides a some of the internal functions,
4566 # so check all of the values exist and move on
4667 if isinstance (wrapped_obj , EnumType ):
47- expected_values = [v for v in dir (internal_obj ) if not v .startswith ("__" )]
48- for value in expected_values :
49- assert value in dir (wrapped_obj )
68+ _check_enum_exports (internal_obj , wrapped_obj )
5069 return
5170
5271 if "__repr__" in internal_obj .__dict__ and "__repr__" not in wrapped_obj .__dict__ :
@@ -74,17 +93,7 @@ def missing_exports(internal_obj, wrapped_obj) -> None: # noqa: C901
7493 continue
7594
7695 if isinstance (internal_attr , list ):
77- assert isinstance (wrapped_attr , list )
78-
79- # We have cases like __all__ that are a list and we want to be certain that
80- # every value in the list in the internal object is also in the wrapper list
81- for val in internal_attr :
82- if isinstance (val , str ) and val in IGNORED_EXPORTS :
83- continue
84- if isinstance (val , str ) and val .startswith ("Raw" ):
85- assert val [3 :] in wrapped_attr
86- else :
87- assert val in wrapped_attr
96+ _check_list_attribute (internal_attr , wrapped_attr )
8897 elif hasattr (internal_attr , "__dict__" ):
8998 # Check all submodules recursively
9099 missing_exports (internal_attr , wrapped_attr )
0 commit comments