summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel P. Berrangé <berrange@redhat.com>2022-03-22 17:52:55 +0000
committerDaniel P. Berrangé <berrange@redhat.com>2022-04-21 15:00:29 +0000
commit8cb4b852d16e6a347f47f40fd10f42d9370d8eeb (patch)
tree49d90080bf23efdcd20e825e53d4bc3cac41a543
parent9fb3a9b234904a24d7b7bc25633a7dc25ff2263d (diff)
downloadlibvirt-python-8cb4b852d16e6a347f47f40fd10f42d9370d8eeb.tar.gz
sanitytest: move function/enum 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>
-rw-r--r--sanitytest.py113
1 files changed, 59 insertions, 54 deletions
diff --git a/sanitytest.py b/sanitytest.py
index a3af7b0..6e6afd2 100644
--- a/sanitytest.py
+++ b/sanitytest.py
@@ -24,60 +24,64 @@ with open(xml, "r") as fp:
verbose = False
fail = False
-enumvals = {} # type: Dict[str, Dict[str, int]]
-second_pass = [] # type: List[str]
-wantenums = [] # type: List[str]
-wantfunctions = [] # type: List[str]
-
-# Phase 1: Identify all functions and enums in public API
-wantfunctions = tree.xpath('/api/files/file/exports[@type="function"]/@symbol')
-
-for n in tree.xpath('/api/symbols/enum'):
- typ = n.attrib['type']
- name = n.attrib['name']
- val = n.attrib['value']
-
- if typ not in enumvals:
- enumvals[typ] = {}
-
- # If the value cannot be converted to int, it is reference to
- # another enum and needs to be sorted out later on
- try:
- val = int(val)
- except ValueError:
- second_pass.append(n)
- continue
-
- enumvals[typ][name] = int(val)
-
-for n in second_pass:
- typ = n.attrib['type']
- name = n.attrib['name']
- val = n.attrib['value']
-
- for v in enumvals.values():
- if val in v:
- val = int(v[val])
- break
-
- # Version 4.0.0 was broken as missing VIR_TYPED_PARAM enums
- # constants. This is harmless from POV of validating API
- # coverage so ignore this error.
- if (not isinstance(val, int) and
- not val.startswith("VIR_TYPED_PARAM_")):
- fail = True
- print("Cannot get a value of enum %s (originally %s)" % (val, name))
- enumvals[typ][name] = val
-
-for n in tree.xpath('/api/files/file/exports[@type="enum"]/@symbol'):
- for enumval in enumvals.values():
- if n in enumval:
- enumv = enumval
- break
- # Eliminate sentinels
- if n.endswith('_LAST') and enumv[n] == max(enumv.values()):
- continue
- wantenums.append(n)
+# Identify all functions and enums in public API
+def identify_functions_enums(tree):
+ enumvals = {} # type: Dict[str, Dict[str, int]]
+ second_pass = [] # type: List[str]
+ wantenums = [] # type: List[str]
+ wantfunctions = [] # type: List[str]
+
+ wantfunctions = tree.xpath('/api/files/file/exports[@type="function"]/@symbol')
+
+ for n in tree.xpath('/api/symbols/enum'):
+ typ = n.attrib['type']
+ name = n.attrib['name']
+ val = n.attrib['value']
+
+ if typ not in enumvals:
+ enumvals[typ] = {}
+
+ # If the value cannot be converted to int, it is reference to
+ # another enum and needs to be sorted out later on
+ try:
+ val = int(val)
+ except ValueError:
+ second_pass.append(n)
+ continue
+
+ enumvals[typ][name] = int(val)
+
+ for n in second_pass:
+ typ = n.attrib['type']
+ name = n.attrib['name']
+ val = n.attrib['value']
+
+ for v in enumvals.values():
+ if val in v:
+ val = int(v[val])
+ break
+
+ # Version 4.0.0 was broken as missing VIR_TYPED_PARAM enums
+ # constants. This is harmless from POV of validating API
+ # coverage so ignore this error.
+ if (not isinstance(val, int) and
+ not val.startswith("VIR_TYPED_PARAM_")):
+ fail = True
+ print("Cannot get a value of enum %s (originally %s)" % (val, name))
+ enumvals[typ][name] = val
+
+ for n in tree.xpath('/api/files/file/exports[@type="enum"]/@symbol'):
+ for enumval in enumvals.values():
+ if n in enumval:
+ enumv = enumval
+ break
+ # Eliminate sentinels
+ if n.endswith('_LAST') and enumv[n] == max(enumv.values()):
+ continue
+ wantenums.append(n)
+
+ return wantfunctions, wantenums, enumvals
+
# Identify all classes and methods in the 'libvirt' python module
def identify_class_methods(wantenums, enumvals):
@@ -382,6 +386,7 @@ def validate_c_api_bindings_present(finalklassmap):
try:
+ wantfunctions, wantenums, enumvals = identify_functions_enums(tree)
gotfunctions, gottypes = identify_class_methods(wantenums, enumvals)
basicklassmap = basic_class_method_mapping(wantfunctions, gottypes)
finalklassmap = fixup_class_method_mapping(basicklassmap)