forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Unittest discovery using the new test adapter #18253
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
Merged
kimadeline
merged 98 commits into
microsoft:main
from
kimadeline:17242-unittest-discovery
Apr 13, 2022
Merged
Changes from 94 commits
Commits
Show all changes
98 commits
Select commit
Hold shift + click to select a range
9eb43a5
Add json-rpc dependency
kimadeline 35a359e
Basic test discovery (no server yet)
kimadeline 4eac7cf
Remove json-rpc dependency
kimadeline 2adac64
Clean up test discovery script
kimadeline cb7ce85
Add default test results array value (py side)
kimadeline 5746990
Add localization
kimadeline 52785d6
Build tree on the Python side + move utils out
kimadeline 9e9a966
Fix comments
kimadeline 95b7f7c
Basic test discovery
kimadeline 05f8599
Fix case where no tests are discovered
kimadeline 0d027f6
Merge branch 'main' into 17242-unittest-discovery
kimadeline d367440
Merge branch 'main' into 17242-unittest-discovery
kimadeline 5876dde
Add test tree update support
kimadeline d1f7e1a
Localization
kimadeline a60b3df
Multiroot workspace support
kimadeline 96120ed
Ship with the requests module
kimadeline ec8c044
Make sure we don't shadow the "type" keyword
kimadeline fe1a530
Move discovery in a function
kimadeline 02168b7
Add Python tests for utils functions
kimadeline df1c3ae
Add copyright header
kimadeline bf1c1e2
Forgot that header
kimadeline 6b8030e
Debugging tests, they work on my machine :(
kimadeline ac629e0
Use pathlib everywhere
kimadeline a082877
News entry
kimadeline fec6118
Add docstrings to utils tests + fix nested case
kimadeline 8e89d63
Rename utils tests data + delete unused files
kimadeline 66b41be
Discovery tests
kimadeline b440762
Fix comments in utils tests
kimadeline 1189ec9
Merge branch 'main' into 17242-unittest-discovery
kimadeline e6454f8
Update comments + requirements
kimadeline d9d40ab
Add comments in the TS code, remove console logs
kimadeline 4582a99
Add tests for commandRunner.ts
kimadeline 44162d1
Add tests for unittest/testDiscoveryAdapter.ts
kimadeline 200c547
Add temp tests for workspaceTestAdapter.ts
kimadeline 73e127c
Use httpx instead of requests
kimadeline 7cd6b99
Skip tests on Python 2.7
kimadeline 49dd69a
Do not run test discovery for now
kimadeline cce1d28
Do not run test discovery for now
kimadeline 1d71719
Leave a comment
kimadeline 58f0f3a
Install dataclasses for Python < 3.7
kimadeline 551560b
Merge branch 'main' into 17242-unittest-discovery
kimadeline 2a249a2
Fix < 3.7 marker for dataclasses
kimadeline f49cb1b
Fix type annotations
kimadeline a116272
Try other skip method
kimadeline 5ed1178
Try skipping tests in a different way
kimadeline eb0d6dd
Fix tests
kimadeline dae0c16
Doesn't like stuff in __init__.py
kimadeline bc21e0c
Forgot that pathlib was also a no-go
kimadeline 3d7c2bb
I don't know how Python works
kimadeline 366ffe9
Use wildcard instead
kimadeline 0667fd4
Re-generate requirements using python 3.7
kimadeline abcae07
Apply suggestions from code review
kimadeline 2b24e0f
Merge branch '17242-unittest-discovery' of github.com:kimadeline/vsco…
kimadeline 3b7d6e5
Merge branch 'main' into 17242-unittest-discovery
kimadeline 7ee315a
First batch of fixes
kimadeline 7469a7a
Parametrize + fix tests
kimadeline a07bf7c
import pathlib instead of from pathlib import
kimadeline 13d7665
Sort imports
kimadeline b369e10
do not use __str__
kimadeline ad36883
Address remaining comments
kimadeline c824944
Last batch of comments
kimadeline c18592f
jk forgot about pathlib /
kimadeline 381aa2c
Merge branch 'main' into 17242-unittest-discovery
kimadeline 13fec99
Use a homemade socket instead of httpx
kimadeline de4b655
Make tests as todo
kimadeline 80205a2
Sort Python imports on save
kimadeline 2252116
WIP new always-alive server
kimadeline 70cee6a
Get new server architecture up
kimadeline 2eb5d3d
Update Python tests
kimadeline e64cefc
Update tests for testDiscoveryAdapter
kimadeline 72dc9c1
Fix tests for workspaceTestAdapter
kimadeline 706bbb1
Add tests to server.ts
kimadeline 52dbb9b
Cleanup
kimadeline 2453730
Add uuid to discovery tests
kimadeline 4b46847
Python linting
kimadeline f90fc71
Add description to the SocketManager class
kimadeline d64a6c6
Fix/silence sonar issues
kimadeline 067f093
Merge branch 'main' into 17242-unittest-discovery
kimadeline fe488e5
Try to silence sonar for now
kimadeline e6f5515
Add comment for tornado
kimadeline f2d4ad8
Apply Python suggestions from code review
kimadeline 8cb7c58
Wrap line
kimadeline 05adacc
Merge branch '17242-unittest-discovery' of github.com:kimadeline/vsco…
kimadeline acb1900
Update pythonFiles/testing_tools/socket_manager.py
kimadeline 54ca851
Update pythonFiles/unittestadapter/utils.py
kimadeline dd36da1
Use self.socket
kimadeline 69ed578
Merge branch 'main' into 17242-unittest-discovery
kimadeline 314b02c
Pass test discovery adapter to workspace adapter
kimadeline 9b2199f
Add a test with decorator #18228
kimadeline da37ded
Wrap nodes under test provider
kimadeline 2c5d442
Remove unused localization
kimadeline 645c7f8
Let the OS pick a port
kimadeline 5ac4dea
traceLog when response processing errors out
kimadeline f01abcf
Update pythonFiles/unittestadapter/utils.py
kimadeline 0641530
Merge branch 'main' into 17242-unittest-discovery
kimadeline 62e7f38
Fix compilation errors
kimadeline e921d28
angery
kimadeline af80b41
Use crypto.randomUUID() instead of uuid.v4()
kimadeline File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Rewrite support for unittest test discovery. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import socket | ||
import sys | ||
|
||
|
||
class SocketManager(object): | ||
"""Create a socket and connect to the given address. | ||
|
||
The address is a (host: str, port: int) tuple. | ||
Example usage: | ||
|
||
``` | ||
with SocketManager(("localhost", 6767)) as sock: | ||
request = json.dumps(payload) | ||
result = s.socket.sendall(request.encode("utf-8")) | ||
``` | ||
""" | ||
|
||
def __init__(self, addr): | ||
self.addr = addr | ||
brettcannon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.socket = None | ||
|
||
def __enter__(self): | ||
self.socket = socket.socket( | ||
socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP | ||
) | ||
if sys.platform == "win32": | ||
addr_use = socket.SO_EXCLUSIVEADDRUSE | ||
else: | ||
addr_use = socket.SO_REUSEADDR | ||
self.socket.setsockopt(socket.SOL_SOCKET, addr_use, 1) | ||
self.socket.connect(self.addr) | ||
|
||
return self | ||
|
||
def __exit__(self, *_): | ||
if self.socket: | ||
try: | ||
self.socket.shutdown(socket.SHUT_RDWR) | ||
except Exception: | ||
pass | ||
self.socket.close() |
15 changes: 15 additions & 0 deletions
15
pythonFiles/tests/unittestadapter/.data/discovery_empty.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import unittest | ||
|
||
|
||
class DiscoveryEmpty(unittest.TestCase): | ||
"""Test class for the test_empty_discovery test. | ||
|
||
The discover_tests function should return a dictionary with a "success" status, no errors, and no test tree | ||
if unittest discovery was performed successfully but no tests were found. | ||
""" | ||
|
||
def something(self) -> bool: | ||
return True |
20 changes: 20 additions & 0 deletions
20
pythonFiles/tests/unittestadapter/.data/discovery_error/file_one.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import unittest | ||
|
||
import something_else # type: ignore | ||
|
||
|
||
class DiscoveryErrorOne(unittest.TestCase): | ||
"""Test class for the test_error_discovery test. | ||
|
||
The discover_tests function should return a dictionary with an "error" status, the discovered tests, and a list of errors | ||
if unittest discovery failed at some point. | ||
""" | ||
|
||
def test_one(self) -> None: | ||
self.assertGreater(2, 1) | ||
|
||
def test_two(self) -> None: | ||
self.assertNotEqual(2, 1) |
18 changes: 18 additions & 0 deletions
18
pythonFiles/tests/unittestadapter/.data/discovery_error/file_two.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import unittest | ||
|
||
|
||
class DiscoveryErrorTwo(unittest.TestCase): | ||
"""Test class for the test_error_discovery test. | ||
|
||
The discover_tests function should return a dictionary with an "error" status, the discovered tests, and a list of errors | ||
if unittest discovery failed at some point. | ||
""" | ||
|
||
def test_one(self) -> None: | ||
self.assertGreater(2, 1) | ||
|
||
def test_two(self) -> None: | ||
self.assertNotEqual(2, 1) |
18 changes: 18 additions & 0 deletions
18
pythonFiles/tests/unittestadapter/.data/discovery_simple.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import unittest | ||
|
||
|
||
class DiscoverySimple(unittest.TestCase): | ||
"""Test class for the test_simple_discovery test. | ||
|
||
The discover_tests function should return a dictionary with a "success" status, no errors, and a test tree | ||
if unittest discovery was performed successfully. | ||
""" | ||
|
||
def test_one(self) -> None: | ||
self.assertGreater(2, 1) | ||
|
||
def test_two(self) -> None: | ||
self.assertNotEqual(2, 1) |
29 changes: 29 additions & 0 deletions
29
pythonFiles/tests/unittestadapter/.data/utils_decorated_tree.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import unittest | ||
from functools import wraps | ||
|
||
|
||
def my_decorator(f): | ||
@wraps(f) | ||
def wrapper(*args, **kwds): | ||
print("Calling decorated function") | ||
return f(*args, **kwds) | ||
|
||
return wrapper | ||
|
||
|
||
class TreeOne(unittest.TestCase): | ||
"""Test class for the test_build_decorated_tree test. | ||
|
||
build_test_tree should build a test tree with these test cases. | ||
""" | ||
|
||
@my_decorator | ||
def test_one(self) -> None: | ||
self.assertGreater(2, 1) | ||
|
||
@my_decorator | ||
def test_two(self) -> None: | ||
self.assertNotEqual(2, 1) |
17 changes: 17 additions & 0 deletions
17
pythonFiles/tests/unittestadapter/.data/utils_nested_cases/file_one.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import unittest | ||
|
||
|
||
class CaseTwoFileOne(unittest.TestCase): | ||
"""Test class for the test_nested_test_cases test. | ||
|
||
get_test_case should return tests from the test suites in this folder. | ||
""" | ||
|
||
def test_one(self) -> None: | ||
self.assertGreater(2, 1) | ||
|
||
def test_two(self) -> None: | ||
self.assertNotEqual(2, 1) |
2 changes: 2 additions & 0 deletions
2
pythonFiles/tests/unittestadapter/.data/utils_nested_cases/folder/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. |
17 changes: 17 additions & 0 deletions
17
pythonFiles/tests/unittestadapter/.data/utils_nested_cases/folder/file_two.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import unittest | ||
|
||
|
||
class CaseTwoFileTwo(unittest.TestCase): | ||
"""Test class for the test_nested_test_cases test. | ||
|
||
get_test_case should return tests from the test suites in this folder. | ||
""" | ||
|
||
def test_one(self) -> None: | ||
self.assertGreater(2, 1) | ||
|
||
def test_two(self) -> None: | ||
self.assertNotEqual(2, 1) |
17 changes: 17 additions & 0 deletions
17
pythonFiles/tests/unittestadapter/.data/utils_simple_cases.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import unittest | ||
|
||
|
||
class CaseOne(unittest.TestCase): | ||
"""Test class for the test_simple_test_cases test. | ||
|
||
get_test_case should return tests from the test suite. | ||
""" | ||
|
||
def test_one(self) -> None: | ||
self.assertGreater(2, 1) | ||
|
||
def test_two(self) -> None: | ||
self.assertNotEqual(2, 1) |
17 changes: 17 additions & 0 deletions
17
pythonFiles/tests/unittestadapter/.data/utils_simple_tree.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import unittest | ||
|
||
|
||
class TreeOne(unittest.TestCase): | ||
"""Test class for the test_build_simple_tree test. | ||
|
||
build_test_tree should build a test tree with these test cases. | ||
""" | ||
|
||
def test_one(self) -> None: | ||
self.assertGreater(2, 1) | ||
|
||
def test_two(self) -> None: | ||
self.assertNotEqual(2, 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import sys | ||
|
||
# Ignore the contents of this folder for Python 2 tests. | ||
if sys.version_info[0] < 3: | ||
kimadeline marked this conversation as resolved.
Show resolved
Hide resolved
|
||
collect_ignore_glob = ["*.py"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
|
||
import pathlib | ||
|
||
TEST_DATA_PATH = pathlib.Path(__file__).parent / ".data" | ||
|
||
|
||
def is_same_tree(tree1, tree2) -> bool: | ||
"""Helper function to test if two test trees are the same. | ||
|
||
`is_same_tree` starts by comparing the root attributes, and then checks if all children are the same. | ||
""" | ||
# Compare the root. | ||
if any(tree1[key] != tree2[key] for key in ["path", "name", "type_"]): | ||
return False | ||
|
||
# Compare child test nodes if they exist, otherwise compare test items. | ||
if "children" in tree1 and "children" in tree2: | ||
children1 = tree1["children"] | ||
children2 = tree2["children"] | ||
|
||
# Compare test nodes. | ||
if len(children1) != len(children2): | ||
return False | ||
else: | ||
return all(is_same_tree(*pair) for pair in zip(children1, children2)) | ||
elif "id_" in tree1 and "id_" in tree2: | ||
# Compare test items. | ||
return all(tree1[key] == tree2[key] for key in ["id_", "lineno"]) | ||
|
||
return False |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.