From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: marcandre.lureau@redhat.com, jsnow@redhat.com, michael.roth@amd.com
Subject: [PATCH 10/12] tests/qapi-schema: Hide OrderedDict in test output
Date: Tue, 31 Aug 2021 14:38:07 +0200 [thread overview]
Message-ID: <20210831123809.1107782-11-armbru@redhat.com> (raw)
In-Reply-To: <20210831123809.1107782-1-armbru@redhat.com>
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>
---
tests/qapi-schema/doc-good.out | 6 +++---
tests/qapi-schema/qapi-schema-test.out | 30 +++++++++++++-------------
tests/qapi-schema/test-qapi.py | 11 +++++++++-
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 @@ def _print_variants(variants):
@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):
--
2.31.1
next prev parent reply other threads:[~2021-08-31 13:23 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-31 12:37 [PATCH 00/12] qapi: Fixes and cleanups for recent work (mostly) Markus Armbruster
2021-08-31 12:37 ` [PATCH 01/12] qapi: Simplify QAPISchemaIfCond's interface for generating C Markus Armbruster
2021-08-31 12:37 ` [PATCH 02/12] qapi: Simplify how QAPISchemaIfCond represents "no condition" Markus Armbruster
2021-08-31 12:38 ` [PATCH 03/12] tests/qapi-schema: Correct two 'if' conditionals Markus Armbruster
2021-08-31 12:38 ` [PATCH 04/12] tests/qapi-schema: Demonstrate broken C code for 'if' Markus Armbruster
2021-08-31 12:38 ` [PATCH 05/12] qapi: Fix C code generation " Markus Armbruster
2021-08-31 12:38 ` [PATCH 06/12] qapi: Factor common recursion out of cgen_ifcond(), docgen_ifcond() Markus Armbruster
2021-08-31 12:38 ` [PATCH 07/12] qapi: Avoid redundant parens in code generated for conditionals Markus Armbruster
2021-08-31 12:38 ` [PATCH 08/12] qapi: Use "not COND" instead of "!COND" for generated documentation Markus Armbruster
2021-08-31 12:38 ` [PATCH 09/12] qapi: Use re.fullmatch() where appropriate Markus Armbruster
2021-08-31 12:38 ` Markus Armbruster [this message]
2021-08-31 12:38 ` [PATCH 11/12] qapi: Tweak error messages for missing / conflicting meta-type Markus Armbruster
2021-08-31 12:38 ` [PATCH 12/12] qapi: Tweak error messages for unknown / conflicting 'if' keys Markus Armbruster
2021-08-31 13:41 ` [PATCH 00/12] qapi: Fixes and cleanups for recent work (mostly) Marc-André Lureau
2021-08-31 14:28 ` Markus Armbruster
2021-09-15 14:50 ` John Snow
2021-09-15 15:08 ` Marc-André Lureau
2021-09-15 15:38 ` John Snow
2021-09-03 19:22 ` Markus Armbruster
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210831123809.1107782-11-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=jsnow@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=michael.roth@amd.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.