From e80f6203b53806910b782cd76171166c37afb7a3 Mon Sep 17 00:00:00 2001 From: Akos Kiss Date: Fri, 10 Nov 2023 08:29:57 +0100 Subject: [PATCH] Ensure test quality via linting (#42) - Start specifying encoding when opening a file - Use f-strings - List standard modules first in imports. - Avoid visual indenting --- tests/resources/sut-json-load.py | 4 ++-- tests/test_cli.py | 9 +++++---- tox.ini | 5 +++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/tests/resources/sut-json-load.py b/tests/resources/sut-json-load.py index 999110e..8ebeed0 100755 --- a/tests/resources/sut-json-load.py +++ b/tests/resources/sut-json-load.py @@ -4,7 +4,7 @@ import sys -with open(sys.argv[1], 'r') as f: +with open(sys.argv[1], 'r', encoding='utf-8') as f: j = json.load(f) -print(repr(j)) +print(f'{j!r}') diff --git a/tests/test_cli.py b/tests/test_cli.py index 6f71d1b..c73d46b 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,4 +1,4 @@ -# Copyright (c) 2016-2022 Renata Hodovan, Akos Kiss. +# Copyright (c) 2016-2023 Renata Hodovan, Akos Kiss. # # Licensed under the BSD 3-Clause License # . @@ -6,10 +6,11 @@ # according to those terms. import os -import pytest import subprocess import sys +import pytest + is_windows = sys.platform.startswith('win32') script_ext = '.bat' if is_windows else '.sh' @@ -40,8 +41,8 @@ def test_cli(test, inp, exp, grammar, rule, input_format, args, tmpdir): out_dir = str(tmpdir) cmd = (sys.executable, '-m', 'picireny') \ - + (f'--test={test}{script_ext}', f'--input={inp}', f'--out={out_dir}') \ - + ('--log-level=TRACE', ) + + (f'--test={test}{script_ext}', f'--input={inp}', f'--out={out_dir}') \ + + ('--log-level=TRACE', ) if grammar: cmd += (f'--grammar={grammar}', ) if rule: diff --git a/tox.ini b/tox.ini index dbe62e8..e80cbfd 100644 --- a/tox.ini +++ b/tox.ini @@ -20,9 +20,10 @@ omit = **/parser/* deps = pycodestyle pylint + pytest commands = - pylint picireny - pycodestyle picireny --ignore=E501 --exclude=picireny/antlr4/parser/ANTLRv4*.py + pylint picireny tests + pycodestyle picireny tests --ignore=E501 --exclude=picireny/antlr4/parser/ANTLRv4*.py [testenv:build] deps =