* [PATCH 0/2] tests/qapi-schema: Minor tooling improvements @ 2021-09-22 12:56 Markus Armbruster 2021-09-22 12:56 ` [PATCH 1/2] tests/qapi-schema: Use Python OSError instead of outmoded IOError Markus Armbruster 2021-09-22 12:56 ` [PATCH 2/2] tests/qapi-schema: Make test-qapi.py -u work when files are absent Markus Armbruster 0 siblings, 2 replies; 8+ messages in thread From: Markus Armbruster @ 2021-09-22 12:56 UTC (permalink / raw) To: qemu-devel; +Cc: marcandre.lureau, jsnow, mdroth Markus Armbruster (2): tests/qapi-schema: Use Python OSError instead of outmoded IOError tests/qapi-schema: Make test-qapi.py -u work when files are absent tests/qapi-schema/test-qapi.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) -- 2.31.1 ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] tests/qapi-schema: Use Python OSError instead of outmoded IOError 2021-09-22 12:56 [PATCH 0/2] tests/qapi-schema: Minor tooling improvements Markus Armbruster @ 2021-09-22 12:56 ` Markus Armbruster 2021-09-22 18:07 ` John Snow 2021-09-22 12:56 ` [PATCH 2/2] tests/qapi-schema: Make test-qapi.py -u work when files are absent Markus Armbruster 1 sibling, 1 reply; 8+ messages in thread From: Markus Armbruster @ 2021-09-22 12:56 UTC (permalink / raw) To: qemu-devel; +Cc: marcandre.lureau, jsnow, mdroth Signed-off-by: Markus Armbruster <armbru@redhat.com> --- tests/qapi-schema/test-qapi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 73cffae2b6..2e384f5efd 100755 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -154,7 +154,7 @@ def test_and_diff(test_name, dir_name, update): errfp = open(os.path.join(dir_name, test_name + '.err'), mode) expected_out = outfp.readlines() expected_err = errfp.readlines() - except IOError as err: + except OSError as err: print("%s: can't open '%s': %s" % (sys.argv[0], err.filename, err.strerror), file=sys.stderr) @@ -180,7 +180,7 @@ def test_and_diff(test_name, dir_name, update): errfp.truncate(0) errfp.seek(0) errfp.writelines(actual_err) - except IOError as err: + except OSError as err: print("%s: can't write '%s': %s" % (sys.argv[0], err.filename, err.strerror), file=sys.stderr) -- 2.31.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] tests/qapi-schema: Use Python OSError instead of outmoded IOError 2021-09-22 12:56 ` [PATCH 1/2] tests/qapi-schema: Use Python OSError instead of outmoded IOError Markus Armbruster @ 2021-09-22 18:07 ` John Snow 2021-09-23 9:33 ` Markus Armbruster 0 siblings, 1 reply; 8+ messages in thread From: John Snow @ 2021-09-22 18:07 UTC (permalink / raw) To: Markus Armbruster; +Cc: marcandre.lureau, qemu-devel, mdroth [-- Attachment #1: Type: text/plain, Size: 1364 bytes --] On Wed, Sep 22, 2021 at 8:56 AM Markus Armbruster <armbru@redhat.com> wrote: > Signed-off-by: Markus Armbruster <armbru@redhat.com> > --- > tests/qapi-schema/test-qapi.py | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/tests/qapi-schema/test-qapi.py > b/tests/qapi-schema/test-qapi.py > index 73cffae2b6..2e384f5efd 100755 > --- a/tests/qapi-schema/test-qapi.py > +++ b/tests/qapi-schema/test-qapi.py > @@ -154,7 +154,7 @@ def test_and_diff(test_name, dir_name, update): > errfp = open(os.path.join(dir_name, test_name + '.err'), mode) > expected_out = outfp.readlines() > expected_err = errfp.readlines() > - except IOError as err: > + except OSError as err: > print("%s: can't open '%s': %s" > % (sys.argv[0], err.filename, err.strerror), > file=sys.stderr) > @@ -180,7 +180,7 @@ def test_and_diff(test_name, dir_name, update): > errfp.truncate(0) > errfp.seek(0) > errfp.writelines(actual_err) > - except IOError as err: > + except OSError as err: > print("%s: can't write '%s': %s" > % (sys.argv[0], err.filename, err.strerror), > file=sys.stderr) > -- > 2.31.1 > > If you're happy with the expanded scope of the exception-catcher, I am too. Reviewed-by: John Snow <jsnow@redhat.com> [-- Attachment #2: Type: text/html, Size: 2047 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] tests/qapi-schema: Use Python OSError instead of outmoded IOError 2021-09-22 18:07 ` John Snow @ 2021-09-23 9:33 ` Markus Armbruster 2021-09-23 9:54 ` Philippe Mathieu-Daudé 2021-09-23 16:55 ` John Snow 0 siblings, 2 replies; 8+ messages in thread From: Markus Armbruster @ 2021-09-23 9:33 UTC (permalink / raw) To: John Snow; +Cc: marcandre.lureau, qemu-devel, mdroth John Snow <jsnow@redhat.com> writes: > On Wed, Sep 22, 2021 at 8:56 AM Markus Armbruster <armbru@redhat.com> wrote: > >> Signed-off-by: Markus Armbruster <armbru@redhat.com> >> --- >> tests/qapi-schema/test-qapi.py | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/tests/qapi-schema/test-qapi.py >> b/tests/qapi-schema/test-qapi.py >> index 73cffae2b6..2e384f5efd 100755 >> --- a/tests/qapi-schema/test-qapi.py >> +++ b/tests/qapi-schema/test-qapi.py >> @@ -154,7 +154,7 @@ def test_and_diff(test_name, dir_name, update): >> errfp = open(os.path.join(dir_name, test_name + '.err'), mode) >> expected_out = outfp.readlines() >> expected_err = errfp.readlines() >> - except IOError as err: >> + except OSError as err: >> print("%s: can't open '%s': %s" >> % (sys.argv[0], err.filename, err.strerror), >> file=sys.stderr) >> @@ -180,7 +180,7 @@ def test_and_diff(test_name, dir_name, update): >> errfp.truncate(0) >> errfp.seek(0) >> errfp.writelines(actual_err) >> - except IOError as err: >> + except OSError as err: >> print("%s: can't write '%s': %s" >> % (sys.argv[0], err.filename, err.strerror), >> file=sys.stderr) >> -- >> 2.31.1 >> >> > If you're happy with the expanded scope of the exception-catcher, I am too. https://docs.python.org/3.6/library/exceptions.html has Changed in version 3.3: EnvironmentError, IOError, WindowsError, socket.error, select.error and mmap.error have been merged into OSError, and the constructor may return a subclass. and The following exceptions are kept for compatibility with previous versions; starting from Python 3.3, they are aliases of OSError. exception EnvironmentError exception IOError exception WindowsError Only available on Windows. So unless I'm misunderstanding something (which is quite possible), we're catching exactly the same exceptions as before, we just switch to their preferred name. > Reviewed-by: John Snow <jsnow@redhat.com> Thanks! ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] tests/qapi-schema: Use Python OSError instead of outmoded IOError 2021-09-23 9:33 ` Markus Armbruster @ 2021-09-23 9:54 ` Philippe Mathieu-Daudé 2021-09-23 16:55 ` John Snow 1 sibling, 0 replies; 8+ messages in thread From: Philippe Mathieu-Daudé @ 2021-09-23 9:54 UTC (permalink / raw) To: Markus Armbruster, John Snow; +Cc: marcandre.lureau, qemu-devel, mdroth On 9/23/21 11:33, Markus Armbruster wrote: > John Snow <jsnow@redhat.com> writes: > >> On Wed, Sep 22, 2021 at 8:56 AM Markus Armbruster <armbru@redhat.com> wrote: >> >>> Signed-off-by: Markus Armbruster <armbru@redhat.com> >>> --- >>> tests/qapi-schema/test-qapi.py | 4 ++-- >>> 1 file changed, 2 insertions(+), 2 deletions(-) >>> >>> diff --git a/tests/qapi-schema/test-qapi.py >>> b/tests/qapi-schema/test-qapi.py >>> index 73cffae2b6..2e384f5efd 100755 >>> --- a/tests/qapi-schema/test-qapi.py >>> +++ b/tests/qapi-schema/test-qapi.py >>> @@ -154,7 +154,7 @@ def test_and_diff(test_name, dir_name, update): >>> errfp = open(os.path.join(dir_name, test_name + '.err'), mode) >>> expected_out = outfp.readlines() >>> expected_err = errfp.readlines() >>> - except IOError as err: >>> + except OSError as err: >>> print("%s: can't open '%s': %s" >>> % (sys.argv[0], err.filename, err.strerror), >>> file=sys.stderr) >>> @@ -180,7 +180,7 @@ def test_and_diff(test_name, dir_name, update): >>> errfp.truncate(0) >>> errfp.seek(0) >>> errfp.writelines(actual_err) >>> - except IOError as err: >>> + except OSError as err: >>> print("%s: can't write '%s': %s" >>> % (sys.argv[0], err.filename, err.strerror), >>> file=sys.stderr) >>> -- >>> 2.31.1 >>> >>> >> If you're happy with the expanded scope of the exception-catcher, I am too. > > https://docs.python.org/3.6/library/exceptions.html has > > Changed in version 3.3: EnvironmentError, IOError, WindowsError, > socket.error, select.error and mmap.error have been merged into > OSError, and the constructor may return a subclass. > > and > > The following exceptions are kept for compatibility with previous > versions; starting from Python 3.3, they are aliases of OSError. > > exception EnvironmentError > > exception IOError > > exception WindowsError > > Only available on Windows. With that information amended to the description: Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> > So unless I'm misunderstanding something (which is quite possible), > we're catching exactly the same exceptions as before, we just switch to > their preferred name. > >> Reviewed-by: John Snow <jsnow@redhat.com> > > Thanks! > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] tests/qapi-schema: Use Python OSError instead of outmoded IOError 2021-09-23 9:33 ` Markus Armbruster 2021-09-23 9:54 ` Philippe Mathieu-Daudé @ 2021-09-23 16:55 ` John Snow 1 sibling, 0 replies; 8+ messages in thread From: John Snow @ 2021-09-23 16:55 UTC (permalink / raw) To: Markus Armbruster; +Cc: marcandre.lureau, qemu-devel, mdroth [-- Attachment #1: Type: text/plain, Size: 2589 bytes --] On Thu, Sep 23, 2021 at 5:33 AM Markus Armbruster <armbru@redhat.com> wrote: > John Snow <jsnow@redhat.com> writes: > > > On Wed, Sep 22, 2021 at 8:56 AM Markus Armbruster <armbru@redhat.com> > wrote: > > > >> Signed-off-by: Markus Armbruster <armbru@redhat.com> > >> --- > >> tests/qapi-schema/test-qapi.py | 4 ++-- > >> 1 file changed, 2 insertions(+), 2 deletions(-) > >> > >> diff --git a/tests/qapi-schema/test-qapi.py > >> b/tests/qapi-schema/test-qapi.py > >> index 73cffae2b6..2e384f5efd 100755 > >> --- a/tests/qapi-schema/test-qapi.py > >> +++ b/tests/qapi-schema/test-qapi.py > >> @@ -154,7 +154,7 @@ def test_and_diff(test_name, dir_name, update): > >> errfp = open(os.path.join(dir_name, test_name + '.err'), mode) > >> expected_out = outfp.readlines() > >> expected_err = errfp.readlines() > >> - except IOError as err: > >> + except OSError as err: > >> print("%s: can't open '%s': %s" > >> % (sys.argv[0], err.filename, err.strerror), > >> file=sys.stderr) > >> @@ -180,7 +180,7 @@ def test_and_diff(test_name, dir_name, update): > >> errfp.truncate(0) > >> errfp.seek(0) > >> errfp.writelines(actual_err) > >> - except IOError as err: > >> + except OSError as err: > >> print("%s: can't write '%s': %s" > >> % (sys.argv[0], err.filename, err.strerror), > >> file=sys.stderr) > >> -- > >> 2.31.1 > >> > >> > > If you're happy with the expanded scope of the exception-catcher, I am > too. > > https://docs.python.org/3.6/library/exceptions.html has > > Changed in version 3.3: EnvironmentError, IOError, WindowsError, > socket.error, select.error and mmap.error have been merged into > OSError, and the constructor may return a subclass. > > and > > The following exceptions are kept for compatibility with previous > versions; starting from Python 3.3, they are aliases of OSError. > > exception EnvironmentError > > exception IOError > > exception WindowsError > > Only available on Windows. > > So unless I'm misunderstanding something (which is quite possible), > we're catching exactly the same exceptions as before, we just switch to > their preferred name. > > > Reviewed-by: John Snow <jsnow@redhat.com> > > Thanks! > > Yeah, I suppose the 3.3 upgrade already "expanded" the coverage here, so you aren't expanding anything. It's just an expansion of intent in the source code, if that distinction makes sense. The code is obviously fine so far as I can tell. My RB stands! --js [-- Attachment #2: Type: text/html, Size: 3879 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 2/2] tests/qapi-schema: Make test-qapi.py -u work when files are absent 2021-09-22 12:56 [PATCH 0/2] tests/qapi-schema: Minor tooling improvements Markus Armbruster 2021-09-22 12:56 ` [PATCH 1/2] tests/qapi-schema: Use Python OSError instead of outmoded IOError Markus Armbruster @ 2021-09-22 12:56 ` Markus Armbruster 2021-09-22 18:11 ` John Snow 1 sibling, 1 reply; 8+ messages in thread From: Markus Armbruster @ 2021-09-22 12:56 UTC (permalink / raw) To: qemu-devel; +Cc: marcandre.lureau, jsnow, mdroth test-qapi.py -u updates the expected files. Since it fails when they are absent, users have to create them manually before they can use test-qapi.py to fill in the contents, say for a new test. Silly. Improve -u to create them. Signed-off-by: Markus Armbruster <armbru@redhat.com> --- tests/qapi-schema/test-qapi.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tests/qapi-schema/test-qapi.py b/tests/qapi-schema/test-qapi.py index 2e384f5efd..c717a7a90b 100755 --- a/tests/qapi-schema/test-qapi.py +++ b/tests/qapi-schema/test-qapi.py @@ -132,6 +132,17 @@ def test_frontend(fname): print(' section=%s\n%s' % (section.name, section.text)) +def open_test_result(dir_name, file_name, update): + mode = 'r+' if update else 'r' + try: + fp = open(os.path.join(dir_name, file_name), mode) + except FileNotFoundError: + if not update: + raise + fp = open(os.path.join(dir_name, file_name), 'w+') + return fp + + def test_and_diff(test_name, dir_name, update): sys.stdout = StringIO() try: @@ -148,10 +159,9 @@ def test_and_diff(test_name, dir_name, update): sys.stdout.close() sys.stdout = sys.__stdout__ - mode = 'r+' if update else 'r' try: - outfp = open(os.path.join(dir_name, test_name + '.out'), mode) - errfp = open(os.path.join(dir_name, test_name + '.err'), mode) + outfp = open_test_result(dir_name, test_name + '.out', update) + errfp = open_test_result(dir_name, test_name + '.err', update) expected_out = outfp.readlines() expected_err = errfp.readlines() except OSError as err: -- 2.31.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 2/2] tests/qapi-schema: Make test-qapi.py -u work when files are absent 2021-09-22 12:56 ` [PATCH 2/2] tests/qapi-schema: Make test-qapi.py -u work when files are absent Markus Armbruster @ 2021-09-22 18:11 ` John Snow 0 siblings, 0 replies; 8+ messages in thread From: John Snow @ 2021-09-22 18:11 UTC (permalink / raw) To: Markus Armbruster; +Cc: marcandre.lureau, qemu-devel, mdroth [-- Attachment #1: Type: text/plain, Size: 1927 bytes --] On Wed, Sep 22, 2021 at 8:56 AM Markus Armbruster <armbru@redhat.com> wrote: > test-qapi.py -u updates the expected files. Since it fails when they > are absent, users have to create them manually before they can use > test-qapi.py to fill in the contents, say for a new test. Silly. > Improve -u to create them. > > Signed-off-by: Markus Armbruster <armbru@redhat.com> > --- > tests/qapi-schema/test-qapi.py | 16 +++++++++++++--- > 1 file changed, 13 insertions(+), 3 deletions(-) > > diff --git a/tests/qapi-schema/test-qapi.py > b/tests/qapi-schema/test-qapi.py > index 2e384f5efd..c717a7a90b 100755 > --- a/tests/qapi-schema/test-qapi.py > +++ b/tests/qapi-schema/test-qapi.py > @@ -132,6 +132,17 @@ def test_frontend(fname): > print(' section=%s\n%s' % (section.name, section.text)) > > > +def open_test_result(dir_name, file_name, update): > + mode = 'r+' if update else 'r' > + try: > + fp = open(os.path.join(dir_name, file_name), mode) > + except FileNotFoundError: > + if not update: > + raise > + fp = open(os.path.join(dir_name, file_name), 'w+') > + return fp > + > + > def test_and_diff(test_name, dir_name, update): > sys.stdout = StringIO() > try: > @@ -148,10 +159,9 @@ def test_and_diff(test_name, dir_name, update): > sys.stdout.close() > sys.stdout = sys.__stdout__ > > - mode = 'r+' if update else 'r' > try: > - outfp = open(os.path.join(dir_name, test_name + '.out'), mode) > - errfp = open(os.path.join(dir_name, test_name + '.err'), mode) > + outfp = open_test_result(dir_name, test_name + '.out', update) > + errfp = open_test_result(dir_name, test_name + '.err', update) > expected_out = outfp.readlines() > expected_err = errfp.readlines() > except OSError as err: > -- > 2.31.1 > > Sure boss, why not? Reviewed-by: John Snow <jsnow@redhat.com> [-- Attachment #2: Type: text/html, Size: 2775 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-09-23 16:58 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2021-09-22 12:56 [PATCH 0/2] tests/qapi-schema: Minor tooling improvements Markus Armbruster 2021-09-22 12:56 ` [PATCH 1/2] tests/qapi-schema: Use Python OSError instead of outmoded IOError Markus Armbruster 2021-09-22 18:07 ` John Snow 2021-09-23 9:33 ` Markus Armbruster 2021-09-23 9:54 ` Philippe Mathieu-Daudé 2021-09-23 16:55 ` John Snow 2021-09-22 12:56 ` [PATCH 2/2] tests/qapi-schema: Make test-qapi.py -u work when files are absent Markus Armbruster 2021-09-22 18:11 ` John Snow
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.