tests/qapi-schema: Tidy up pylint warnings and advice

Pylint warns:

    tests/qapi-schema/test-qapi.py:139:13: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)
    tests/qapi-schema/test-qapi.py:143:13: W1514: Using open without explicitly specifying an encoding (unspecified-encoding)

Add encoding='utf-8'.

Pylint advises:

    tests/qapi-schema/test-qapi.py:143:13: R1732: Consider using 'with' for resource-allocating operations (consider-using-with)

Silence this by returning the value directly.

Pylint advises:

    tests/qapi-schema/test-qapi.py:221:4: R1722: Consider using sys.exit() (consider-using-sys-exit)
    tests/qapi-schema/test-qapi.py:226:4: R1722: Consider using sys.exit() (consider-using-sys-exit)

Sure, why not.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20231025092925.1785934-1-armbru@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
This commit is contained in:
Markus Armbruster 2023-10-25 11:29:25 +02:00
parent c375f05ef5
commit 5c24c3e2f3
1 changed files with 4 additions and 5 deletions

View File

@ -136,12 +136,11 @@ def test_frontend(fname):
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)
return open(os.path.join(dir_name, file_name), mode, encoding='utf-8')
except FileNotFoundError:
if not update:
raise
fp = open(os.path.join(dir_name, file_name), 'w+')
return fp
return open(os.path.join(dir_name, file_name), 'w+', encoding='utf-8')
def test_and_diff(test_name, dir_name, update):
@ -218,9 +217,9 @@ def main(argv):
test_name = os.path.splitext(base_name)[0]
status |= test_and_diff(test_name, dir_name, args.update)
exit(status)
sys.exit(status)
if __name__ == '__main__':
main(sys.argv)
exit(0)
sys.exit(0)