Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support EOT for testing #21876

Merged
merged 56 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
87d299a
add path parser
eleanorjboyd Aug 15, 2023
5566ad3
remove other parser
eleanorjboyd Aug 15, 2023
f2a4bd1
switching to at least to reduce flakiness
eleanorjboyd Aug 15, 2023
cf814ac
add in then not finally
eleanorjboyd Aug 15, 2023
0838717
change to keep socket open
eleanorjboyd Aug 16, 2023
78819b8
switch to 200
eleanorjboyd Aug 16, 2023
7e25d50
remove old line
eleanorjboyd Aug 16, 2023
d07bda5
reformat + pyright + change to 20
eleanorjboyd Aug 16, 2023
0986aa6
linting
eleanorjboyd Aug 16, 2023
87f3036
change to assert
eleanorjboyd Aug 16, 2023
19a4e06
switch to mock output channel
eleanorjboyd Aug 23, 2023
f4e1b55
extra log
eleanorjboyd Aug 23, 2023
f115025
add in tests
eleanorjboyd Aug 23, 2023
4df1d11
add timeout
eleanorjboyd Aug 23, 2023
3638b95
implement retries
eleanorjboyd Aug 23, 2023
03c3781
import time
eleanorjboyd Aug 23, 2023
3207dc7
try on ts side
eleanorjboyd Aug 23, 2023
fb589f6
add logging typescript side
eleanorjboyd Aug 24, 2023
499ecbc
log on run data recieved
eleanorjboyd Aug 24, 2023
b4f9204
multi payload per chunk support
eleanorjboyd Aug 24, 2023
87c0ef1
from stash
eleanorjboyd Aug 27, 2023
b98bf18
add doc string, fix pyright
eleanorjboyd Aug 28, 2023
e7fd57f
revert incorrectly staged changes
eleanorjboyd Aug 28, 2023
60e46a2
pytest discovery
eleanorjboyd Aug 28, 2023
0e6ddf4
tests passing for pytest execution
eleanorjboyd Aug 28, 2023
53f4306
unittest functioning- all test.ts
eleanorjboyd Aug 28, 2023
5594566
remove result resolver mock
eleanorjboyd Aug 28, 2023
22dc781
fix imports
eleanorjboyd Aug 28, 2023
397f3c5
add sep function for server data process
eleanorjboyd Aug 29, 2023
0a45e5b
most tests working, need to fix the buffer
eleanorjboyd Sep 7, 2023
505740b
4 tests working
eleanorjboyd Sep 7, 2023
3a0c585
revert files which shouldn't be touched
eleanorjboyd Sep 12, 2023
5be4238
fix test_discovery typing
eleanorjboyd Sep 12, 2023
95348ae
pyright
eleanorjboyd Sep 12, 2023
cd1a4c8
pyright p2
eleanorjboyd Sep 12, 2023
3c3f339
pytestExecutionAdapter tests
eleanorjboyd Sep 13, 2023
c8d80fe
fix server tests
eleanorjboyd Sep 13, 2023
10bd3e3
fix linting
eleanorjboyd Sep 13, 2023
8ac9df1
null uuid error handling
eleanorjboyd Sep 13, 2023
00a8fd6
seg fault tests working
eleanorjboyd Sep 13, 2023
2eee564
logging fixing
eleanorjboyd Sep 13, 2023
b064d37
add cancellation token tests
eleanorjboyd Sep 13, 2023
3512173
fix linting
eleanorjboyd Sep 14, 2023
c1079a1
cancellation for debug
eleanorjboyd Sep 14, 2023
aeabdc3
formatting
eleanorjboyd Sep 14, 2023
0c51954
fix seg_fault up test count
eleanorjboyd Sep 14, 2023
9712c09
types
eleanorjboyd Sep 14, 2023
855d23c
tests
eleanorjboyd Sep 14, 2023
5481fa5
another
eleanorjboyd Sep 14, 2023
a4e559c
add additional info logging
eleanorjboyd Sep 15, 2023
5b48927
fix seg fault on diff machines
eleanorjboyd Sep 15, 2023
8913256
Merge branch 'main' into at-eot
eleanorjboyd Sep 15, 2023
2dd5d05
fix testid
eleanorjboyd Sep 15, 2023
e290587
delete unused import
eleanorjboyd Sep 15, 2023
f0d0860
fix name testid
eleanorjboyd Sep 15, 2023
8e72673
fix search
eleanorjboyd Sep 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion pythonFiles/testing_tools/socket_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ def __init__(self, addr):
self.socket = None

def __enter__(self):
return self.connect()

def __exit__(self, *_):
self.close()

def connect(self):
self.socket = socket.socket(
socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP
)
Expand All @@ -35,7 +41,7 @@ def __enter__(self):

return self

def __exit__(self, *_):
def close(self):
if self.socket:
try:
self.socket.shutdown(socket.SHUT_RDWR)
Expand Down
4 changes: 4 additions & 0 deletions pythonFiles/tests/pytestadapter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
import uuid
from typing import Any, Dict, List, Optional, Tuple

script_dir = pathlib.Path(__file__).parent.parent.parent
sys.path.append(os.fspath(script_dir))
sys.path.append(os.fspath(script_dir / "lib" / "python"))

TEST_DATA_PATH = pathlib.Path(__file__).parent / ".data"
from typing_extensions import TypedDict

Expand Down
129 changes: 86 additions & 43 deletions pythonFiles/tests/pytestadapter/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,26 @@ def test_import_error(tmp_path):
temp_dir.mkdir()
p = temp_dir / "error_pytest_import.py"
shutil.copyfile(file_path, p)
actual_list: Optional[List[Dict[str, Any]]] = runner(
["--collect-only", os.fspath(p)]
)
assert actual_list
for actual in actual_list:
assert all(item in actual for item in ("status", "cwd", "error"))
assert actual["status"] == "error"
assert actual["cwd"] == os.fspath(TEST_DATA_PATH)
assert len(actual["error"]) == 2
actual: Optional[List[Dict[str, Any]]] = 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 actual_item.get("status") == "error"
assert actual_item.get("cwd") == os.fspath(TEST_DATA_PATH)

# Ensure that 'error' is a list and then check its length
error_content = actual_item.get("error")
if error_content is not None and isinstance(
error_content, (list, tuple, str)
): # You can add other types if needed
assert len(error_content) == 2
else:
assert False


def test_syntax_error(tmp_path):
Expand All @@ -60,13 +71,25 @@ def test_syntax_error(tmp_path):
p = temp_dir / "error_syntax_discovery.py"
shutil.copyfile(file_path, p)
actual = runner(["--collect-only", os.fspath(p)])
if actual:
actual = actual[0]
assert actual
assert all(item in actual for item in ("status", "cwd", "error"))
assert actual["status"] == "error"
assert actual["cwd"] == os.fspath(TEST_DATA_PATH)
assert len(actual["error"]) == 2
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 actual_item.get("status") == "error"
assert actual_item.get("cwd") == os.fspath(TEST_DATA_PATH)

# Ensure that 'error' is a list and then check its length
error_content = actual_item.get("error")
if error_content is not None and isinstance(
error_content, (list, tuple, str)
): # You can add other types if needed
assert len(error_content) == 2
else:
assert False


def test_parameterized_error_collect():
Expand All @@ -76,12 +99,25 @@ def test_parameterized_error_collect():
"""
file_path_str = "error_parametrize_discovery.py"
actual = runner(["--collect-only", file_path_str])
if actual:
actual = actual[0]
assert all(item in actual for item in ("status", "cwd", "error"))
assert actual["status"] == "error"
assert actual["cwd"] == os.fspath(TEST_DATA_PATH)
assert len(actual["error"]) == 2
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 actual_item.get("status") == "error"
assert actual_item.get("cwd") == os.fspath(TEST_DATA_PATH)

# Ensure that 'error' is a list and then check its length
error_content = actual_item.get("error")
if error_content is not None and isinstance(
error_content, (list, tuple, str)
): # You can add other types if needed
assert len(error_content) == 2
else:
assert False


@pytest.mark.parametrize(
Expand Down Expand Up @@ -146,13 +182,16 @@ def test_pytest_collect(file, expected_const):
os.fspath(TEST_DATA_PATH / file),
]
)
if actual:
actual = actual[0]
assert actual
assert all(item in actual for item in ("status", "cwd", "tests"))
assert actual["status"] == "success"
assert actual["cwd"] == os.fspath(TEST_DATA_PATH)
assert actual["tests"] == expected_const

assert actual
actual_list: List[Dict[str, Any]] = actual
if actual_list is not None:
assert actual_list.pop(-1).get("eot")
actual_item = actual_list.pop(0)
assert all(item in actual_item.keys() for item in ("status", "cwd", "error"))
assert actual_item.get("status") == "success"
assert actual_item.get("cwd") == os.fspath(TEST_DATA_PATH)
assert actual_item.get("tests") == expected_const


def test_pytest_root_dir():
Expand All @@ -168,14 +207,16 @@ def test_pytest_root_dir():
],
TEST_DATA_PATH / "root",
)
if actual:
actual = actual[0]
assert actual
assert all(item in actual for item in ("status", "cwd", "tests"))
assert actual["status"] == "success"
assert actual["cwd"] == os.fspath(TEST_DATA_PATH / "root")
assert actual
actual_list: List[Dict[str, Any]] = actual
if actual_list is not None:
assert actual_list.pop(-1).get("eot")
actual_item = actual_list.pop(0)
assert all(item in actual_item.keys() for item in ("status", "cwd", "error"))
assert actual_item.get("status") == "success"
assert actual_item.get("cwd") == os.fspath(TEST_DATA_PATH / "root")
assert (
actual["tests"]
actual_item.get("tests")
== expected_discovery_test_output.root_with_config_expected_output
)

Expand All @@ -193,13 +234,15 @@ def test_pytest_config_file():
],
TEST_DATA_PATH / "root",
)
if actual:
actual = actual[0]
assert actual
assert all(item in actual for item in ("status", "cwd", "tests"))
assert actual["status"] == "success"
assert actual["cwd"] == os.fspath(TEST_DATA_PATH / "root")
assert actual
actual_list: List[Dict[str, Any]] = actual
if actual_list is not None:
assert actual_list.pop(-1).get("eot")
actual_item = actual_list.pop(0)
assert all(item in actual_item.keys() for item in ("status", "cwd", "error"))
assert actual_item.get("status") == "success"
assert actual_item.get("cwd") == os.fspath(TEST_DATA_PATH / "root")
assert (
actual["tests"]
actual_item.get("tests")
== expected_discovery_test_output.root_with_config_expected_output
)
110 changes: 73 additions & 37 deletions pythonFiles/tests/pytestadapter/test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Licensed under the MIT License.
import os
import shutil
from typing import Any, Dict, List

import pytest

Expand All @@ -23,14 +24,19 @@ def test_config_file():
expected_execution_test_output.config_file_pytest_expected_execution_output
)
assert actual
assert len(actual) == len(expected_const)
actual_list: List[Dict[str, Any]] = actual
assert actual_list.pop(-1).get("eot")
assert len(actual_list) == len(expected_const)
actual_result_dict = dict()
for a in actual:
assert all(item in a for item in ("status", "cwd", "result"))
assert a["status"] == "success"
assert a["cwd"] == os.fspath(new_cwd)
actual_result_dict.update(a["result"])
assert actual_result_dict == expected_const
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 actual_item.get("status") == "success"
assert actual_item.get("cwd") == os.fspath(new_cwd)
actual_result_dict.update(actual_item["result"])
assert actual_result_dict == expected_const


def test_rootdir_specified():
Expand All @@ -43,14 +49,19 @@ def test_rootdir_specified():
expected_execution_test_output.config_file_pytest_expected_execution_output
)
assert actual
assert len(actual) == len(expected_const)
actual_list: List[Dict[str, Any]] = actual
assert actual_list.pop(-1).get("eot")
assert len(actual_list) == len(expected_const)
actual_result_dict = dict()
for a in actual:
assert all(item in a for item in ("status", "cwd", "result"))
assert a["status"] == "success"
assert a["cwd"] == os.fspath(new_cwd)
actual_result_dict.update(a["result"])
assert actual_result_dict == expected_const
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 actual_item.get("status") == "success"
assert actual_item.get("cwd") == os.fspath(new_cwd)
actual_result_dict.update(actual_item["result"])
assert actual_result_dict == expected_const


def test_syntax_error_execution(tmp_path):
Expand All @@ -73,13 +84,23 @@ def test_syntax_error_execution(tmp_path):
p = temp_dir / "error_syntax_discovery.py"
shutil.copyfile(file_path, p)
actual = runner(["error_syntax_discover.py::test_function"])
if actual:
actual = actual[0]
assert actual
assert all(item in actual for item in ("status", "cwd", "error"))
assert actual["status"] == "error"
assert actual["cwd"] == os.fspath(TEST_DATA_PATH)
assert len(actual["error"]) == 1
assert actual
actual_list: List[Dict[str, Any]] = actual
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 actual_item.get("status") == "error"
assert actual_item.get("cwd") == os.fspath(TEST_DATA_PATH)
error_content = actual_item.get("error")
if error_content is not None and isinstance(
error_content, (list, tuple, str)
): # You can add other types if needed
assert len(error_content) == 1
else:
assert False


def test_bad_id_error_execution():
Expand All @@ -88,13 +109,23 @@ def test_bad_id_error_execution():
The json should still be returned but the errors list should be present.
"""
actual = runner(["not/a/real::test_id"])
if actual:
actual = actual[0]
assert actual
assert all(item in actual for item in ("status", "cwd", "error"))
assert actual["status"] == "error"
assert actual["cwd"] == os.fspath(TEST_DATA_PATH)
assert len(actual["error"]) == 1
assert actual
actual_list: List[Dict[str, Any]] = actual
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 actual_item.get("status") == "error"
assert actual_item.get("cwd") == os.fspath(TEST_DATA_PATH)
error_content = actual_item.get("error")
if error_content is not None and isinstance(
error_content, (list, tuple, str)
): # You can add other types if needed
assert len(error_content) == 1
else:
assert False


@pytest.mark.parametrize(
Expand Down Expand Up @@ -195,7 +226,8 @@ def test_pytest_execution(test_ids, expected_const):
3. uf_single_method_execution_expected_output: test run on a single method in a file.
4. uf_non_adjacent_tests_execution_expected_output: test run on unittests in two files with single selection in test explorer.
5. unit_pytest_same_file_execution_expected_output: test run on a file with both unittest and pytest tests.
6. dual_level_nested_folder_execution_expected_output: test run on a file with one test file at the top level and one test file in a nested folder.
6. dual_level_nested_folder_execution_expected_output: test run on a file with one test file
at the top level and one test file in a nested folder.
7. double_nested_folder_expected_execution_output: test run on a double nested folder.
8. parametrize_tests_expected_execution_output: test run on a parametrize test with 3 inputs.
9. single_parametrize_tests_expected_execution_output: test run on single parametrize test.
Expand All @@ -205,18 +237,22 @@ 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
print(actual)
assert len(actual) == len(expected_const)
actual_list: List[Dict[str, Any]] = actual
assert actual_list.pop(-1).get("eot")
assert len(actual_list) == len(expected_const)
actual_result_dict = dict()
for a in actual:
assert all(item in a for item in ("status", "cwd", "result"))
assert a["status"] == "success"
assert a["cwd"] == os.fspath(TEST_DATA_PATH)
actual_result_dict.update(a["result"])
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 actual_item.get("status") == "success"
assert actual_item.get("cwd") == os.fspath(TEST_DATA_PATH)
actual_result_dict.update(actual_item["result"])
for key in actual_result_dict:
if (
actual_result_dict[key]["outcome"] == "failure"
Expand Down
Loading
Loading