From 3740925216ade31fc8279d46fac7c62678e51a9e Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 2 Aug 2023 11:01:05 -0700 Subject: [PATCH 01/25] run ruff instead of pyright --- .github/workflows/build.yml | 7 +++---- .github/workflows/pr-check.yml | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 24d91b94da10..7390b1899f28 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -100,11 +100,10 @@ jobs: python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy python -m pip install --upgrade -r build/test-requirements.txt - - name: Run Pyright - uses: jakebailey/pyright-action@v1 + - name: Run ruff + uses: chartboost/ruff-action@v1 with: - version: 1.1.308 - working-directory: 'pythonFiles' + src: "./pythonFiles" ### Non-smoke tests tests: diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index aa9cae2aa474..0a944029c61d 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -74,11 +74,10 @@ jobs: python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy python -m pip install --upgrade -r build/test-requirements.txt - - name: Run Pyright - uses: jakebailey/pyright-action@v1 + - name: Run ruff + uses: chartboost/ruff-action@v1 with: - version: 1.1.308 - working-directory: 'pythonFiles' + src: "./pythonFiles" ### Non-smoke tests tests: From 2005d16901398a81083b9dca3d3718474301971c Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 2 Aug 2023 11:05:08 -0700 Subject: [PATCH 02/25] Fix github action name by capitalizing --- .github/workflows/build.yml | 2 +- .github/workflows/pr-check.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7390b1899f28..8b4b31687e91 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -100,7 +100,7 @@ jobs: python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy python -m pip install --upgrade -r build/test-requirements.txt - - name: Run ruff + - name: Run Ruff uses: chartboost/ruff-action@v1 with: src: "./pythonFiles" diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 0a944029c61d..591e9eab80eb 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -74,7 +74,7 @@ jobs: python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy python -m pip install --upgrade -r build/test-requirements.txt - - name: Run ruff + - name: Run Ruff uses: chartboost/ruff-action@v1 with: src: "./pythonFiles" From 4b8b9c2d3e8d744847cdfa81f472d734fabdaa8b Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 2 Aug 2023 11:16:25 -0700 Subject: [PATCH 03/25] format with prettier --- .github/workflows/build.yml | 2 +- .github/workflows/pr-check.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8b4b31687e91..f03908cb5c6b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -103,7 +103,7 @@ jobs: - name: Run Ruff uses: chartboost/ruff-action@v1 with: - src: "./pythonFiles" + src: './pythonFiles' ### Non-smoke tests tests: diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 591e9eab80eb..9df3a389c9dc 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -77,7 +77,7 @@ jobs: - name: Run Ruff uses: chartboost/ruff-action@v1 with: - src: "./pythonFiles" + src: './pythonFiles' ### Non-smoke tests tests: From b424581a5ae887ca240edb24bd9959bfc1bcce17 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 2 Aug 2023 11:43:35 -0700 Subject: [PATCH 04/25] add Ruff to lint workflow --- .github/actions/lint/action.yml | 5 +++++ .github/workflows/build.yml | 7 ++++--- .github/workflows/pr-check.yml | 7 ++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/.github/actions/lint/action.yml b/.github/actions/lint/action.yml index 9478550c107b..19e702f03777 100644 --- a/.github/actions/lint/action.yml +++ b/.github/actions/lint/action.yml @@ -47,3 +47,8 @@ runs: python -m black . --check working-directory: pythonFiles shell: bash + + - name: Run Ruff + uses: chartboost/ruff-action@v1 + with: + src: './pythonFiles' diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f03908cb5c6b..24d91b94da10 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -100,10 +100,11 @@ jobs: python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy python -m pip install --upgrade -r build/test-requirements.txt - - name: Run Ruff - uses: chartboost/ruff-action@v1 + - name: Run Pyright + uses: jakebailey/pyright-action@v1 with: - src: './pythonFiles' + version: 1.1.308 + working-directory: 'pythonFiles' ### Non-smoke tests tests: diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 9df3a389c9dc..aa9cae2aa474 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -74,10 +74,11 @@ jobs: python -m pip --disable-pip-version-check install -t ./pythonFiles/lib/python --no-cache-dir --implementation py --no-deps --upgrade --pre debugpy python -m pip install --upgrade -r build/test-requirements.txt - - name: Run Ruff - uses: chartboost/ruff-action@v1 + - name: Run Pyright + uses: jakebailey/pyright-action@v1 with: - src: './pythonFiles' + version: 1.1.308 + working-directory: 'pythonFiles' ### Non-smoke tests tests: From 3bb9461f1fa55bd364199df6d0e4ede7d4620111 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 2 Aug 2023 11:50:56 -0700 Subject: [PATCH 05/25] line-length 120 for Ruff toml --- pythonFiles/pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pythonFiles/pyproject.toml b/pythonFiles/pyproject.toml index 56237999e603..c31dd7e2fc71 100644 --- a/pythonFiles/pyproject.toml +++ b/pythonFiles/pyproject.toml @@ -34,3 +34,6 @@ ignore = [ 'tests/testing_tools/adapter/pytest/test_cli.py', 'tests/testing_tools/adapter/pytest/test_discovery.py', ] + +[tool.ruff] +line-length = 120 From 0591728e1b725b8411efc71b60884d1e5b9e97b9 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 2 Aug 2023 13:09:39 -0700 Subject: [PATCH 06/25] exempt testing files as such from Pyright --- pythonFiles/pyproject.toml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pythonFiles/pyproject.toml b/pythonFiles/pyproject.toml index c31dd7e2fc71..aadc48a1a705 100644 --- a/pythonFiles/pyproject.toml +++ b/pythonFiles/pyproject.toml @@ -37,3 +37,25 @@ ignore = [ [tool.ruff] line-length = 120 +exclude = ['lib'] +ignore = [ + # Exempt as same as Pyright + 'get-pip.py', + 'install_debugpy.py', + 'tensorboard_launcher.py', + 'testlauncher.py', + 'visualstudio_py_testlauncher.py', + 'testing_tools/unittest_discovery.py', + 'testing_tools/adapter/util.py', + 'testing_tools/adapter/pytest/_discovery.py', + 'testing_tools/adapter/pytest/_pytest_item.py', + 'tests/debug_adapter/test_install_debugpy.py', + 'tests/testing_tools/adapter/.data', + 'tests/testing_tools/adapter/test___main__.py', + 'tests/testing_tools/adapter/test_discovery.py', + 'tests/testing_tools/adapter/test_functional.py', + 'tests/testing_tools/adapter/test_report.py', + 'tests/testing_tools/adapter/test_util.py', + 'tests/testing_tools/adapter/pytest/test_cli.py', + 'tests/testing_tools/adapter/pytest/test_discovery.py', +] From 54d3c42cdf3d7f936ef6a7e5d342f359b88ff3be Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Wed, 2 Aug 2023 13:20:15 -0700 Subject: [PATCH 07/25] Ignore testing_tools files same as Pyright way --- pythonFiles/pyproject.toml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pythonFiles/pyproject.toml b/pythonFiles/pyproject.toml index aadc48a1a705..f01da12b916c 100644 --- a/pythonFiles/pyproject.toml +++ b/pythonFiles/pyproject.toml @@ -37,9 +37,8 @@ ignore = [ [tool.ruff] line-length = 120 -exclude = ['lib'] -ignore = [ - # Exempt as same as Pyright +exclude = [ + # Ignore testing_tools files same as Pyright way 'get-pip.py', 'install_debugpy.py', 'tensorboard_launcher.py', From d3ba893ad4272f1f3ee7289b82d9917f6016ad06 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 3 Aug 2023 11:19:32 -0700 Subject: [PATCH 08/25] Change line length to 140 --- pythonFiles/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonFiles/pyproject.toml b/pythonFiles/pyproject.toml index f01da12b916c..366842dec0c7 100644 --- a/pythonFiles/pyproject.toml +++ b/pythonFiles/pyproject.toml @@ -36,7 +36,7 @@ ignore = [ ] [tool.ruff] -line-length = 120 +line-length = 140 exclude = [ # Ignore testing_tools files same as Pyright way 'get-pip.py', From 7b2efc822fad2d7a44a326dbfea97cb494fed694 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 3 Aug 2023 11:21:21 -0700 Subject: [PATCH 09/25] ignore import top level warning --- pythonFiles/pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pythonFiles/pyproject.toml b/pythonFiles/pyproject.toml index 366842dec0c7..9c44e47013e0 100644 --- a/pythonFiles/pyproject.toml +++ b/pythonFiles/pyproject.toml @@ -37,6 +37,7 @@ ignore = [ [tool.ruff] line-length = 140 +ignore = ["E402"] exclude = [ # Ignore testing_tools files same as Pyright way 'get-pip.py', From 35c28c5fe9fd3868d0e49bd32893846e1560f820 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 3 Aug 2023 11:29:50 -0700 Subject: [PATCH 10/25] exclude old testing files --- pythonFiles/pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pythonFiles/pyproject.toml b/pythonFiles/pyproject.toml index 9c44e47013e0..3e338683b9b8 100644 --- a/pythonFiles/pyproject.toml +++ b/pythonFiles/pyproject.toml @@ -58,4 +58,5 @@ exclude = [ 'tests/testing_tools/adapter/test_util.py', 'tests/testing_tools/adapter/pytest/test_cli.py', 'tests/testing_tools/adapter/pytest/test_discovery.py', + 'pythonFiles/testing_tools/*' ] From 6406c6d9300ba121a2076555543fb0547c25fc4a Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 3 Aug 2023 13:02:36 -0700 Subject: [PATCH 11/25] fix empty try except --- pythonFiles/installed_check.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pythonFiles/installed_check.py b/pythonFiles/installed_check.py index f0e1c268d270..df5d3cb9d082 100644 --- a/pythonFiles/installed_check.py +++ b/pythonFiles/installed_check.py @@ -36,7 +36,7 @@ def parse_requirements(line: str) -> Optional[Requirement]: return req elif req.marker.evaluate(): return req - except: + except Exception: return None @@ -51,7 +51,7 @@ def process_requirements(req_file: pathlib.Path) -> List[Dict[str, Union[str, in try: # Check if package is installed metadata(req.name) - except: + except Exception: diagnostics.append( { "line": n, @@ -79,7 +79,7 @@ def process_pyproject(req_file: pathlib.Path) -> List[Dict[str, Union[str, int]] try: raw_text = req_file.read_text(encoding="utf-8") pyproject = tomli.loads(raw_text) - except: + except Exception: return diagnostics lines = raw_text.splitlines() @@ -91,7 +91,7 @@ def process_pyproject(req_file: pathlib.Path) -> List[Dict[str, Union[str, int]] try: # Check if package is installed metadata(req.name) - except: + except Exception: diagnostics.append( { "line": n, From 48f01649e2b3e3b6f855f237658a1d52ead1fbbd Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 3 Aug 2023 15:12:36 -0700 Subject: [PATCH 12/25] fix more bare exceptions --- pythonFiles/normalizeSelection.py | 2 +- pythonFiles/shell_exec.py | 3 +-- pythonFiles/unittestadapter/utils.py | 7 ++++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pythonFiles/normalizeSelection.py b/pythonFiles/normalizeSelection.py index 35bc42d6e6fe..0363702717ab 100644 --- a/pythonFiles/normalizeSelection.py +++ b/pythonFiles/normalizeSelection.py @@ -118,7 +118,7 @@ def normalize_lines(selection): # Insert a newline between each top-level statement, and append a newline to the selection. source = "\n".join(statements) + "\n" - except: + except Exception: # If there's a problem when parsing statements, # append a blank line to end the block and send it as-is. source = selection + "\n\n" diff --git a/pythonFiles/shell_exec.py b/pythonFiles/shell_exec.py index c521586ca31b..4987399a53ea 100644 --- a/pythonFiles/shell_exec.py +++ b/pythonFiles/shell_exec.py @@ -1,9 +1,8 @@ # Copyright (c) Microsoft Corporation. All rights reserved. # Licensed under the MIT License. -import os -import sys import subprocess +import sys # This is a simple solution to waiting for completion of commands sent to terminal. # 1. Intercept commands send to a terminal diff --git a/pythonFiles/unittestadapter/utils.py b/pythonFiles/unittestadapter/utils.py index 78000e2a945f..64f08217f38f 100644 --- a/pythonFiles/unittestadapter/utils.py +++ b/pythonFiles/unittestadapter/utils.py @@ -60,11 +60,11 @@ def get_source_line(obj) -> str: """Get the line number of a test case start line.""" try: sourcelines, lineno = inspect.getsourcelines(obj) - except: + except Exception: try: # tornado-specific, see https://github.com/microsoft/vscode-python/issues/17285. sourcelines, lineno = inspect.getsourcelines(obj.orig_method) - except: + except Exception: return "*" # Return the line number of the first line of the test case definition. @@ -226,7 +226,8 @@ def parse_unittest_args(args: List[str]) -> Tuple[str, str, Union[str, None]]: The returned tuple contains the following items - start_directory: The directory where to start discovery, defaults to . - pattern: The pattern to match test files, defaults to test*.py - - top_level_directory: The top-level directory of the project, defaults to None, and unittest will use start_directory behind the scenes. + - top_level_directory: The top-level directory of the project, defaults to None, + and unittest will use start_directory behind the scenes. """ arg_parser = argparse.ArgumentParser() From cf15203782f954c2dbcc33a6cc84dfd85093dffb Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 3 Aug 2023 15:28:51 -0700 Subject: [PATCH 13/25] remove unused imports --- pythonFiles/pyproject.toml | 4 +++- pythonFiles/tests/pytestadapter/helpers.py | 2 +- pythonFiles/tests/pytestadapter/test_execution.py | 5 +++-- pythonFiles/tests/test_create_microvenv.py | 1 - 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pythonFiles/pyproject.toml b/pythonFiles/pyproject.toml index 3e338683b9b8..8331e1fe3684 100644 --- a/pythonFiles/pyproject.toml +++ b/pythonFiles/pyproject.toml @@ -58,5 +58,7 @@ exclude = [ 'tests/testing_tools/adapter/test_util.py', 'tests/testing_tools/adapter/pytest/test_cli.py', 'tests/testing_tools/adapter/pytest/test_discovery.py', - 'pythonFiles/testing_tools/*' + 'pythonFiles/testing_tools/*', + 'pythonFiles/testing_tools/adapter/pytest/__init__.py', + 'pythonFiles/tests/pytestadapter/expected_execution_test_output.py:8:141', ] diff --git a/pythonFiles/tests/pytestadapter/helpers.py b/pythonFiles/tests/pytestadapter/helpers.py index 28feb6282b92..7195cfe43ea5 100644 --- a/pythonFiles/tests/pytestadapter/helpers.py +++ b/pythonFiles/tests/pytestadapter/helpers.py @@ -10,7 +10,7 @@ import sys import threading import uuid -from typing import Any, Dict, List, Optional, Tuple, Union +from typing import Any, Dict, List, Optional, Tuple TEST_DATA_PATH = pathlib.Path(__file__).parent / ".data" from typing_extensions import TypedDict diff --git a/pythonFiles/tests/pytestadapter/test_execution.py b/pythonFiles/tests/pytestadapter/test_execution.py index 2be4886c24c1..30f1a7e439d9 100644 --- a/pythonFiles/tests/pytestadapter/test_execution.py +++ b/pythonFiles/tests/pytestadapter/test_execution.py @@ -5,6 +5,7 @@ import shutil import pytest + from tests.pytestadapter import expected_execution_test_output from .helpers import TEST_DATA_PATH, runner, runner_with_cwd @@ -205,7 +206,7 @@ def test_pytest_execution(test_ids, expected_const): Keyword arguments: test_ids -- an array of test_ids to run. expected_const -- a dictionary of the expected output from running pytest discovery on the files. - """ + """ # noqa: E501 args = test_ids actual = runner(args) assert actual @@ -223,6 +224,6 @@ def test_pytest_execution(test_ids, expected_const): or actual_result_dict[key]["outcome"] == "error" ): actual_result_dict[key]["message"] = "ERROR MESSAGE" - if actual_result_dict[key]["traceback"] != None: + if actual_result_dict[key]["traceback"] is not None: actual_result_dict[key]["traceback"] = "TRACEBACK" assert actual_result_dict == expected_const diff --git a/pythonFiles/tests/test_create_microvenv.py b/pythonFiles/tests/test_create_microvenv.py index f123052c491c..6e8846e6bacf 100644 --- a/pythonFiles/tests/test_create_microvenv.py +++ b/pythonFiles/tests/test_create_microvenv.py @@ -6,7 +6,6 @@ import sys import create_microvenv -import pytest def test_create_microvenv(): From 2f92f7e31594638fccc034ce8870cd4687dd63c9 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 3 Aug 2023 16:20:26 -0700 Subject: [PATCH 14/25] fix true conditional to ruff compliant --- pythonFiles/testing_tools/adapter/pytest/__init__.py | 2 -- pythonFiles/tests/test_create_microvenv.py | 2 +- pythonFiles/tests/test_create_venv.py | 5 +++-- .../tests/unittestadapter/.data/discovery_error/file_one.py | 2 -- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/pythonFiles/testing_tools/adapter/pytest/__init__.py b/pythonFiles/testing_tools/adapter/pytest/__init__.py index e894f7bcdb8e..102898e8dacb 100644 --- a/pythonFiles/testing_tools/adapter/pytest/__init__.py +++ b/pythonFiles/testing_tools/adapter/pytest/__init__.py @@ -3,5 +3,3 @@ from __future__ import absolute_import -from ._cli import add_subparser as add_cli_subparser -from ._discovery import discover diff --git a/pythonFiles/tests/test_create_microvenv.py b/pythonFiles/tests/test_create_microvenv.py index 6e8846e6bacf..e5d4e68802e9 100644 --- a/pythonFiles/tests/test_create_microvenv.py +++ b/pythonFiles/tests/test_create_microvenv.py @@ -25,4 +25,4 @@ def run_process(args, error_message): create_microvenv.run_process = run_process create_microvenv.main() - assert run_process_called == True + assert run_process_called is True diff --git a/pythonFiles/tests/test_create_venv.py b/pythonFiles/tests/test_create_venv.py index bebe304c13c3..ae3f18be6f3c 100644 --- a/pythonFiles/tests/test_create_venv.py +++ b/pythonFiles/tests/test_create_venv.py @@ -5,9 +5,10 @@ import os import sys -import create_venv import pytest +import create_venv + @pytest.mark.skipif( sys.platform == "win32", reason="Windows does not have micro venv fallback." @@ -35,7 +36,7 @@ def run_process(args, error_message): create_venv.main(["--name", ".test_venv"]) # run_process is called when the venv does not exist - assert run_process_called == True + assert run_process_called is True @pytest.mark.skipif( diff --git a/pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py b/pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py index 42f84f046760..c03163dab8de 100644 --- a/pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py +++ b/pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py @@ -3,8 +3,6 @@ import unittest -import something_else # type: ignore - class DiscoveryErrorOne(unittest.TestCase): """Test class for the test_error_discovery test. From c3579e2dded6013cc3264e47a4f29fb348f57e67 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 3 Aug 2023 16:38:43 -0700 Subject: [PATCH 15/25] bring back import used in testing --- pythonFiles/testing_tools/adapter/pytest/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pythonFiles/testing_tools/adapter/pytest/__init__.py b/pythonFiles/testing_tools/adapter/pytest/__init__.py index 102898e8dacb..89b7c066a459 100644 --- a/pythonFiles/testing_tools/adapter/pytest/__init__.py +++ b/pythonFiles/testing_tools/adapter/pytest/__init__.py @@ -3,3 +3,5 @@ from __future__ import absolute_import +from ._cli import add_subparser as add_cli_subparser # noqa: F401 +from ._discovery import discover # noqa: F401 From a9c48639bb8998ad1bedd41d822f61aa8e5be70d Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 3 Aug 2023 16:53:31 -0700 Subject: [PATCH 16/25] bring back import something_else --- .../tests/unittestadapter/.data/discovery_error/file_one.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py b/pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py index c03163dab8de..cffe435a6fa2 100644 --- a/pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py +++ b/pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py @@ -3,6 +3,8 @@ import unittest +import something_else + class DiscoveryErrorOne(unittest.TestCase): """Test class for the test_error_discovery test. From db6dda444de9d874381015ee7e863ca9e142a99a Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 3 Aug 2023 16:54:28 -0700 Subject: [PATCH 17/25] bring back import something_else --- .../tests/unittestadapter/.data/discovery_error/file_one.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py b/pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py index cffe435a6fa2..42f84f046760 100644 --- a/pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py +++ b/pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py @@ -3,7 +3,7 @@ import unittest -import something_else +import something_else # type: ignore class DiscoveryErrorOne(unittest.TestCase): From ab4d1fe5498db1109688372e860a505541aed045 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 4 Aug 2023 13:02:26 -0700 Subject: [PATCH 18/25] skip old test file and incorrect file name --- pythonFiles/pyproject.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pythonFiles/pyproject.toml b/pythonFiles/pyproject.toml index 8331e1fe3684..3b75f715fdae 100644 --- a/pythonFiles/pyproject.toml +++ b/pythonFiles/pyproject.toml @@ -60,5 +60,8 @@ exclude = [ 'tests/testing_tools/adapter/pytest/test_discovery.py', 'pythonFiles/testing_tools/*', 'pythonFiles/testing_tools/adapter/pytest/__init__.py', - 'pythonFiles/tests/pytestadapter/expected_execution_test_output.py:8:141', + 'pythonFiles/tests/pytestadapter/expected_execution_test_output.py', + 'pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py', + 'pythonFiles/tests/unittestadapter/test_utils.py, + ] From 5bac89555cc91eda82c5c0e76d38874c3752cd31 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 4 Aug 2023 13:08:43 -0700 Subject: [PATCH 19/25] fix typo on .toml file --- pythonFiles/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonFiles/pyproject.toml b/pythonFiles/pyproject.toml index 3b75f715fdae..d865e27418e0 100644 --- a/pythonFiles/pyproject.toml +++ b/pythonFiles/pyproject.toml @@ -62,6 +62,6 @@ exclude = [ 'pythonFiles/testing_tools/adapter/pytest/__init__.py', 'pythonFiles/tests/pytestadapter/expected_execution_test_output.py', 'pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py', - 'pythonFiles/tests/unittestadapter/test_utils.py, + 'pythonFiles/tests/unittestadapter/test_utils.py', ] From 5c129d73e63b2616092ad89cfe818bb438cec5f1 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 4 Aug 2023 13:15:35 -0700 Subject: [PATCH 20/25] format comment and respect ruff confused imports --- .../tests/pytestadapter/expected_execution_test_output.py | 2 +- .../tests/unittestadapter/.data/discovery_error/file_one.py | 2 +- pythonFiles/tests/unittestadapter/test_utils.py | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pythonFiles/tests/pytestadapter/expected_execution_test_output.py b/pythonFiles/tests/pytestadapter/expected_execution_test_output.py index 0a7e737dfc0e..2dddd172127c 100644 --- a/pythonFiles/tests/pytestadapter/expected_execution_test_output.py +++ b/pythonFiles/tests/pytestadapter/expected_execution_test_output.py @@ -5,7 +5,7 @@ TEST_ADD_FUNCTION = "unittest_folder/test_add.py::TestAddFunction::" SUCCESS = "success" FAILURE = "failure" -TEST_SUBTRACT_FUNCTION_NEGATIVE_NUMBERS_ERROR = "self = \n\n def test_subtract_negative_numbers( # test_marker--test_subtract_negative_numbers\n self,\n ):\n result = subtract(-2, -3)\n> self.assertEqual(result, 100000)\nE AssertionError: 1 != 100000\n\nunittest_folder/test_subtract.py:25: AssertionError" +TEST_SUBTRACT_FUNCTION_NEGATIVE_NUMBERS_ERROR = "self = \n\n def test_subtract_negative_numbers( # test_marker--test_subtract_negative_numbers\n self,\n ):\n result = subtract(-2, -3)\n> self.assertEqual(result, 100000)\nE AssertionError: 1 != 100000\n\nunittest_folder/test_subtract.py:25: AssertionError" # noqa: E501 from .helpers import TEST_DATA_PATH, get_absolute_test_id # This is the expected output for the unittest_folder execute tests diff --git a/pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py b/pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py index 42f84f046760..031b6f6c9d68 100644 --- a/pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py +++ b/pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py @@ -3,7 +3,7 @@ import unittest -import something_else # type: ignore +import something_else # type: ignore # noqa: F401 class DiscoveryErrorOne(unittest.TestCase): diff --git a/pythonFiles/tests/unittestadapter/test_utils.py b/pythonFiles/tests/unittestadapter/test_utils.py index a3bc1dd7693c..e262f877d52c 100644 --- a/pythonFiles/tests/unittestadapter/test_utils.py +++ b/pythonFiles/tests/unittestadapter/test_utils.py @@ -6,6 +6,7 @@ import unittest import pytest + from unittestadapter.utils import ( TestNode, TestNodeTypeEnum, @@ -284,7 +285,8 @@ def test_build_decorated_tree() -> None: def test_build_empty_tree() -> None: - """The build_test_tree function should return None if there are no discovered test suites, and an empty list of errors if there are none in the discovered data.""" + """The build_test_tree function should return None if there are no discovered test suites, + and an empty list of errors if there are none in the discovered data.""" start_dir = os.fsdecode(TEST_DATA_PATH) pattern = "does_not_exist*" From 8cd26e02cc0a16ba59b5093a5da964feb2ce41b3 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 4 Aug 2023 13:35:15 -0700 Subject: [PATCH 21/25] remove unused imports expected_execution_test_out --- .../tests/pytestadapter/expected_execution_test_output.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pythonFiles/tests/pytestadapter/expected_execution_test_output.py b/pythonFiles/tests/pytestadapter/expected_execution_test_output.py index d0f3924fe1b9..dd8f458d792e 100644 --- a/pythonFiles/tests/pytestadapter/expected_execution_test_output.py +++ b/pythonFiles/tests/pytestadapter/expected_execution_test_output.py @@ -7,7 +7,7 @@ FAILURE = "failure" TEST_SUBTRACT_FUNCTION_NEGATIVE_NUMBERS_ERROR = "self = \n\n def test_subtract_negative_numbers( # test_marker--test_subtract_negative_numbers\n self,\n ):\n result = subtract(-2, -3)\n> self.assertEqual(result, 100000)\nE AssertionError: 1 != 100000\n\nunittest_folder/test_subtract.py:25: AssertionError" # noqa: E501 -from .helpers import TEST_DATA_PATH, get_absolute_test_id + # This is the expected output for the unittest_folder execute tests # └── unittest_folder From cf0d542eca3923648749a6e099040c4eb6f053d0 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 4 Aug 2023 13:41:18 -0700 Subject: [PATCH 22/25] fix warning execution.py --- pythonFiles/unittestadapter/execution.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pythonFiles/unittestadapter/execution.py b/pythonFiles/unittestadapter/execution.py index dfb6928a2074..f239f81c2d87 100644 --- a/pythonFiles/unittestadapter/execution.py +++ b/pythonFiles/unittestadapter/execution.py @@ -17,8 +17,9 @@ sys.path.append(os.fspath(script_dir)) sys.path.insert(0, os.fspath(script_dir / "lib" / "python")) -from testing_tools import process_json_util, socket_manager from typing_extensions import NotRequired, TypeAlias, TypedDict + +from testing_tools import process_json_util, socket_manager from unittestadapter.utils import parse_unittest_args DEFAULT_PORT = "45454" @@ -194,12 +195,12 @@ def run_tests( # Discover tests at path with the file name as a pattern (if any). loader = unittest.TestLoader() - args = { + args = { # noqa: F841 "start_dir": start_dir, "pattern": pattern, "top_level_dir": top_level_dir, } - suite = loader.discover(start_dir, pattern, top_level_dir) + suite = loader.discover(start_dir, pattern, top_level_dir) # noqa: F841 # Run tests. runner = unittest.TextTestRunner(resultclass=UnittestTestResult) From 85ea52f949f8c7bf69f570168cafa81c5f6abd57 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 4 Aug 2023 13:46:29 -0700 Subject: [PATCH 23/25] fix warning logParser.py --- .../vscode_datascience_helpers/tests/logParser.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/pythonFiles/vscode_datascience_helpers/tests/logParser.py b/pythonFiles/vscode_datascience_helpers/tests/logParser.py index 767f837c5136..e021853fee7a 100644 --- a/pythonFiles/vscode_datascience_helpers/tests/logParser.py +++ b/pythonFiles/vscode_datascience_helpers/tests/logParser.py @@ -1,11 +1,10 @@ -from io import TextIOWrapper -import sys import argparse import os +from io import TextIOWrapper os.system("color") -from pathlib import Path import re +from pathlib import Path parser = argparse.ArgumentParser(description="Parse a test log into its parts") parser.add_argument("testlog", type=str, nargs=1, help="Log to parse") @@ -63,14 +62,14 @@ def splitByPid(testlog): pid = int(match.group(1)) # See if we've created a log for this pid or not - if not pid in pids: + if pid not in pids: pids.add(pid) logFile = "{}_{}.log".format(baseFile, pid) print("Writing to new log: " + logFile) logs[pid] = Path(logFile).open(mode="w") # Add this line to the log - if pid != None: + if pid is not None: logs[pid].write(line) # Close all of the open logs for key in logs: From 46a291170799b096941672023dabe204b79c1c5e Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 4 Aug 2023 13:58:31 -0700 Subject: [PATCH 24/25] switch from github action to pip install --- .github/actions/lint/action.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/actions/lint/action.yml b/.github/actions/lint/action.yml index 19e702f03777..a59618224a05 100644 --- a/.github/actions/lint/action.yml +++ b/.github/actions/lint/action.yml @@ -49,6 +49,8 @@ runs: shell: bash - name: Run Ruff - uses: chartboost/ruff-action@v1 - with: - src: './pythonFiles' + run: | + python -m pip install -U ruff + python -m ruff . --check + working-directory: pythonFiles + shell: bash From a7c6d511a964d5734a00d8734c29ffa5c98d5b1c Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 4 Aug 2023 14:02:41 -0700 Subject: [PATCH 25/25] follow ruff doc to run --- .github/actions/lint/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/lint/action.yml b/.github/actions/lint/action.yml index a59618224a05..1efa6aab79a5 100644 --- a/.github/actions/lint/action.yml +++ b/.github/actions/lint/action.yml @@ -51,6 +51,6 @@ runs: - name: Run Ruff run: | python -m pip install -U ruff - python -m ruff . --check + python -m ruff check . working-directory: pythonFiles shell: bash