Skip to content

Commit

Permalink
Merge branch 'main' into right-rattlesnake
Browse files Browse the repository at this point in the history
  • Loading branch information
eleanorjboyd authored Oct 4, 2024
2 parents 0b37929 + 6bd34bf commit 787ccc5
Show file tree
Hide file tree
Showing 35 changed files with 241 additions and 422 deletions.
8 changes: 6 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
"mocha": true
},
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"plugins": [
"@typescript-eslint",
"no-only-tests"
],
"extends": [
"airbnb",
"plugin:@typescript-eslint/recommended",
Expand Down Expand Up @@ -97,6 +100,7 @@
}
],
"operator-assignment": "off",
"strict": "off"
"strict": "off",
"no-only-tests/no-only-tests": ["error", { "block": ["test", "suite"], "focus": ["only"] }]
}
}
2 changes: 1 addition & 1 deletion build/azure-pipeline.pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ extends:
buildType: 'specific'
project: 'Monaco'
definition: 591
buildVersionToDownload: 'latestFromBranch'
buildVersionToDownload: 'latest'
branchName: 'refs/heads/main'
targetPath: '$(Build.SourcesDirectory)/python-env-tools/bin'
artifactName: 'bin-$(vsceTarget)'
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@
"browser": "./dist/extension.browser.js",
"l10n": "./l10n",
"contributes": {
"problemMatchers":
[
"problemMatchers": [
{
"name": "python",
"owner": "python",
Expand All @@ -98,7 +97,6 @@
},
{
"regexp": "^\\s*(.*)\\s*$"

},
{
"regexp": "^\\s*(.*Error.*)$",
Expand Down Expand Up @@ -682,6 +680,12 @@
"experimental"
]
},
"python.REPL.provideVariables": {
"default": true,
"description": "%python.REPL.provideVariables.description%",
"scope": "resource",
"type": "boolean"
},
"python.testing.autoTestDiscoverOnSaveEnabled": {
"default": true,
"description": "%python.testing.autoTestDiscoverOnSaveEnabled.description%",
Expand Down Expand Up @@ -1640,6 +1644,7 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsx-a11y": "^6.3.1",
"eslint-plugin-no-only-tests": "^3.3.0",
"eslint-plugin-react": "^7.20.3",
"eslint-plugin-react-hooks": "^4.0.0",
"expose-loader": "^3.1.0",
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"python.pixiToolPath.description": "Path to the pixi executable.",
"python.EnableREPLSmartSend.description": "Toggle Smart Send for the Python REPL. Smart Send enables sending the smallest runnable block of code to the REPL on Shift+Enter and moves the cursor accordingly.",
"python.REPL.sendToNativeREPL.description": "Toggle to send code to Python REPL instead of the terminal on execution. Turning this on will change the behavior for both Smart Send and Run Selection/Line in the Context Menu.",
"python.REPL.provideVariables.description": "Toggle to provide variables for the REPL variable view for the native REPL.",
"python.tensorBoard.logDirectory.description": "Set this setting to your preferred TensorBoard log directory to skip log directory prompt when starting TensorBoard.",
"python.tensorBoard.logDirectory.markdownDeprecationMessage": "Tensorboard support has been moved to the extension [Tensorboard extension](https://marketplace.visualstudio.com/items?itemName=ms-toolsai.tensorboard). Instead use the setting `tensorBoard.logDirectory`.",
"python.tensorBoard.logDirectory.deprecationMessage": "Tensorboard support has been moved to the extension Tensorboard extension. Instead use the setting `tensorBoard.logDirectory`.",
Expand Down
7 changes: 1 addition & 6 deletions python_files/tests/pytestadapter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def process_data_received(data: str) -> List[Dict[str, Any]]:
This function also:
- Checks that the jsonrpc value is 2.0
- Checks that the last JSON message contains the `eot` token.
"""
json_messages = []
remaining = data
Expand All @@ -85,18 +84,14 @@ def process_data_received(data: str) -> List[Dict[str, Any]]:
else:
json_messages.append(json_data["params"])

last_json = json_messages.pop(-1)
if "eot" not in last_json:
raise ValueError("Last JSON messages does not contain 'eot' as its last payload.")
return json_messages # return the list of json messages, only the params part without the EOT token
return json_messages # return the list of json messages


def parse_rpc_message(data: str) -> Tuple[Dict[str, str], str]:
"""Process the JSON data which comes from the server.
A single rpc payload is in the format:
content-length: #LEN# \r\ncontent-type: application/json\r\n\r\n{"jsonrpc": "2.0", "params": ENTIRE_DATA}
with EOT params: "params": {"command_type": "discovery", "eot": true}
returns:
json_data: A single rpc payload of JSON data from the server.
Expand Down
46 changes: 46 additions & 0 deletions python_files/tests/pytestadapter/test_coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import pathlib
import sys

import pytest

script_dir = pathlib.Path(__file__).parent.parent
sys.path.append(os.fspath(script_dir))

Expand Down Expand Up @@ -42,3 +44,47 @@ def test_simple_pytest_coverage():
assert focal_function_coverage.get("lines_missed") is not None
assert set(focal_function_coverage.get("lines_covered")) == {4, 5, 7, 9, 10, 11, 12, 13, 14, 17}
assert set(focal_function_coverage.get("lines_missed")) == {18, 19, 6}


coverage_file_path = TEST_DATA_PATH / "coverage_gen" / "coverage.json"


@pytest.fixture
def cleanup_coverage_file():
# delete the coverage file if it exists as part of test cleanup
yield
if os.path.exists(coverage_file_path): # noqa: PTH110
os.remove(coverage_file_path) # noqa: PTH107


def test_coverage_gen_report(cleanup_coverage_file): # noqa: ARG001
"""
Test coverage payload is correct for simple pytest example. Output of coverage run is below.
Name Stmts Miss Branch BrPart Cover
---------------------------------------------------
__init__.py 0 0 0 0 100%
reverse.py 13 3 8 2 76%
test_reverse.py 11 0 0 0 100%
---------------------------------------------------
TOTAL 24 3 8 2 84%
"""
args = ["--cov-report=json"]
env_add = {"COVERAGE_ENABLED": "True"}
cov_folder_path = TEST_DATA_PATH / "coverage_gen"
actual = runner_with_cwd_env(args, cov_folder_path, env_add)
assert actual
coverage = actual[-1]
assert coverage
results = coverage["result"]
assert results
assert len(results) == 3
focal_function_coverage = results.get(os.fspath(TEST_DATA_PATH / "coverage_gen" / "reverse.py"))
assert focal_function_coverage
assert focal_function_coverage.get("lines_covered") is not None
assert focal_function_coverage.get("lines_missed") is not None
assert set(focal_function_coverage.get("lines_covered")) == {4, 5, 7, 9, 10, 11, 12, 13, 14, 17}
assert set(focal_function_coverage.get("lines_missed")) == {18, 19, 6}
# assert that the coverage file was created at the right path
assert os.path.exists(coverage_file_path) # noqa: PTH110
5 changes: 0 additions & 5 deletions python_files/unittestadapter/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# If I use from utils then there will be an import error in test_discovery.py.
from unittestadapter.pvsc_utils import ( # noqa: E402
DiscoveryPayloadDict,
EOTPayloadDict,
VSCodeUnittestError,
build_test_tree,
parse_unittest_args,
Expand Down Expand Up @@ -129,7 +128,6 @@ def discover_tests(
# collect args for Django discovery runner.
args = argv[index + 1 :] or []
django_discovery_runner(manage_py_path, args)
# eot payload sent within Django runner.
except Exception as e:
error_msg = f"Error configuring Django test runner: {e}"
print(error_msg, file=sys.stderr)
Expand All @@ -139,6 +137,3 @@ def discover_tests(
payload = discover_tests(start_dir, pattern, top_level_dir)
# Post this discovery payload.
send_post_request(payload, test_run_pipe)
# Post EOT token.
eot_payload: EOTPayloadDict = {"command_type": "discovery", "eot": True}
send_post_request(eot_payload, test_run_pipe)
4 changes: 0 additions & 4 deletions python_files/unittestadapter/django_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from execution import UnittestTestResult # noqa: E402
from pvsc_utils import ( # noqa: E402
DiscoveryPayloadDict,
EOTPayloadDict,
VSCodeUnittestError,
build_test_tree,
send_post_request,
Expand Down Expand Up @@ -64,9 +63,6 @@ def run_tests(self, test_labels, **kwargs):

# Send discovery payload.
send_post_request(payload, test_run_pipe)
# Send EOT token.
eot_payload: EOTPayloadDict = {"command_type": "discovery", "eot": True}
send_post_request(eot_payload, test_run_pipe)
return 0 # Skip actual test execution, return 0 as no tests were run.
except Exception as e:
error_msg = (
Expand Down
26 changes: 1 addition & 25 deletions python_files/unittestadapter/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

from unittestadapter.pvsc_utils import ( # noqa: E402
CoveragePayloadDict,
EOTPayloadDict,
ExecutionPayloadDict,
FileCoverageInfo,
TestExecutionStatus,
Expand Down Expand Up @@ -60,21 +59,6 @@ def startTest(self, test: unittest.TestCase): # noqa: N802

def stopTestRun(self): # noqa: N802
super().stopTestRun()
# After stopping the test run, send EOT
test_run_pipe = os.getenv("TEST_RUN_PIPE")
if os.getenv("MANAGE_PY_PATH"):
# only send this if it is a Django run
if not test_run_pipe:
print(
"UNITTEST ERROR: TEST_RUN_PIPE is not set at the time of unittest trying to send data. "
f"TEST_RUN_PIPE = {test_run_pipe}\n",
file=sys.stderr,
)
raise VSCodeUnittestError(
"UNITTEST ERROR: TEST_RUN_PIPE is not set at the time of unittest trying to send data. "
)
eot_payload: EOTPayloadDict = {"command_type": "execution", "eot": True}
send_post_request(eot_payload, test_run_pipe)

def addError( # noqa: N802
self,
Expand Down Expand Up @@ -269,15 +253,8 @@ def run_tests(
return payload


def execute_eot_and_cleanup():
eot_payload: EOTPayloadDict = {"command_type": "execution", "eot": True}
send_post_request(eot_payload, test_run_pipe)
if __socket:
__socket.close()


__socket = None
atexit.register(execute_eot_and_cleanup)
atexit.register(lambda: __socket.close() if __socket else None)


def send_run_data(raw_data, test_run_pipe):
Expand Down Expand Up @@ -361,7 +338,6 @@ def send_run_data(raw_data, test_run_pipe):
print("MANAGE_PY_PATH env var set, running Django test suite.")
args = argv[index + 1 :] or []
django_execution_runner(manage_py_path, test_ids, args)
# the django run subprocesses sends the eot payload.
else:
# Perform regular unittest execution.
payload = run_tests(
Expand Down
9 changes: 1 addition & 8 deletions python_files/unittestadapter/pvsc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,6 @@ class ExecutionPayloadDict(TypedDict):
error: NotRequired[str]


class EOTPayloadDict(TypedDict):
"""A dictionary that is used to send a end of transmission post request to the server."""

command_type: Literal["discovery", "execution"]
eot: bool


class FileCoverageInfo(TypedDict):
lines_covered: List[int]
lines_missed: List[int]
Expand Down Expand Up @@ -314,7 +307,7 @@ def parse_unittest_args(


def send_post_request(
payload: Union[ExecutionPayloadDict, DiscoveryPayloadDict, EOTPayloadDict, CoveragePayloadDict],
payload: Union[ExecutionPayloadDict, DiscoveryPayloadDict, CoveragePayloadDict],
test_run_pipe: Optional[str],
):
"""
Expand Down
13 changes: 1 addition & 12 deletions python_files/vscode_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,6 @@ def pytest_sessionfinish(session, exitstatus):
)
send_post_request(payload)

command_type = "discovery" if IS_DISCOVERY else "execution"
payload_eot: EOTPayloadDict = {"command_type": command_type, "eot": True}
send_post_request(payload_eot)


def build_test_tree(session: pytest.Session) -> TestNode:
"""Builds a tree made up of testing nodes from the pytest session.
Expand Down Expand Up @@ -782,13 +778,6 @@ class CoveragePayloadDict(Dict):
error: str | None # Currently unused need to check


class EOTPayloadDict(TypedDict):
"""A dictionary that is used to send a end of transmission post request to the server."""

command_type: Literal["discovery", "execution"]
eot: bool


def get_node_path(node: Any) -> pathlib.Path:
"""A function that returns the path of a node given the switch to pathlib.Path.
Expand Down Expand Up @@ -873,7 +862,7 @@ def default(self, o):


def send_post_request(
payload: ExecutionPayloadDict | DiscoveryPayloadDict | EOTPayloadDict | CoveragePayloadDict,
payload: ExecutionPayloadDict | DiscoveryPayloadDict | CoveragePayloadDict,
cls_encoder=None,
):
"""
Expand Down
4 changes: 3 additions & 1 deletion python_files/vscode_pytest/run_pytest_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def run_pytest(args):
if is_coverage_run == "True":
# If coverage is enabled, check if the coverage plugin is already in the args, if so keep user args.
for arg in args:
if "--cov" in arg:
# if '--cov' is an arg or if '--cov=' is in an arg (check to see if this arg is set to not override user intent)
if arg == "--cov" or "--cov=" in arg:
print("coverage already enabled with specific args")
coverage_enabled = True
break
if not coverage_enabled:
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ packaging==24.1 \
--hash=sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002 \
--hash=sha256:5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124
# via -r requirements.in
tomli==2.0.1 \
--hash=sha256:939de3e7a6161af0c887ef91b7d41a53e7c5a1ca976325f429cb46ea9bc30ecc \
--hash=sha256:de526c12914f0c550d15924c62d72abc48d6fe7364aa87328337a31007fe8a4f
tomli==2.0.2 \
--hash=sha256:2ebe24485c53d303f690b0ec092806a085f07af5a5aa1464f3931eec36caaa38 \
--hash=sha256:d46d457a85337051c36524bc5349dd91b1877838e2979ac5ced3e710ed8a60ed
# via -r requirements.in
typing-extensions==4.12.2 \
--hash=sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d \
Expand Down
7 changes: 6 additions & 1 deletion src/client/common/application/commands/reportIssueCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ export class ReportIssueCommandHandler implements IExtensionSingleActivationServ

const installedExtensions = getExtensions()
.filter((extension) => !extension.id.startsWith('vscode.'))
.sort((a, b) => a.packageJSON.displayName.localeCompare(b.packageJSON.displayName))
.sort((a, b) => {
if (a.packageJSON.displayName && b.packageJSON.displayName) {
return a.packageJSON.displayName.localeCompare(b.packageJSON.displayName);
}
return a.id.localeCompare(b.id);
})
.map(
(extension) =>
`|${extension.packageJSON.displayName}|${extension.id}|${extension.packageJSON.version}|`,
Expand Down
2 changes: 1 addition & 1 deletion src/client/common/terminal/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export class TerminalService implements ITerminalService, Disposable {
resolve(true);
},
);
const TIMEOUT_DURATION = 3000;
const TIMEOUT_DURATION = 500;
setTimeout(() => {
this.executeCommandListeners.add(shellIntegrationChangeEventListener);
resolve(true);
Expand Down
Loading

0 comments on commit 787ccc5

Please sign in to comment.