aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2021-08-31 14:38:07 +0200
committerMarkus Armbruster <armbru@redhat.com>2021-09-03 17:09:10 +0200
commit9c629fa8340792cd30758b65f0593d93d7a383d7 (patch)
tree9ea02bed5328e443ba13669b06c3ddf2c14af4c6 /tests
parent555dd1aaa6b654d0ad62da9660c32835ab493678 (diff)
tests/qapi-schema: Hide OrderedDict in test output
Since commit 5d83b9a130 "qapi: replace if condition list with dict {'all': [...]}", we represent if conditionals as trees consisting of OrderedDict, list and str. This results in less than legible test output. For instance: if OrderedDict([('not', OrderedDict([('any', [OrderedDict([('not', 'TEST_IF_EVT')]), OrderedDict([('not', 'TEST_IF_STRUCT')])])]))]) We intend to replace OrderedDict by dict when we get Python 3.7, which will result in more legible output: if {'not': {'any': [{'not': 'TEST_IF_EVT'}, {'not': 'TEST_IF_STRUCT'}]}} Can't wait: put in a hack to get that now, with a comment to revert it when we replace OrderedDict. Signed-off-by: Markus Armbruster <armbru@redhat.com> Message-Id: <20210831123809.1107782-11-armbru@redhat.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/qapi-schema/doc-good.out6
-rw-r--r--tests/qapi-schema/qapi-schema-test.out30
-rwxr-xr-xtests/qapi-schema/test-qapi.py11
3 files changed, 28 insertions, 19 deletions
diff --git a/tests/qapi-schema/doc-good.out b/tests/qapi-schema/doc-good.out
index d72f3047e9..478fe6f82e 100644
--- a/tests/qapi-schema/doc-good.out
+++ b/tests/qapi-schema/doc-good.out
@@ -18,7 +18,7 @@ enum Enum
feature enum-feat
object Base
member base1: Enum optional=False
- if OrderedDict([('all', ['IFALL1', 'IFALL2'])])
+ if {'all': ['IFALL1', 'IFALL2']}
object Variant1
member var1: str optional=False
if IFSTR
@@ -30,7 +30,7 @@ object Object
tag base1
case one: Variant1
case two: Variant2
- if OrderedDict([('any', ['IFONE', 'IFTWO'])])
+ if {'any': ['IFONE', 'IFTWO']}
feature union-feat1
object q_obj_Variant1-wrapper
member data: Variant1 optional=False
@@ -51,7 +51,7 @@ alternate Alternate
tag type
case i: int
case b: bool
- if OrderedDict([('not', OrderedDict([('any', ['IFONE', 'IFTWO'])]))])
+ if {'not': {'any': ['IFONE', 'IFTWO']}}
feature alt-feat
object q_obj_cmd-arg
member arg1: int optional=False
diff --git a/tests/qapi-schema/qapi-schema-test.out b/tests/qapi-schema/qapi-schema-test.out
index 5d2e830ba2..d557fe2d89 100644
--- a/tests/qapi-schema/qapi-schema-test.out
+++ b/tests/qapi-schema/qapi-schema-test.out
@@ -311,40 +311,40 @@ enum TestIfUnionKind
member foo
member bar
if TEST_IF_UNION_BAR
- if OrderedDict([('all', ['TEST_IF_UNION', 'TEST_IF_STRUCT'])])
+ if {'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT']}
object TestIfUnion
member type: TestIfUnionKind optional=False
tag type
case foo: q_obj_TestStruct-wrapper
case bar: q_obj_str-wrapper
if TEST_IF_UNION_BAR
- if OrderedDict([('all', ['TEST_IF_UNION', 'TEST_IF_STRUCT'])])
+ if {'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT']}
object q_obj_test-if-union-cmd-arg
member union-cmd-arg: TestIfUnion optional=False
- if OrderedDict([('all', ['TEST_IF_UNION', 'TEST_IF_STRUCT'])])
+ if {'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT']}
command test-if-union-cmd q_obj_test-if-union-cmd-arg -> None
gen=True success_response=True boxed=False oob=False preconfig=False
- if OrderedDict([('all', ['TEST_IF_UNION', 'TEST_IF_STRUCT'])])
+ if {'all': ['TEST_IF_UNION', 'TEST_IF_STRUCT']}
alternate TestIfAlternate
tag type
case foo: int
case bar: TestStruct
if TEST_IF_ALT_BAR
- if OrderedDict([('all', ['TEST_IF_ALT', 'TEST_IF_STRUCT'])])
+ if {'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT']}
object q_obj_test-if-alternate-cmd-arg
member alt-cmd-arg: TestIfAlternate optional=False
- if OrderedDict([('all', ['TEST_IF_ALT', 'TEST_IF_STRUCT'])])
+ if {'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT']}
command test-if-alternate-cmd q_obj_test-if-alternate-cmd-arg -> None
gen=True success_response=True boxed=False oob=False preconfig=False
- if OrderedDict([('all', ['TEST_IF_ALT', 'TEST_IF_STRUCT'])])
+ if {'all': ['TEST_IF_ALT', 'TEST_IF_STRUCT']}
object q_obj_test-if-cmd-arg
member foo: TestIfStruct optional=False
member bar: TestIfEnum optional=False
if TEST_IF_CMD_BAR
- if OrderedDict([('all', ['TEST_IF_CMD', 'TEST_IF_STRUCT'])])
+ if {'all': ['TEST_IF_CMD', 'TEST_IF_STRUCT']}
command test-if-cmd q_obj_test-if-cmd-arg -> UserDefThree
gen=True success_response=True boxed=False oob=False preconfig=False
- if OrderedDict([('all', ['TEST_IF_CMD', 'TEST_IF_STRUCT'])])
+ if {'all': ['TEST_IF_CMD', 'TEST_IF_STRUCT']}
command test-cmd-return-def-three None -> UserDefThree
gen=True success_response=True boxed=False oob=False preconfig=False
array TestIfEnumList TestIfEnum
@@ -353,13 +353,13 @@ object q_obj_TEST_IF_EVENT-arg
member foo: TestIfStruct optional=False
member bar: TestIfEnumList optional=False
if TEST_IF_EVT_BAR
- if OrderedDict([('all', ['TEST_IF_EVT', 'TEST_IF_STRUCT'])])
+ if {'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT']}
event TEST_IF_EVENT q_obj_TEST_IF_EVENT-arg
boxed=False
- if OrderedDict([('all', ['TEST_IF_EVT', 'TEST_IF_STRUCT'])])
+ if {'all': ['TEST_IF_EVT', 'TEST_IF_STRUCT']}
event TEST_IF_EVENT2 None
boxed=False
- if OrderedDict([('not', OrderedDict([('any', [OrderedDict([('not', 'TEST_IF_EVT')]), OrderedDict([('not', 'TEST_IF_STRUCT')])])]))])
+ if {'not': {'any': [{'not': 'TEST_IF_EVT'}, {'not': 'TEST_IF_STRUCT'}]}}
object FeatureStruct0
member foo: int optional=False
object FeatureStruct1
@@ -392,11 +392,11 @@ object CondFeatureStruct2
object CondFeatureStruct3
member foo: int optional=False
feature feature1
- if OrderedDict([('all', ['TEST_IF_COND_1', 'TEST_IF_COND_2'])])
+ if {'all': ['TEST_IF_COND_1', 'TEST_IF_COND_2']}
object CondFeatureStruct4
member foo: int optional=False
feature feature1
- if OrderedDict([('any', ['TEST_IF_COND_1', 'TEST_IF_COND_2'])])
+ if {'any': ['TEST_IF_COND_1', 'TEST_IF_COND_2']}
enum FeatureEnum1
member eins
member zwei
@@ -447,7 +447,7 @@ command test-command-cond-features2 None -> None
command test-command-cond-features3 None -> None
gen=True success_response=True boxed=False oob=False preconfig=False
feature feature1
- if OrderedDict([('all', ['TEST_IF_COND_1', 'TEST_IF_COND_2'])])
+ if {'all': ['TEST_IF_COND_1', 'TEST_IF_COND_2']}
event TEST_EVENT_FEATURES0 FeatureStruct1
boxed=False
event TEST_EVENT_FEATURES1 None
diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py
index c92be2d086..73cffae2b6 100755
--- a/tests/qapi-schema/test-qapi.py
+++ b/tests/qapi-schema/test-qapi.py
@@ -94,8 +94,17 @@ class QAPISchemaTestVisitor(QAPISchemaVisitor):
@staticmethod
def _print_if(ifcond, indent=4):
+ # TODO Drop this hack after replacing OrderedDict by plain
+ # dict (requires Python 3.7)
+ def _massage(subcond):
+ if isinstance(subcond, str):
+ return subcond
+ if isinstance(subcond, list):
+ return [_massage(val) for val in subcond]
+ return {key: _massage(val) for key, val in subcond.items()}
+
if ifcond.is_present():
- print('%sif %s' % (' ' * indent, ifcond.ifcond))
+ print('%sif %s' % (' ' * indent, _massage(ifcond.ifcond)))
@classmethod
def _print_features(cls, features, indent=4):