1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-12-21 04:23:49 +03:00

sanitytest: move class identification into a helper method

This is a step towards turning the sanitytest.py file into a normal
python unittest.

Best viewed with the '-b' flag to diff.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé
2022-03-22 17:52:55 +00:00
parent f850a9f9e6
commit 9fb3a9b234

View File

@@ -79,12 +79,13 @@ for n in tree.xpath('/api/files/file/exports[@type="enum"]/@symbol'):
continue continue
wantenums.append(n) wantenums.append(n)
# Phase 2: Identify all classes and methods in the 'libvirt' python module # Identify all classes and methods in the 'libvirt' python module
gotenums = [] # type: List[str] def identify_class_methods(wantenums, enumvals):
gottypes = [] # type: List[str] gotenums = [] # type: List[str]
gotfunctions = {"libvirt": []} # type: Dict[str, List[str]] gottypes = [] # type: List[str]
gotfunctions = {"libvirt": []} # type: Dict[str, List[str]]
for name in dir(libvirt): for name in dir(libvirt):
if name.startswith('_'): if name.startswith('_'):
continue continue
thing = getattr(libvirt, name) thing = getattr(libvirt, name)
@@ -100,14 +101,14 @@ for name in dir(libvirt):
elif callable(thing): elif callable(thing):
gotfunctions["libvirt"].append(name) gotfunctions["libvirt"].append(name)
for enum in wantenums: for enum in wantenums:
if enum not in gotenums: if enum not in gotenums:
fail = True fail = True
for typ, enumval in enumvals.items(): for typ, enumval in enumvals.items():
if enum in enumval: if enum in enumval:
print("FAIL Missing exported enum %s of type %s" % (enum, typ)) raise Exception("Missing exported enum %s of type %s" % (enum, typ))
for klassname in gottypes: for klassname in gottypes:
klassobj = getattr(libvirt, klassname) klassobj = getattr(libvirt, klassname)
for name in dir(klassobj): for name in dir(klassobj):
if name.startswith('_'): if name.startswith('_'):
@@ -118,6 +119,8 @@ for klassname in gottypes:
if callable(thing): if callable(thing):
gotfunctions[klassname].append(name) gotfunctions[klassname].append(name)
return gotfunctions, gottypes
# First cut at mapping of C APIs to python classes + methods # First cut at mapping of C APIs to python classes + methods
def basic_class_method_mapping(wantfunctions, gottypes): def basic_class_method_mapping(wantfunctions, gottypes):
@@ -379,6 +382,7 @@ def validate_c_api_bindings_present(finalklassmap):
try: try:
gotfunctions, gottypes = identify_class_methods(wantenums, enumvals)
basicklassmap = basic_class_method_mapping(wantfunctions, gottypes) basicklassmap = basic_class_method_mapping(wantfunctions, gottypes)
finalklassmap = fixup_class_method_mapping(basicklassmap) finalklassmap = fixup_class_method_mapping(basicklassmap)
usedfunctions = validate_c_to_python_api_mappings(finalklassmap, gotfunctions) usedfunctions = validate_c_to_python_api_mappings(finalklassmap, gotfunctions)