21
21
import datafusion .substrait
22
22
import pytest
23
23
24
-
25
24
IGNORED_EXPORTS = {"TableProvider" }
26
25
27
26
# EnumType introduced in 3.11. 3.10 and prior it was called EnumMeta.
31
30
from enum import EnumMeta as EnumType
32
31
33
32
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 :
35
56
"""
36
57
Identify if any of the rust exposted structs or functions do not have wrappers.
37
58
@@ -44,9 +65,7 @@ def missing_exports(internal_obj, wrapped_obj) -> None: # noqa: C901
44
65
# Special case enums - EnumType overrides a some of the internal functions,
45
66
# so check all of the values exist and move on
46
67
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 )
50
69
return
51
70
52
71
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
74
93
continue
75
94
76
95
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 )
88
97
elif hasattr (internal_attr , "__dict__" ):
89
98
# Check all submodules recursively
90
99
missing_exports (internal_attr , wrapped_attr )
0 commit comments