From 10a57d0464ea717c1f8c88346320bd021c29e903 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Tue, 12 Mar 2024 15:35:53 -0700 Subject: [PATCH] Move to Ruff for formatting (#23060) Also set the line length to 100. --- .devcontainer/devcontainer.json | 3 +- .github/actions/lint/action.yml | 9 +- .vscode/extensions.json | 6 +- .vscode/settings.json | 2 +- python_files/linter.py | 6 +- python_files/normalizeSelection.py | 8 +- python_files/pyproject.toml | 10 +- .../testing_tools/adapter/__main__.py | 4 +- python_files/testing_tools/adapter/info.py | 4 +- .../adapter/pytest/_discovery.py | 2 +- .../adapter/pytest/_pytest_item.py | 4 +- python_files/testing_tools/adapter/report.py | 2 +- python_files/testing_tools/adapter/util.py | 4 +- python_files/testing_tools/socket_manager.py | 4 +- python_files/tests/__main__.py | 4 +- .../debug_adapter/test_install_debugpy.py | 8 +- .../expected_discovery_test_output.py | 37 ++---- .../expected_execution_test_output.py | 118 +++++------------- python_files/tests/pytestadapter/helpers.py | 20 +-- .../tests/pytestadapter/test_discovery.py | 20 +-- .../tests/pytestadapter/test_execution.py | 36 ++---- python_files/tests/test_create_conda.py | 4 +- python_files/tests/test_create_venv.py | 16 +-- .../adapter/pytest/test_discovery.py | 66 ++++------ .../testing_tools/adapter/test_discovery.py | 4 +- .../testing_tools/adapter/test_functional.py | 4 +- .../tests/testing_tools/adapter/test_util.py | 4 +- .../.data/two_patterns/pattern_a_test.py | 3 +- .../.data/two_patterns/test_pattern_b.py | 4 +- .../.data/unittest_folder/test_add.py | 9 +- .../.data/unittest_folder/test_subtract.py | 4 +- .../expected_discovery_test_output.py | 36 ++---- .../tests/unittestadapter/test_discovery.py | 36 +----- python_files/unittestadapter/discovery.py | 8 +- python_files/unittestadapter/execution.py | 16 +-- python_files/unittestadapter/pvsc_utils.py | 12 +- python_files/visualstudio_py_testlauncher.py | 24 +--- .../tests/logParser.py | 6 +- python_files/vscode_pytest/__init__.py | 25 +--- .../vscode_pytest/run_pytest_script.py | 8 +- 40 files changed, 162 insertions(+), 438 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index f123a5864932..67a8833d30cf 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -9,13 +9,12 @@ "customizations": { "vscode": { "extensions": [ + "charliermarsh.ruff", "editorconfig.editorconfig", "esbenp.prettier-vscode", "dbaeumer.vscode-eslint", "ms-python.python", - "ms-python.black-formatter", "ms-python.vscode-pylance", - "charliermarsh.ruff", "ms-python.debugpy" ] } diff --git a/.github/actions/lint/action.yml b/.github/actions/lint/action.yml index 97f19814b362..444f331a3a96 100644 --- a/.github/actions/lint/action.yml +++ b/.github/actions/lint/action.yml @@ -41,17 +41,10 @@ runs: python-version: '3.x' cache: 'pip' - - name: Check Python format - run: | - python -m pip install -U black ruff - python -m ruff check - python -m black . --check - working-directory: python_files - shell: bash - - name: Run Ruff run: | python -m pip install -U ruff python -m ruff check . + python -m ruff format --check working-directory: python_files shell: bash diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 93a73827e7a2..15e6aada1d50 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -2,13 +2,11 @@ // See https://go.microsoft.com/fwlink/?LinkId=827846 // for the documentation about the extensions.json format "recommendations": [ + "charliermarsh.ruff", "editorconfig.editorconfig", "esbenp.prettier-vscode", "dbaeumer.vscode-eslint", "ms-python.python", - "ms-python.black-formatter", - "ms-python.vscode-pylance", - "ms-python.isort", - "ms-python.flake8" + "ms-python.vscode-pylance" ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index 5e5954991562..89959f33b6b1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -28,7 +28,7 @@ "source.fixAll.eslint": "explicit", "source.organizeImports.isort": "explicit" }, - "editor.defaultFormatter": "ms-python.black-formatter", + "editor.defaultFormatter": "charliermarsh.ruff", }, "[typescript]": { "editor.defaultFormatter": "esbenp.prettier-vscode", diff --git a/python_files/linter.py b/python_files/linter.py index 58ad9397f58b..af9634f83f4b 100644 --- a/python_files/linter.py +++ b/python_files/linter.py @@ -37,11 +37,7 @@ def main(): invoke = sys.argv[1] if invoke == "-m": linter = sys.argv[2] - args = ( - [sys.executable, "-m", linter] - + linter_settings[linter]["args"] - + sys.argv[3:] - ) + args = [sys.executable, "-m", linter] + linter_settings[linter]["args"] + sys.argv[3:] else: linter = sys.argv[2] args = [sys.argv[3]] + linter_settings[linter]["args"] + sys.argv[4:] diff --git a/python_files/normalizeSelection.py b/python_files/normalizeSelection.py index 7608ce8860f6..7c65575c1dd8 100644 --- a/python_files/normalizeSelection.py +++ b/python_files/normalizeSelection.py @@ -191,9 +191,7 @@ def traverse_file(wholeFileContent, start_line, end_line, was_highlighted): ast.IfExp, ast.ExceptHandler, ) - if isinstance(node, ast_types_with_nodebody) and isinstance( - node.body, Iterable - ): + if isinstance(node, ast_types_with_nodebody) and isinstance(node.body, Iterable): for child_nodes in node.body: top_level_nodes.append(child_nodes) @@ -204,9 +202,7 @@ def traverse_file(wholeFileContent, start_line, end_line, was_highlighted): which_line_next = 0 for same_line_node in exact_nodes: should_run_top_blocks.append(same_line_node) - smart_code += ( - f"{ast.get_source_segment(wholeFileContent, same_line_node)}\n" - ) + smart_code += f"{ast.get_source_segment(wholeFileContent, same_line_node)}\n" which_line_next = get_next_block_lineno(should_run_top_blocks) return { "normalized_smart_result": smart_code, diff --git a/python_files/pyproject.toml b/python_files/pyproject.toml index 94353be0b644..9e8f55910e70 100644 --- a/python_files/pyproject.toml +++ b/python_files/pyproject.toml @@ -36,8 +36,14 @@ ignore = [ ] [tool.ruff] -line-length = 140 -exclude = ["tests/testing_tools/adapter/.data"] +line-length = 100 +exclude = [ + "tests/testing_tools/adapter/.data", + "tests/unittestadapter/.data" +] + +[tool.ruff.format] +docstring-code-format = true [tool.ruff.lint.pydocstyle] convention = "pep257" diff --git a/python_files/testing_tools/adapter/__main__.py b/python_files/testing_tools/adapter/__main__.py index 218456897df6..cc7084eb9439 100644 --- a/python_files/testing_tools/adapter/__main__.py +++ b/python_files/testing_tools/adapter/__main__.py @@ -50,9 +50,7 @@ def parse_args( subsub = add_subparser(cmdname, toolname, subsubs) if cmdname == "discover": subsub.add_argument("--simple", action="store_true") - subsub.add_argument( - "--no-hide-stdio", dest="hidestdio", action="store_false" - ) + subsub.add_argument("--no-hide-stdio", dest="hidestdio", action="store_false") subsub.add_argument("--pretty", action="store_true") # Parse the args! diff --git a/python_files/testing_tools/adapter/info.py b/python_files/testing_tools/adapter/info.py index d518a29dd97a..8e5d0442ce15 100644 --- a/python_files/testing_tools/adapter/info.py +++ b/python_files/testing_tools/adapter/info.py @@ -61,9 +61,7 @@ def __init__(self, *args, **kwargs): raise TypeError("missing relpath") -class SingleTestInfo( - namedtuple("TestInfo", "id name path source markers parentid kind") -): +class SingleTestInfo(namedtuple("TestInfo", "id name path source markers parentid kind")): """Info for a single test.""" MARKERS = ("skip", "skip-if", "expected-failure") diff --git a/python_files/testing_tools/adapter/pytest/_discovery.py b/python_files/testing_tools/adapter/pytest/_discovery.py index 4b852ecf81c9..bbe5ae9856c8 100644 --- a/python_files/testing_tools/adapter/pytest/_discovery.py +++ b/python_files/testing_tools/adapter/pytest/_discovery.py @@ -17,7 +17,7 @@ def discover( # *, _pytest_main=pytest.main, _plugin=None, - **_ignored + **_ignored, ): """Return the results of test discovery.""" if _plugin is None: diff --git a/python_files/testing_tools/adapter/pytest/_pytest_item.py b/python_files/testing_tools/adapter/pytest/_pytest_item.py index ccfe14122316..724b71a1ac44 100644 --- a/python_files/testing_tools/adapter/pytest/_pytest_item.py +++ b/python_files/testing_tools/adapter/pytest/_pytest_item.py @@ -170,9 +170,7 @@ def parse_item( parents = [(parentid, item.originalname, kind)] + parents name = parameterized[1:-1] or "" else: - (nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id( - item.nodeid, kind - ) + (nodeid, parents, fileid, testfunc, parameterized) = _parse_node_id(item.nodeid, kind) name = item.name # Note: testfunc does not necessarily match item.function.__name__. diff --git a/python_files/testing_tools/adapter/report.py b/python_files/testing_tools/adapter/report.py index bacdef7b9a00..1ad02fe7bcd4 100644 --- a/python_files/testing_tools/adapter/report.py +++ b/python_files/testing_tools/adapter/report.py @@ -13,7 +13,7 @@ def report_discovered( pretty=False, simple=False, _send=print, - **_ignored + **_ignored, ): """Serialize the discovered tests and write to stdout.""" if simple: diff --git a/python_files/testing_tools/adapter/util.py b/python_files/testing_tools/adapter/util.py index 4799980db53e..9f3089fb29d0 100644 --- a/python_files/testing_tools/adapter/util.py +++ b/python_files/testing_tools/adapter/util.py @@ -128,7 +128,7 @@ def fix_fileid( normalize=False, strictpathsep=None, _pathsep=PATH_SEP, - **kwargs + **kwargs, ): """Return a pathsep-separated file ID ("./"-prefixed) for the given value. @@ -150,7 +150,7 @@ def fix_fileid( rootdir, _pathsep=_pathsep, # ... - **kwargs + **kwargs, ) if relpath: # Note that we treat "" here as an absolute path. _fileid = "./" + relpath diff --git a/python_files/testing_tools/socket_manager.py b/python_files/testing_tools/socket_manager.py index b2afbf0e5a17..3392a4d54e07 100644 --- a/python_files/testing_tools/socket_manager.py +++ b/python_files/testing_tools/socket_manager.py @@ -29,9 +29,7 @@ def __exit__(self, *_): self.close() def connect(self): - self.socket = socket.socket( - socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP - ) + self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) if sys.platform == "win32": addr_use = socket.SO_EXCLUSIVEADDRUSE else: diff --git a/python_files/tests/__main__.py b/python_files/tests/__main__.py index 901385d41d87..347222bd85db 100644 --- a/python_files/tests/__main__.py +++ b/python_files/tests/__main__.py @@ -12,9 +12,7 @@ def parse_args(): parser = argparse.ArgumentParser() # To mark a test as functional: (decorator) @pytest.mark.functional - parser.add_argument( - "--functional", dest="markers", action="append_const", const="functional" - ) + parser.add_argument("--functional", dest="markers", action="append_const", const="functional") parser.add_argument( "--no-functional", dest="markers", action="append_const", const="not functional" ) diff --git a/python_files/tests/debug_adapter/test_install_debugpy.py b/python_files/tests/debug_adapter/test_install_debugpy.py index 45eff1272e00..f72e1089aaab 100644 --- a/python_files/tests/debug_adapter/test_install_debugpy.py +++ b/python_files/tests/debug_adapter/test_install_debugpy.py @@ -18,12 +18,8 @@ def test_install_debugpy(tmpdir): import install_debugpy install_debugpy.main(str(tmpdir)) - dir_path = os.path.join( - str(tmpdir), "debugpy", "_vendored", "pydevd", "_pydevd_bundle" - ) + dir_path = os.path.join(str(tmpdir), "debugpy", "_vendored", "pydevd", "_pydevd_bundle") _check_binaries(dir_path) - dir_path = os.path.join( - str(tmpdir), "debugpy", "_vendored", "pydevd", "_pydevd_frame_eval" - ) + dir_path = os.path.join(str(tmpdir), "debugpy", "_vendored", "pydevd", "_pydevd_frame_eval") _check_binaries(dir_path) diff --git a/python_files/tests/pytestadapter/expected_discovery_test_output.py b/python_files/tests/pytestadapter/expected_discovery_test_output.py index 7fbb0c5c43e7..ba42fcc68fe8 100644 --- a/python_files/tests/pytestadapter/expected_discovery_test_output.py +++ b/python_files/tests/pytestadapter/expected_discovery_test_output.py @@ -322,19 +322,12 @@ # └── test_bottom_function_t # └── test_bottom_function_f dual_level_nested_folder_path = TEST_DATA_PATH / "dual_level_nested_folder" -test_top_folder_path = ( - TEST_DATA_PATH / "dual_level_nested_folder" / "test_top_folder.py" -) +test_top_folder_path = TEST_DATA_PATH / "dual_level_nested_folder" / "test_top_folder.py" -test_nested_folder_one_path = ( - TEST_DATA_PATH / "dual_level_nested_folder" / "nested_folder_one" -) +test_nested_folder_one_path = TEST_DATA_PATH / "dual_level_nested_folder" / "nested_folder_one" test_bottom_folder_path = ( - TEST_DATA_PATH - / "dual_level_nested_folder" - / "nested_folder_one" - / "test_bottom_folder.py" + TEST_DATA_PATH / "dual_level_nested_folder" / "nested_folder_one" / "test_bottom_folder.py" ) @@ -851,12 +844,8 @@ os.path.join(tests_path, "test_a.py"), ), "type_": "test", - "id_": get_absolute_test_id( - "tests/test_a.py::test_a_function", tests_a_path - ), - "runID": get_absolute_test_id( - "tests/test_a.py::test_a_function", tests_a_path - ), + "id_": get_absolute_test_id("tests/test_a.py::test_a_function", tests_a_path), + "runID": get_absolute_test_id("tests/test_a.py::test_a_function", tests_a_path), } ], }, @@ -874,12 +863,8 @@ os.path.join(tests_path, "test_b.py"), ), "type_": "test", - "id_": get_absolute_test_id( - "tests/test_b.py::test_b_function", tests_b_path - ), - "runID": get_absolute_test_id( - "tests/test_b.py::test_b_function", tests_b_path - ), + "id_": get_absolute_test_id("tests/test_b.py::test_b_function", tests_b_path), + "runID": get_absolute_test_id("tests/test_b.py::test_b_function", tests_b_path), } ], }, @@ -996,12 +981,8 @@ } SYMLINK_FOLDER_PATH = TEST_DATA_PATH / "symlink_folder" SYMLINK_FOLDER_PATH_TESTS = TEST_DATA_PATH / "symlink_folder" / "tests" -SYMLINK_FOLDER_PATH_TESTS_TEST_A = ( - TEST_DATA_PATH / "symlink_folder" / "tests" / "test_a.py" -) -SYMLINK_FOLDER_PATH_TESTS_TEST_B = ( - TEST_DATA_PATH / "symlink_folder" / "tests" / "test_b.py" -) +SYMLINK_FOLDER_PATH_TESTS_TEST_A = TEST_DATA_PATH / "symlink_folder" / "tests" / "test_a.py" +SYMLINK_FOLDER_PATH_TESTS_TEST_B = TEST_DATA_PATH / "symlink_folder" / "tests" / "test_b.py" symlink_expected_discovery_output = { "name": "symlink_folder", diff --git a/python_files/tests/pytestadapter/expected_execution_test_output.py b/python_files/tests/pytestadapter/expected_execution_test_output.py index db4e493c3daa..34693d36b125 100644 --- a/python_files/tests/pytestadapter/expected_execution_test_output.py +++ b/python_files/tests/pytestadapter/expected_execution_test_output.py @@ -20,9 +20,7 @@ test_add_path = TEST_DATA_PATH / "unittest_folder" / "test_add.py" test_subtract_path = TEST_DATA_PATH / "unittest_folder" / "test_subtract.py" uf_execution_expected_output = { - get_absolute_test_id( - f"{TEST_ADD_FUNCTION}test_add_negative_numbers", test_add_path - ): { + get_absolute_test_id(f"{TEST_ADD_FUNCTION}test_add_negative_numbers", test_add_path): { "test": get_absolute_test_id( f"{TEST_ADD_FUNCTION}test_add_negative_numbers", test_add_path ), @@ -31,9 +29,7 @@ "traceback": None, "subtest": None, }, - get_absolute_test_id( - f"{TEST_ADD_FUNCTION}test_add_positive_numbers", test_add_path - ): { + get_absolute_test_id(f"{TEST_ADD_FUNCTION}test_add_positive_numbers", test_add_path): { "test": get_absolute_test_id( f"{TEST_ADD_FUNCTION}test_add_positive_numbers", test_add_path ), @@ -80,9 +76,7 @@ test_add_path = TEST_DATA_PATH / "unittest_folder" / "test_add.py" uf_single_file_expected_output = { - get_absolute_test_id( - f"{TEST_ADD_FUNCTION}test_add_negative_numbers", test_add_path - ): { + get_absolute_test_id(f"{TEST_ADD_FUNCTION}test_add_negative_numbers", test_add_path): { "test": get_absolute_test_id( f"{TEST_ADD_FUNCTION}test_add_negative_numbers", test_add_path ), @@ -91,9 +85,7 @@ "traceback": None, "subtest": None, }, - get_absolute_test_id( - f"{TEST_ADD_FUNCTION}test_add_positive_numbers", test_add_path - ): { + get_absolute_test_id(f"{TEST_ADD_FUNCTION}test_add_positive_numbers", test_add_path): { "test": get_absolute_test_id( f"{TEST_ADD_FUNCTION}test_add_positive_numbers", test_add_path ), @@ -111,9 +103,7 @@ # │ └── TestAddFunction # │ └── test_add_positive_numbers: success uf_single_method_execution_expected_output = { - get_absolute_test_id( - f"{TEST_ADD_FUNCTION}test_add_positive_numbers", test_add_path - ): { + get_absolute_test_id(f"{TEST_ADD_FUNCTION}test_add_positive_numbers", test_add_path): { "test": get_absolute_test_id( f"{TEST_ADD_FUNCTION}test_add_positive_numbers", test_add_path ), @@ -149,9 +139,7 @@ "traceback": None, "subtest": None, }, - get_absolute_test_id( - f"{TEST_ADD_FUNCTION}test_add_positive_numbers", test_add_path - ): { + get_absolute_test_id(f"{TEST_ADD_FUNCTION}test_add_positive_numbers", test_add_path): { "test": get_absolute_test_id( f"{TEST_ADD_FUNCTION}test_add_positive_numbers", test_add_path ), @@ -252,35 +240,27 @@ "subtest": None, }, get_absolute_test_id("skip_tests.py::test_another_thing", skip_tests_path): { - "test": get_absolute_test_id( - "skip_tests.py::test_another_thing", skip_tests_path - ), + "test": get_absolute_test_id("skip_tests.py::test_another_thing", skip_tests_path), "outcome": "skipped", "message": None, "traceback": None, "subtest": None, }, get_absolute_test_id("skip_tests.py::test_decorator_thing", skip_tests_path): { - "test": get_absolute_test_id( - "skip_tests.py::test_decorator_thing", skip_tests_path - ), + "test": get_absolute_test_id("skip_tests.py::test_decorator_thing", skip_tests_path), "outcome": "skipped", "message": None, "traceback": None, "subtest": None, }, get_absolute_test_id("skip_tests.py::test_decorator_thing_2", skip_tests_path): { - "test": get_absolute_test_id( - "skip_tests.py::test_decorator_thing_2", skip_tests_path - ), + "test": get_absolute_test_id("skip_tests.py::test_decorator_thing_2", skip_tests_path), "outcome": "skipped", "message": None, "traceback": None, "subtest": None, }, - get_absolute_test_id( - "skip_tests.py::TestClass::test_class_function_a", skip_tests_path - ): { + get_absolute_test_id("skip_tests.py::TestClass::test_class_function_a", skip_tests_path): { "test": get_absolute_test_id( "skip_tests.py::TestClass::test_class_function_a", skip_tests_path ), @@ -289,9 +269,7 @@ "traceback": None, "subtest": None, }, - get_absolute_test_id( - "skip_tests.py::TestClass::test_class_function_b", skip_tests_path - ): { + get_absolute_test_id("skip_tests.py::TestClass::test_class_function_b", skip_tests_path): { "test": get_absolute_test_id( "skip_tests.py::TestClass::test_class_function_b", skip_tests_path ), @@ -316,10 +294,7 @@ TEST_DATA_PATH / "dual_level_nested_folder" / "test_top_folder.py" ) dual_level_nested_folder_bottom_path = ( - TEST_DATA_PATH - / "dual_level_nested_folder" - / "nested_folder_one" - / "test_bottom_folder.py" + TEST_DATA_PATH / "dual_level_nested_folder" / "nested_folder_one" / "test_bottom_folder.py" ) dual_level_nested_folder_execution_expected_output = { get_absolute_test_id( @@ -379,9 +354,7 @@ # └── test_nest.py # └── test_function: success -nested_folder_path = ( - TEST_DATA_PATH / "folder_a" / "folder_b" / "folder_a" / "test_nest.py" -) +nested_folder_path = TEST_DATA_PATH / "folder_a" / "folder_b" / "folder_a" / "test_nest.py" double_nested_folder_expected_execution_output = { get_absolute_test_id( "folder_a/folder_b/folder_a/test_nest.py::test_function", nested_folder_path @@ -403,9 +376,7 @@ parametrize_tests_path = TEST_DATA_PATH / "parametrize_tests.py" parametrize_tests_expected_execution_output = { - get_absolute_test_id( - "parametrize_tests.py::test_adding[3+5-8]", parametrize_tests_path - ): { + get_absolute_test_id("parametrize_tests.py::test_adding[3+5-8]", parametrize_tests_path): { "test": get_absolute_test_id( "parametrize_tests.py::test_adding[3+5-8]", parametrize_tests_path ), @@ -414,9 +385,7 @@ "traceback": None, "subtest": None, }, - get_absolute_test_id( - "parametrize_tests.py::test_adding[2+4-6]", parametrize_tests_path - ): { + get_absolute_test_id("parametrize_tests.py::test_adding[2+4-6]", parametrize_tests_path): { "test": get_absolute_test_id( "parametrize_tests.py::test_adding[2+4-6]", parametrize_tests_path ), @@ -425,9 +394,7 @@ "traceback": None, "subtest": None, }, - get_absolute_test_id( - "parametrize_tests.py::test_adding[6+9-16]", parametrize_tests_path - ): { + get_absolute_test_id("parametrize_tests.py::test_adding[6+9-16]", parametrize_tests_path): { "test": get_absolute_test_id( "parametrize_tests.py::test_adding[6+9-16]", parametrize_tests_path ), @@ -442,9 +409,7 @@ # └── parametrize_tests.py # └── test_adding[3+5-8]: success single_parametrize_tests_expected_execution_output = { - get_absolute_test_id( - "parametrize_tests.py::test_adding[3+5-8]", parametrize_tests_path - ): { + get_absolute_test_id("parametrize_tests.py::test_adding[3+5-8]", parametrize_tests_path): { "test": get_absolute_test_id( "parametrize_tests.py::test_adding[3+5-8]", parametrize_tests_path ), @@ -461,9 +426,7 @@ doc_test_path = TEST_DATA_PATH / "text_docstring.txt" doctest_pytest_expected_execution_output = { get_absolute_test_id("text_docstring.txt::text_docstring.txt", doc_test_path): { - "test": get_absolute_test_id( - "text_docstring.txt::text_docstring.txt", doc_test_path - ), + "test": get_absolute_test_id("text_docstring.txt::text_docstring.txt", doc_test_path), "outcome": "success", "message": None, "traceback": None, @@ -477,10 +440,7 @@ TEST_DATA_PATH / "dual_level_nested_folder" / "test_top_folder.py" ) dual_level_nested_folder_bottom_path = ( - TEST_DATA_PATH - / "dual_level_nested_folder" - / "nested_folder_one" - / "test_bottom_folder.py" + TEST_DATA_PATH / "dual_level_nested_folder" / "nested_folder_one" / "test_bottom_folder.py" ) unittest_folder_add_path = TEST_DATA_PATH / "unittest_folder" / "test_add.py" unittest_folder_subtract_path = TEST_DATA_PATH / "unittest_folder" / "test_subtract.py" @@ -494,26 +454,20 @@ "subtest": None, }, get_absolute_test_id("test_top_function_t", dual_level_nested_folder_top_path): { - "test": get_absolute_test_id( - "test_top_function_t", dual_level_nested_folder_top_path - ), + "test": get_absolute_test_id("test_top_function_t", dual_level_nested_folder_top_path), "outcome": "success", "message": None, "traceback": None, "subtest": None, }, get_absolute_test_id("test_top_function_f", dual_level_nested_folder_top_path): { - "test": get_absolute_test_id( - "test_top_function_f", dual_level_nested_folder_top_path - ), + "test": get_absolute_test_id("test_top_function_f", dual_level_nested_folder_top_path), "outcome": "failure", "message": "ERROR MESSAGE", "traceback": None, "subtest": None, }, - get_absolute_test_id( - "test_bottom_function_t", dual_level_nested_folder_bottom_path - ): { + get_absolute_test_id("test_bottom_function_t", dual_level_nested_folder_bottom_path): { "test": get_absolute_test_id( "test_bottom_function_t", dual_level_nested_folder_bottom_path ), @@ -522,9 +476,7 @@ "traceback": None, "subtest": None, }, - get_absolute_test_id( - "test_bottom_function_f", dual_level_nested_folder_bottom_path - ): { + get_absolute_test_id("test_bottom_function_f", dual_level_nested_folder_bottom_path): { "test": get_absolute_test_id( "test_bottom_function_f", dual_level_nested_folder_bottom_path ), @@ -533,9 +485,7 @@ "traceback": None, "subtest": None, }, - get_absolute_test_id( - "TestAddFunction::test_add_negative_numbers", unittest_folder_add_path - ): { + get_absolute_test_id("TestAddFunction::test_add_negative_numbers", unittest_folder_add_path): { "test": get_absolute_test_id( "TestAddFunction::test_add_negative_numbers", unittest_folder_add_path ), @@ -544,9 +494,7 @@ "traceback": None, "subtest": None, }, - get_absolute_test_id( - "TestAddFunction::test_add_positive_numbers", unittest_folder_add_path - ): { + get_absolute_test_id("TestAddFunction::test_add_positive_numbers", unittest_folder_add_path): { "test": get_absolute_test_id( "TestAddFunction::test_add_positive_numbers", unittest_folder_add_path ), @@ -606,18 +554,14 @@ logging_test_expected_execution_output = { get_absolute_test_id("test_logging.py::test_logging2", test_logging_path): { - "test": get_absolute_test_id( - "test_logging.py::test_logging2", test_logging_path - ), + "test": get_absolute_test_id("test_logging.py::test_logging2", test_logging_path), "outcome": "failure", "message": "ERROR MESSAGE", "traceback": None, "subtest": None, }, get_absolute_test_id("test_logging.py::test_logging", test_logging_path): { - "test": get_absolute_test_id( - "test_logging.py::test_logging", test_logging_path - ), + "test": get_absolute_test_id("test_logging.py::test_logging", test_logging_path), "outcome": "success", "message": None, "traceback": None, @@ -632,9 +576,7 @@ test_safe_clear_env_vars_path = TEST_DATA_PATH / "test_env_vars.py" safe_clear_env_vars_expected_execution_output = { - get_absolute_test_id( - "test_env_vars.py::test_clear_env", test_safe_clear_env_vars_path - ): { + get_absolute_test_id("test_env_vars.py::test_clear_env", test_safe_clear_env_vars_path): { "test": get_absolute_test_id( "test_env_vars.py::test_clear_env", test_safe_clear_env_vars_path ), @@ -643,9 +585,7 @@ "traceback": None, "subtest": None, }, - get_absolute_test_id( - "test_env_vars.py::test_check_env", test_safe_clear_env_vars_path - ): { + get_absolute_test_id("test_env_vars.py::test_check_env", test_safe_clear_env_vars_path): { "test": get_absolute_test_id( "test_env_vars.py::test_check_env", test_safe_clear_env_vars_path ), diff --git a/python_files/tests/pytestadapter/helpers.py b/python_files/tests/pytestadapter/helpers.py index 8657da612954..dd69379a45b9 100644 --- a/python_files/tests/pytestadapter/helpers.py +++ b/python_files/tests/pytestadapter/helpers.py @@ -68,9 +68,7 @@ def create_server( def _new_sock() -> socket.socket: - sock: socket.socket = socket.socket( - socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP - ) + sock: socket.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP) options = [ ("SOL_SOCKET", "SO_KEEPALIVE", 1), ("IPPROTO_TCP", "TCP_KEEPIDLE", 1), @@ -88,9 +86,7 @@ def _new_sock() -> socket.socket: CONTENT_LENGTH: str = "Content-Length:" -Env_Dict = TypedDict( - "Env_Dict", {"TEST_UUID": str, "TEST_PORT": str, "PYTHONPATH": str} -) +Env_Dict = TypedDict("Env_Dict", {"TEST_UUID": str, "TEST_PORT": str, "PYTHONPATH": str}) def process_rpc_message(data: str) -> Tuple[Dict[str, Any], str]: @@ -133,9 +129,7 @@ def runner(args: List[str]) -> Optional[List[Dict[str, Any]]]: return runner_with_cwd(args, TEST_DATA_PATH) -def runner_with_cwd( - args: List[str], path: pathlib.Path -) -> Optional[List[Dict[str, Any]]]: +def runner_with_cwd(args: List[str], path: pathlib.Path) -> Optional[List[Dict[str, Any]]]: """Run the pytest discovery and return the JSON data from the server.""" process_args: List[str] = [ sys.executable, @@ -177,9 +171,7 @@ def runner_with_cwd( return process_rpc_json(result[0]) if result else None -def _listen_on_socket( - listener: socket.socket, result: List[str], completed: threading.Event -): +def _listen_on_socket(listener: socket.socket, result: List[str], completed: threading.Event): """Listen on the socket for the JSON data from the server. Created as a separate function for clarity in threading. """ @@ -201,9 +193,7 @@ def _listen_on_socket( result.append("".join(all_data)) -def _run_test_code( - proc_args: List[str], proc_env, proc_cwd: str, completed: threading.Event -): +def _run_test_code(proc_args: List[str], proc_env, proc_cwd: str, completed: threading.Event): result = subprocess.run(proc_args, env=proc_env, cwd=proc_cwd) completed.set() return result diff --git a/python_files/tests/pytestadapter/test_discovery.py b/python_files/tests/pytestadapter/test_discovery.py index 42795fb7920f..942f741a4767 100644 --- a/python_files/tests/pytestadapter/test_discovery.py +++ b/python_files/tests/pytestadapter/test_discovery.py @@ -36,17 +36,13 @@ def test_import_error(tmp_path): temp_dir.mkdir() p = temp_dir / "error_pytest_import.py" shutil.copyfile(file_path, p) - actual: Optional[List[Dict[str, Any]]] = helpers.runner( - ["--collect-only", os.fspath(p)] - ) + actual: Optional[List[Dict[str, Any]]] = helpers.runner(["--collect-only", os.fspath(p)]) assert actual actual_list: List[Dict[str, Any]] = actual if actual_list is not None: assert actual_list.pop(-1).get("eot") for actual_item in actual_list: - assert all( - item in actual_item.keys() for item in ("status", "cwd", "error") - ) + assert all(item in actual_item.keys() for item in ("status", "cwd", "error")) assert actual_item.get("status") == "error" assert actual_item.get("cwd") == os.fspath(helpers.TEST_DATA_PATH) @@ -89,9 +85,7 @@ def test_syntax_error(tmp_path): if actual_list is not None: assert actual_list.pop(-1).get("eot") for actual_item in actual_list: - assert all( - item in actual_item.keys() for item in ("status", "cwd", "error") - ) + assert all(item in actual_item.keys() for item in ("status", "cwd", "error")) assert actual_item.get("status") == "error" assert actual_item.get("cwd") == os.fspath(helpers.TEST_DATA_PATH) @@ -117,9 +111,7 @@ def test_parameterized_error_collect(): if actual_list is not None: assert actual_list.pop(-1).get("eot") for actual_item in actual_list: - assert all( - item in actual_item.keys() for item in ("status", "cwd", "error") - ) + assert all(item in actual_item.keys() for item in ("status", "cwd", "error")) assert actual_item.get("status") == "error" assert actual_item.get("cwd") == os.fspath(helpers.TEST_DATA_PATH) @@ -243,9 +235,7 @@ def test_symlink_root_dir(): assert actual_item.get("cwd") == os.fspath( destination ), f"CWD does not match: {os.fspath(destination)}" - assert ( - actual_item.get("tests") == expected - ), "Tests do not match expected value" + assert actual_item.get("tests") == expected, "Tests do not match expected value" except AssertionError as e: # Print the actual_item in JSON format if an assertion fails print(json.dumps(actual_item, indent=4)) diff --git a/python_files/tests/pytestadapter/test_execution.py b/python_files/tests/pytestadapter/test_execution.py index a8336089d0a9..b4fffd6a640b 100644 --- a/python_files/tests/pytestadapter/test_execution.py +++ b/python_files/tests/pytestadapter/test_execution.py @@ -28,9 +28,7 @@ def test_config_file(): ] new_cwd = TEST_DATA_PATH / "root" actual = runner_with_cwd(args, new_cwd) - expected_const = ( - expected_execution_test_output.config_file_pytest_expected_execution_output - ) + expected_const = expected_execution_test_output.config_file_pytest_expected_execution_output assert actual actual_list: List[Dict[str, Any]] = actual assert actual_list.pop(-1).get("eot") @@ -38,9 +36,7 @@ def test_config_file(): actual_result_dict = dict() if actual_list is not None: for actual_item in actual_list: - assert all( - item in actual_item.keys() for item in ("status", "cwd", "result") - ) + assert all(item in actual_item.keys() for item in ("status", "cwd", "result")) assert actual_item.get("status") == "success" assert actual_item.get("cwd") == os.fspath(new_cwd) actual_result_dict.update(actual_item["result"]) @@ -53,9 +49,7 @@ def test_rootdir_specified(): args = [rd, "tests/test_a.py::test_a_function"] new_cwd = TEST_DATA_PATH / "root" actual = runner_with_cwd(args, new_cwd) - expected_const = ( - expected_execution_test_output.config_file_pytest_expected_execution_output - ) + expected_const = expected_execution_test_output.config_file_pytest_expected_execution_output assert actual actual_list: List[Dict[str, Any]] = actual assert actual_list.pop(-1).get("eot") @@ -63,9 +57,7 @@ def test_rootdir_specified(): actual_result_dict = dict() if actual_list is not None: for actual_item in actual_list: - assert all( - item in actual_item.keys() for item in ("status", "cwd", "result") - ) + assert all(item in actual_item.keys() for item in ("status", "cwd", "result")) assert actual_item.get("status") == "success" assert actual_item.get("cwd") == os.fspath(new_cwd) actual_result_dict.update(actual_item["result"]) @@ -101,9 +93,7 @@ def test_syntax_error_execution(tmp_path): assert actual_list.pop(-1).get("eot") if actual_list is not None: for actual_item in actual_list: - assert all( - item in actual_item.keys() for item in ("status", "cwd", "error") - ) + assert all(item in actual_item.keys() for item in ("status", "cwd", "error")) assert actual_item.get("status") == "error" assert actual_item.get("cwd") == os.fspath(TEST_DATA_PATH) error_content = actual_item.get("error") @@ -126,9 +116,7 @@ def test_bad_id_error_execution(): assert actual_list.pop(-1).get("eot") if actual_list is not None: for actual_item in actual_list: - assert all( - item in actual_item.keys() for item in ("status", "cwd", "error") - ) + assert all(item in actual_item.keys() for item in ("status", "cwd", "error")) assert actual_item.get("status") == "error" assert actual_item.get("cwd") == os.fspath(TEST_DATA_PATH) error_content = actual_item.get("error") @@ -273,9 +261,7 @@ def test_pytest_execution(test_ids, expected_const): actual_result_dict = dict() if actual_list is not None: for actual_item in actual_list: - assert all( - item in actual_item.keys() for item in ("status", "cwd", "result") - ) + assert all(item in actual_item.keys() for item in ("status", "cwd", "result")) assert actual_item.get("status") == "success" assert actual_item.get("cwd") == os.fspath(TEST_DATA_PATH) actual_result_dict.update(actual_item["result"]) @@ -307,13 +293,9 @@ def test_symlink_run(): ) # Run pytest with the cwd being the resolved symlink path (as it will be when we run the subprocess from node). - actual = runner_with_cwd( - [f"--rootdir={os.fspath(destination)}", test_a_id], source - ) + actual = runner_with_cwd([f"--rootdir={os.fspath(destination)}", test_a_id], source) - expected_const = ( - expected_execution_test_output.symlink_run_expected_execution_output - ) + expected_const = expected_execution_test_output.symlink_run_expected_execution_output assert actual actual_list: List[Dict[str, Any]] = actual if actual_list is not None: diff --git a/python_files/tests/test_create_conda.py b/python_files/tests/test_create_conda.py index 29dc323402eb..8681184ba821 100644 --- a/python_files/tests/test_create_conda.py +++ b/python_files/tests/test_create_conda.py @@ -29,9 +29,7 @@ def install_packages(_name): def run_process(args, error_message): nonlocal run_process_called run_process_called = True - version = ( - "12345" if python else f"{sys.version_info.major}.{sys.version_info.minor}" - ) + version = "12345" if python else f"{sys.version_info.major}.{sys.version_info.minor}" if not env_exists: assert args == [ sys.executable, diff --git a/python_files/tests/test_create_venv.py b/python_files/tests/test_create_venv.py index 446d6da8bc55..1539f1d9b44e 100644 --- a/python_files/tests/test_create_venv.py +++ b/python_files/tests/test_create_venv.py @@ -14,9 +14,7 @@ import create_venv -@pytest.mark.skipif( - sys.platform == "win32", reason="Windows does not have micro venv fallback." -) +@pytest.mark.skipif(sys.platform == "win32", reason="Windows does not have micro venv fallback.") def test_venv_not_installed_unix(): importlib.reload(create_venv) create_venv.is_installed = lambda module: module != "venv" @@ -43,9 +41,7 @@ def run_process(args, error_message): assert run_process_called is True -@pytest.mark.skipif( - sys.platform != "win32", reason="Windows does not have microvenv fallback." -) +@pytest.mark.skipif(sys.platform != "win32", reason="Windows does not have microvenv fallback.") def test_venv_not_installed_windows(): importlib.reload(create_venv) create_venv.is_installed = lambda module: module != "venv" @@ -106,9 +102,7 @@ def add_gitignore(_name): assert run_process_called == (env_exists == "noEnv") # add_gitignore is called when new venv is created and git_ignore is True - assert add_gitignore_called == ( - (env_exists == "noEnv") and (git_ignore == "useGitIgnore") - ) + assert add_gitignore_called == ((env_exists == "noEnv") and (git_ignore == "useGitIgnore")) @pytest.mark.parametrize("install_type", ["requirements", "pyproject", "both"]) @@ -238,9 +232,7 @@ def run_process(args, error_message): if "install" in args and "pip" in args: nonlocal run_process_called run_process_called = True - pip_pyz_path = os.fspath( - create_venv.CWD / create_venv.VENV_NAME / "pip.pyz" - ) + pip_pyz_path = os.fspath(create_venv.CWD / create_venv.VENV_NAME / "pip.pyz") assert args[1:] == [pip_pyz_path, "install", "pip"] assert error_message == "CREATE_VENV.INSTALL_PIP_FAILED" diff --git a/python_files/tests/testing_tools/adapter/pytest/test_discovery.py b/python_files/tests/testing_tools/adapter/pytest/test_discovery.py index 83eeaa1f9062..55a0e65102ae 100644 --- a/python_files/tests/testing_tools/adapter/pytest/test_discovery.py +++ b/python_files/tests/testing_tools/adapter/pytest/test_discovery.py @@ -224,7 +224,7 @@ def _fix_fileid(*args): # dependency injection _normcase=normcase, _pathsep=pathsep, - ) + ), ) def _normalize_test_id(*args): @@ -234,7 +234,7 @@ def _normalize_test_id(*args): # dependency injection _fix_fileid=_fix_fileid, _pathsep=pathsep, - ) + ), ) def _iter_nodes(*args): @@ -245,7 +245,7 @@ def _iter_nodes(*args): _normalize_test_id=_normalize_test_id, _normcase=normcase, _pathsep=pathsep, - ) + ), ) def _parse_node_id(*args): @@ -254,7 +254,7 @@ def _parse_node_id(*args): **dict( # dependency injection _iter_nodes=_iter_nodes, - ) + ), ) ########## @@ -264,7 +264,7 @@ def _split_fspath(*args): **dict( # dependency injection _normcase=normcase, - ) + ), ) ########## @@ -275,7 +275,7 @@ def _matches_relfile(*args): # dependency injection _normcase=normcase, _pathsep=pathsep, - ) + ), ) def _is_legacy_wrapper(*args): @@ -284,7 +284,7 @@ def _is_legacy_wrapper(*args): **dict( # dependency injection _pathsep=pathsep, - ) + ), ) def _get_location(*args): @@ -295,7 +295,7 @@ def _get_location(*args): _matches_relfile=_matches_relfile, _is_legacy_wrapper=_is_legacy_wrapper, _pathsep=pathsep, - ) + ), ) ########## @@ -307,7 +307,7 @@ def _parse_item(item): _parse_node_id=_parse_node_id, _split_fspath=_split_fspath, _get_location=_get_location, - ) + ), ) return _parse_item @@ -347,9 +347,7 @@ def test_basic(self): ("discovered.__getitem__", (0,), None), ] - parents, tests = _discovery.discover( - [], _pytest_main=stubpytest.main, _plugin=plugin - ) + parents, tests = _discovery.discover([], _pytest_main=stubpytest.main, _plugin=plugin) actual_calls = unique(stub.calls, lambda k: k[0]) expected_calls = unique(calls, lambda k: k[0]) @@ -389,9 +387,7 @@ def test_no_tests_found(self): ("discovered.__getitem__", (0,), None), ] - parents, tests = _discovery.discover( - [], _pytest_main=pytest.main, _plugin=plugin - ) + parents, tests = _discovery.discover([], _pytest_main=pytest.main, _plugin=plugin) actual_calls = unique(stub.calls, lambda k: k[0]) expected_calls = unique(calls, lambda k: k[0]) @@ -414,9 +410,7 @@ def test_found_with_collection_error(self): ("discovered.__getitem__", (0,), None), ] - parents, tests = _discovery.discover( - [], _pytest_main=pytest.main, _plugin=plugin - ) + parents, tests = _discovery.discover([], _pytest_main=pytest.main, _plugin=plugin) actual_calls = unique(stub.calls, lambda k: k[0]) expected_calls = unique(calls, lambda k: k[0]) @@ -845,9 +839,7 @@ def test_finish(self): func="SpamTests.test_spam", sub=None, ), - source="{}:{}".format( - adapter_util.fix_relpath(relfile), 13 - ), + source="{}:{}".format(adapter_util.fix_relpath(relfile), 13), markers=None, parentid="./x/y/z/test_eggs.py::SpamTests", ), @@ -920,9 +912,7 @@ def test_doctest(self): relfile=adapter_util.fix_relpath(doctestfile), func=None, ), - source="{}:{}".format( - adapter_util.fix_relpath(doctestfile), 1 - ), + source="{}:{}".format(adapter_util.fix_relpath(doctestfile), 1), markers=[], parentid="./x/test_doctest.txt", ), @@ -972,9 +962,7 @@ def test_doctest(self): relfile=adapter_util.fix_relpath(relfile), func=None, ), - source="{}:{}".format( - adapter_util.fix_relpath(relfile), 13 - ), + source="{}:{}".format(adapter_util.fix_relpath(relfile), 13), markers=[], parentid="./x/y/z/test_eggs.py", ), @@ -999,9 +987,7 @@ def test_doctest(self): relfile=adapter_util.fix_relpath(relfile), func=None, ), - source="{}:{}".format( - adapter_util.fix_relpath(relfile), 28 - ), + source="{}:{}".format(adapter_util.fix_relpath(relfile), 28), markers=[], parentid="./x/y/z/test_eggs.py", ), @@ -1062,9 +1048,7 @@ def test_nested_brackets(self): func="SpamTests.test_spam", sub=["[a-[b]-c]"], ), - source="{}:{}".format( - adapter_util.fix_relpath(relfile), 13 - ), + source="{}:{}".format(adapter_util.fix_relpath(relfile), 13), markers=None, parentid="./x/y/z/test_eggs.py::SpamTests::test_spam", ), @@ -1126,9 +1110,7 @@ def test_nested_suite(self): func="SpamTests.Ham.Eggs.test_spam", sub=None, ), - source="{}:{}".format( - adapter_util.fix_relpath(relfile), 13 - ), + source="{}:{}".format(adapter_util.fix_relpath(relfile), 13), markers=None, parentid="./x/y/z/test_eggs.py::SpamTests::Ham::Eggs", ), @@ -1479,9 +1461,7 @@ def test_mysterious_parens(self): func="SpamTests.test_spam", sub=[], ), - source="{}:{}".format( - adapter_util.fix_relpath(relfile), 13 - ), + source="{}:{}".format(adapter_util.fix_relpath(relfile), 13), markers=None, parentid="./x/y/z/test_eggs.py::SpamTests", ), @@ -1537,9 +1517,7 @@ def test_mysterious_colons(self): func="SpamTests.test_spam", sub=[], ), - source="{}:{}".format( - adapter_util.fix_relpath(relfile), 13 - ), + source="{}:{}".format(adapter_util.fix_relpath(relfile), 13), markers=None, parentid="./x/y/z/test_eggs.py::SpamTests", ), @@ -1607,9 +1585,7 @@ def test_imported_test(self): func="SpamTests.test_spam", sub=None, ), - source="{}:{}".format( - adapter_util.fix_relpath(srcfile), 13 - ), + source="{}:{}".format(adapter_util.fix_relpath(srcfile), 13), markers=None, parentid="./x/y/z/test_eggs.py::SpamTests", ), diff --git a/python_files/tests/testing_tools/adapter/test_discovery.py b/python_files/tests/testing_tools/adapter/test_discovery.py index c01e625becde..2fe4db7caa37 100644 --- a/python_files/tests/testing_tools/adapter/test_discovery.py +++ b/python_files/tests/testing_tools/adapter/test_discovery.py @@ -252,9 +252,7 @@ def test_add_test_simple(self): # missing "./": parentid=relfile, ) - expected = test._replace( - id=_fix_nodeid(test.id), parentid=_fix_nodeid(test.parentid) - ) + expected = test._replace(id=_fix_nodeid(test.id), parentid=_fix_nodeid(test.parentid)) discovered = DiscoveredTests() before = list(discovered), discovered.parents diff --git a/python_files/tests/testing_tools/adapter/test_functional.py b/python_files/tests/testing_tools/adapter/test_functional.py index a78d36a5fdcf..45c85ee951dc 100644 --- a/python_files/tests/testing_tools/adapter/test_functional.py +++ b/python_files/tests/testing_tools/adapter/test_functional.py @@ -48,9 +48,7 @@ def _run_adapter(cmd, tool, *cliargs, **kwargs): argv.insert(4, "--no-hide-stdio") kwds["stderr"] = subprocess.STDOUT argv.append("--cache-clear") - print( - "running {!r}".format(" ".join(arg.rpartition(CWD + "/")[-1] for arg in argv)) - ) + print("running {!r}".format(" ".join(arg.rpartition(CWD + "/")[-1] for arg in argv))) output = subprocess.check_output(argv, universal_newlines=True, **kwds) return output diff --git a/python_files/tests/testing_tools/adapter/test_util.py b/python_files/tests/testing_tools/adapter/test_util.py index 3fcafd1a93d5..8a7cd475a1c7 100644 --- a/python_files/tests/testing_tools/adapter/test_util.py +++ b/python_files/tests/testing_tools/adapter/test_util.py @@ -259,9 +259,7 @@ def test_fix_fileid(self): ) for fileid, rootdir, _os_path, expected in tests: pathsep = _os_path.sep - with self.subTest( - r"for {} (with rootdir {!r}): {!r}".format(pathsep, rootdir, fileid) - ): + with self.subTest(r"for {} (with rootdir {!r}): {!r}".format(pathsep, rootdir, fileid)): fixed = fix_fileid( fileid, rootdir, diff --git a/python_files/tests/unittestadapter/.data/two_patterns/pattern_a_test.py b/python_files/tests/unittestadapter/.data/two_patterns/pattern_a_test.py index 4f3f77e1056e..52641360b526 100644 --- a/python_files/tests/unittestadapter/.data/two_patterns/pattern_a_test.py +++ b/python_files/tests/unittestadapter/.data/two_patterns/pattern_a_test.py @@ -7,7 +7,6 @@ # and the two tests with their outcome as "success". - class DiscoveryA(unittest.TestCase): """Test class for the two file pattern test. It is pattern *test.py @@ -19,4 +18,4 @@ def test_one_a(self) -> None: self.assertGreater(2, 1) def test_two_a(self) -> None: - self.assertNotEqual(2, 1) \ No newline at end of file + self.assertNotEqual(2, 1) diff --git a/python_files/tests/unittestadapter/.data/two_patterns/test_pattern_b.py b/python_files/tests/unittestadapter/.data/two_patterns/test_pattern_b.py index a912699383ca..06b6a818537d 100644 --- a/python_files/tests/unittestadapter/.data/two_patterns/test_pattern_b.py +++ b/python_files/tests/unittestadapter/.data/two_patterns/test_pattern_b.py @@ -6,10 +6,10 @@ # The test_ids_multiple_runs function should return a dictionary with a "success" status, # and the two tests with their outcome as "success". -class DiscoveryB(unittest.TestCase): +class DiscoveryB(unittest.TestCase): def test_one_b(self) -> None: self.assertGreater(2, 1) def test_two_b(self) -> None: - self.assertNotEqual(2, 1) \ No newline at end of file + self.assertNotEqual(2, 1) diff --git a/python_files/tests/unittestadapter/.data/unittest_folder/test_add.py b/python_files/tests/unittestadapter/.data/unittest_folder/test_add.py index 2e616077ec40..f562474b596a 100644 --- a/python_files/tests/unittestadapter/.data/unittest_folder/test_add.py +++ b/python_files/tests/unittestadapter/.data/unittest_folder/test_add.py @@ -6,17 +6,16 @@ # files in the same folder. The cwd is set to the parent folder. This should return # a dictionary with a "success" status and the two tests with their outcome as "success". + def add(a, b): return a + b class TestAddFunction(unittest.TestCase): - - def test_add_positive_numbers(self): + def test_add_positive_numbers(self): result = add(2, 3) self.assertEqual(result, 5) - - def test_add_negative_numbers(self): + def test_add_negative_numbers(self): result = add(-2, -3) - self.assertEqual(result, -5) \ No newline at end of file + self.assertEqual(result, -5) diff --git a/python_files/tests/unittestadapter/.data/unittest_folder/test_subtract.py b/python_files/tests/unittestadapter/.data/unittest_folder/test_subtract.py index 4028e25825d1..8ac3988a3251 100644 --- a/python_files/tests/unittestadapter/.data/unittest_folder/test_subtract.py +++ b/python_files/tests/unittestadapter/.data/unittest_folder/test_subtract.py @@ -6,6 +6,7 @@ # files in the same folder. The cwd is set to the parent folder. This should return # a dictionary with a "success" status and the two tests with their outcome as "success". + def subtract(a, b): return a - b @@ -15,7 +16,6 @@ def test_subtract_positive_numbers(self): result = subtract(5, 3) self.assertEqual(result, 2) - def test_subtract_negative_numbers(self): result = subtract(-2, -3) - self.assertEqual(result, 1) \ No newline at end of file + self.assertEqual(result, 1) diff --git a/python_files/tests/unittestadapter/expected_discovery_test_output.py b/python_files/tests/unittestadapter/expected_discovery_test_output.py index 1007a8f42dfd..9fca67a3a574 100644 --- a/python_files/tests/unittestadapter/expected_discovery_test_output.py +++ b/python_files/tests/unittestadapter/expected_discovery_test_output.py @@ -14,20 +14,14 @@ "type_": TestNodeTypeEnum.folder, "children": [ { - "path": os.fspath( - TEST_DATA_PATH / "unittest_skip" / "unittest_skip_file.py" - ), + "path": os.fspath(TEST_DATA_PATH / "unittest_skip" / "unittest_skip_file.py"), "name": "unittest_skip_file.py", "type_": TestNodeTypeEnum.file, "children": [], - "id_": os.fspath( - TEST_DATA_PATH / "unittest_skip" / "unittest_skip_file.py" - ), + "id_": os.fspath(TEST_DATA_PATH / "unittest_skip" / "unittest_skip_file.py"), }, { - "path": os.fspath( - TEST_DATA_PATH / "unittest_skip" / "unittest_skip_function.py" - ), + "path": os.fspath(TEST_DATA_PATH / "unittest_skip" / "unittest_skip_function.py"), "name": "unittest_skip_function.py", "type_": TestNodeTypeEnum.file, "children": [ @@ -41,30 +35,22 @@ { "name": "testadd1", "path": os.fspath( - TEST_DATA_PATH - / "unittest_skip" - / "unittest_skip_function.py" + TEST_DATA_PATH / "unittest_skip" / "unittest_skip_function.py" ), "lineno": "13", "type_": TestNodeTypeEnum.test, "id_": os.fspath( - TEST_DATA_PATH - / "unittest_skip" - / "unittest_skip_function.py" + TEST_DATA_PATH / "unittest_skip" / "unittest_skip_function.py" ) + "\\SimpleTest\\testadd1", "runID": "unittest_skip_function.SimpleTest.testadd1", } ], - "id_": os.fspath( - TEST_DATA_PATH / "unittest_skip" / "unittest_skip_function.py" - ) + "id_": os.fspath(TEST_DATA_PATH / "unittest_skip" / "unittest_skip_function.py") + "\\SimpleTest", } ], - "id_": os.fspath( - TEST_DATA_PATH / "unittest_skip" / "unittest_skip_function.py" - ), + "id_": os.fspath(TEST_DATA_PATH / "unittest_skip" / "unittest_skip_function.py"), }, ], "id_": os.fspath(TEST_DATA_PATH / "unittest_skip"), @@ -88,9 +74,7 @@ "name": "test_outer_folder", "type_": TestNodeTypeEnum.folder, "path": os.fsdecode( - pathlib.PurePath( - TEST_DATA_PATH, "utils_complex_tree", "test_outer_folder" - ) + pathlib.PurePath(TEST_DATA_PATH, "utils_complex_tree", "test_outer_folder") ), "children": [ { @@ -145,9 +129,7 @@ }, ], "id_": os.fsdecode( - pathlib.PurePath( - TEST_DATA_PATH, "utils_complex_tree", "test_outer_folder" - ) + pathlib.PurePath(TEST_DATA_PATH, "utils_complex_tree", "test_outer_folder") ), } ], diff --git a/python_files/tests/unittestadapter/test_discovery.py b/python_files/tests/unittestadapter/test_discovery.py index fadc2aa3f7e2..462b9cf9b0fe 100644 --- a/python_files/tests/unittestadapter/test_discovery.py +++ b/python_files/tests/unittestadapter/test_discovery.py @@ -107,22 +107,14 @@ def test_simple_discovery() -> None: "path": file_path, "type_": TestNodeTypeEnum.test, "lineno": "14", - "id_": file_path - + "\\" - + "DiscoverySimple" - + "\\" - + "test_one", + "id_": file_path + "\\" + "DiscoverySimple" + "\\" + "test_one", }, { "name": "test_two", "path": file_path, "type_": TestNodeTypeEnum.test, "lineno": "17", - "id_": file_path - + "\\" - + "DiscoverySimple" - + "\\" - + "test_two", + "id_": file_path + "\\" + "DiscoverySimple" + "\\" + "test_two", }, ], "id_": file_path + "\\" + "DiscoverySimple", @@ -170,22 +162,14 @@ def test_simple_discovery_with_top_dir_calculated() -> None: "path": file_path, "type_": TestNodeTypeEnum.test, "lineno": "14", - "id_": file_path - + "\\" - + "DiscoverySimple" - + "\\" - + "test_one", + "id_": file_path + "\\" + "DiscoverySimple" + "\\" + "test_one", }, { "name": "test_two", "path": file_path, "type_": TestNodeTypeEnum.test, "lineno": "17", - "id_": file_path - + "\\" - + "DiscoverySimple" - + "\\" - + "test_two", + "id_": file_path + "\\" + "DiscoverySimple" + "\\" + "test_two", }, ], "id_": file_path + "\\" + "DiscoverySimple", @@ -253,22 +237,14 @@ def test_error_discovery() -> None: "path": file_path, "type_": TestNodeTypeEnum.test, "lineno": "14", - "id_": file_path - + "\\" - + "DiscoveryErrorTwo" - + "\\" - + "test_one", + "id_": file_path + "\\" + "DiscoveryErrorTwo" + "\\" + "test_one", }, { "name": "test_two", "path": file_path, "type_": TestNodeTypeEnum.test, "lineno": "17", - "id_": file_path - + "\\" - + "DiscoveryErrorTwo" - + "\\" - + "test_two", + "id_": file_path + "\\" + "DiscoveryErrorTwo" + "\\" + "test_two", }, ], "id_": file_path + "\\" + "DiscoveryErrorTwo", diff --git a/python_files/unittestadapter/discovery.py b/python_files/unittestadapter/discovery.py index a8dc8ed38097..298fe027d1d9 100644 --- a/python_files/unittestadapter/discovery.py +++ b/python_files/unittestadapter/discovery.py @@ -98,9 +98,7 @@ def discover_tests( # Get abspath of top level directory for build_test_tree. top_level_dir = os.path.abspath(top_level_dir) - tests, error = build_test_tree( - suite, top_level_dir - ) # test tree built successfully here. + tests, error = build_test_tree(suite, top_level_dir) # test tree built successfully here. except Exception: error.append(traceback.format_exc()) @@ -116,9 +114,7 @@ def discover_tests( return payload -def post_response( - payload: Union[PayloadDict, EOTPayloadDict], port: int, uuid: str -) -> None: +def post_response(payload: Union[PayloadDict, EOTPayloadDict], port: int, uuid: str) -> None: # Build the request data (it has to be a POST request or the Node side will not process it), and send it. addr = ("localhost", port) data = json.dumps(payload) diff --git a/python_files/unittestadapter/execution.py b/python_files/unittestadapter/execution.py index f433c117ec7c..9394303b69a1 100644 --- a/python_files/unittestadapter/execution.py +++ b/python_files/unittestadapter/execution.py @@ -22,9 +22,7 @@ from testing_tools import process_json_util, socket_manager # noqa: E402 from unittestadapter.pvsc_utils import parse_unittest_args # noqa: E402 -ErrorType = Union[ - Tuple[Type[BaseException], BaseException, TracebackType], Tuple[None, None, None] -] +ErrorType = Union[Tuple[Type[BaseException], BaseException, TracebackType], Tuple[None, None, None]] testPort = 0 testUuid = 0 START_DIR = "" @@ -244,9 +242,7 @@ def send_run_data(raw_data, port, uuid): post_response(payload, port, uuid) -def post_response( - payload: Union[PayloadDict, EOTPayloadDict], port: int, uuid: str -) -> None: +def post_response(payload: Union[PayloadDict, EOTPayloadDict], port: int, uuid: str) -> None: # Build the request data (it has to be a POST request or the Node side will not process it), and send it. addr = ("localhost", port) global __socket @@ -286,9 +282,7 @@ def post_response( ) = parse_unittest_args(argv[index + 1 :]) run_test_ids_port = os.environ.get("RUN_TEST_IDS_PORT") - run_test_ids_port_int = ( - int(run_test_ids_port) if run_test_ids_port is not None else 0 - ) + run_test_ids_port_int = int(run_test_ids_port) if run_test_ids_port is not None else 0 if run_test_ids_port_int == 0: print("Error[vscode-unittest]: RUN_TEST_IDS_PORT env var is not set.") # get data from socket @@ -309,9 +303,7 @@ def post_response( try: # Try to parse the buffer as JSON - test_ids_from_buffer = process_json_util.process_rpc_json( - buffer.decode("utf-8") - ) + test_ids_from_buffer = process_json_util.process_rpc_json(buffer.decode("utf-8")) # Clear the buffer as complete JSON object is received buffer = b"" break diff --git a/python_files/unittestadapter/pvsc_utils.py b/python_files/unittestadapter/pvsc_utils.py index 673da2aa1eec..de4f23957b8b 100644 --- a/python_files/unittestadapter/pvsc_utils.py +++ b/python_files/unittestadapter/pvsc_utils.py @@ -91,9 +91,7 @@ def build_test_node(path: str, name: str, type_: TestNodeTypeEnum) -> TestNode: return {"path": path, "name": name, "type_": type_, "children": [], "id_": id_gen} -def get_child_node( - name: str, path: str, type_: TestNodeTypeEnum, root: TestNode -) -> TestNode: +def get_child_node(name: str, path: str, type_: TestNodeTypeEnum, root: TestNode) -> TestNode: """Find a child node in a test tree given its name, type and path. If the node doesn't exist, create it. Path is required to distinguish between nodes with the same name and type.""" try: @@ -154,9 +152,7 @@ def build_test_tree( """ error = [] directory_path = pathlib.PurePath(top_level_directory) - root = build_test_node( - top_level_directory, directory_path.name, TestNodeTypeEnum.folder - ) + root = build_test_node(top_level_directory, directory_path.name, TestNodeTypeEnum.folder) for test_case in get_test_case(suite): test_id = test_case.id() @@ -167,9 +163,7 @@ def build_test_tree( class_name = f"{components[-1]}.py" # Find/build class node. file_path = os.fsdecode(os.path.join(directory_path, class_name)) - current_node = get_child_node( - class_name, file_path, TestNodeTypeEnum.file, root - ) + current_node = get_child_node(class_name, file_path, TestNodeTypeEnum.file, root) else: # Get the static test path components: filename, class name and function name. components = test_id.split(".") diff --git a/python_files/visualstudio_py_testlauncher.py b/python_files/visualstudio_py_testlauncher.py index 854a9f4fae5a..b085d5ce4e6f 100644 --- a/python_files/visualstudio_py_testlauncher.py +++ b/python_files/visualstudio_py_testlauncher.py @@ -170,9 +170,7 @@ def addUnexpectedSuccess(self, test): def addSubTest(self, test, subtest, err): super(VsTestResult, self).addSubTest(test, subtest, err) - self.sendResult( - test, "subtest-passed" if err is None else "subtest-failed", err, subtest - ) + self.sendResult(test, "subtest-passed" if err is None else "subtest-failed", err, subtest) def sendResult(self, test, outcome, trace=None, subtest=None): if _channel is not None: @@ -224,9 +222,7 @@ def main(): prog="visualstudio_py_testlauncher", usage="Usage: %prog [