-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Unify test suites' module exclusion logic #14575
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
be4afdc
Reduce DataSuite use of module exclusion lists
ikonst 34b644a
style
ikonst 76ec300
Remove unused NOT_DUMPED_MODULES
ikonst 0f3b959
test_paths -> test_modules
ikonst a54a74c
update testtypegen
ikonst 0b97b6f
fix windows compat
ikonst 6e74f50
Merge branch 'master' into 2023-02-01-test_paths
ikonst 1b3330d
Merge branch 'master' into 2023-02-01-test_paths
ikonst 4b8e0fc
Merge branch 'master' into 2023-02-01-test_paths
ikonst b8b7cca
Merge branch 'master' into 2023-02-01-test_paths
ikonst 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
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 |
---|---|---|
|
@@ -41,6 +41,14 @@ class DeleteFile(NamedTuple): | |
FileOperation: _TypeAlias = Union[UpdateFile, DeleteFile] | ||
|
||
|
||
def _file_arg_to_module(filename: str) -> str: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if "there's a function for that" in stdlib, but seemed easy enough to add one here. (I'm sure it misses some cases, just wanted something short and practical.) |
||
filename, _ = os.path.splitext(filename) | ||
parts = filename.split("/") # not os.sep since it comes from test data | ||
if parts[-1] == "__init__": | ||
parts.pop() | ||
return ".".join(parts) | ||
|
||
|
||
def parse_test_case(case: DataDrivenTestCase) -> None: | ||
"""Parse and prepare a single case from suite with test case descriptions. | ||
|
||
|
@@ -65,22 +73,26 @@ def parse_test_case(case: DataDrivenTestCase) -> None: | |
rechecked_modules: dict[int, set[str]] = {} # from run number module names | ||
triggered: list[str] = [] # Active triggers (one line per incremental step) | ||
targets: dict[int, list[str]] = {} # Fine-grained targets (per fine-grained update) | ||
test_modules: list[str] = [] # Modules which are deemed "test" (vs "fixture") | ||
|
||
# Process the parsed items. Each item has a header of form [id args], | ||
# optionally followed by lines of text. | ||
item = first_item = test_items[0] | ||
test_modules.append("__main__") | ||
for item in test_items[1:]: | ||
if item.id in {"file", "outfile", "outfile-re"}: | ||
if item.id in {"file", "fixture", "outfile", "outfile-re"}: | ||
# Record an extra file needed for the test case. | ||
assert item.arg is not None | ||
contents = expand_variables("\n".join(item.data)) | ||
file_entry = (join(base_path, item.arg), contents) | ||
if item.id == "file": | ||
files.append(file_entry) | ||
path = join(base_path, item.arg) | ||
if item.id != "fixture": | ||
test_modules.append(_file_arg_to_module(item.arg)) | ||
if item.id in {"file", "fixture"}: | ||
files.append((path, contents)) | ||
elif item.id == "outfile-re": | ||
output_files.append((file_entry[0], re.compile(file_entry[1].rstrip(), re.S))) | ||
else: | ||
output_files.append(file_entry) | ||
output_files.append((path, re.compile(contents.rstrip(), re.S))) | ||
elif item.id == "outfile": | ||
output_files.append((path, contents)) | ||
elif item.id == "builtins": | ||
# Use an alternative stub file for the builtins module. | ||
assert item.arg is not None | ||
|
@@ -207,6 +219,7 @@ def parse_test_case(case: DataDrivenTestCase) -> None: | |
case.triggered = triggered or [] | ||
case.normalize_output = normalize_output | ||
case.expected_fine_grained_targets = targets | ||
case.test_modules = test_modules | ||
|
||
|
||
class DataDrivenTestCase(pytest.Item): | ||
|
@@ -225,6 +238,8 @@ class DataDrivenTestCase(pytest.Item): | |
|
||
# (file path, file content) tuples | ||
files: list[tuple[str, str]] | ||
# Modules which is to be considered "test" rather than "fixture" | ||
test_modules: list[str] | ||
expected_stale_modules: dict[int, set[str]] | ||
expected_rechecked_modules: dict[int, set[str]] | ||
expected_fine_grained_targets: dict[int, list[str]] | ||
|
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
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
processed_targets
is (as the comment says) for testing only, specifically forTypeCheckSuite
.I'm adding the module's name so that
TypeCheckSuite
could perform filtering more coherently: