Skip to content

Commit

Permalink
Better typing for test options and fix existing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Nov 29, 2021
1 parent 32b12ff commit df20ded
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 10 deletions.
42 changes: 37 additions & 5 deletions pylint/testutils/functional/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE

import configparser
import sys
from os.path import basename, exists, join
from typing import Dict, List, Tuple, Union
from typing import List, Tuple


def parse_python_version(ver_str: str) -> Tuple[int, ...]:
Expand All @@ -15,6 +16,33 @@ class NoFileError(Exception):
pass


if sys.version_info >= (3, 8):
from typing import TypedDict
else:
from typing_extensions import TypedDict


class TestFileOptions(TypedDict):
min_pyver: Tuple[int, ...]
max_pyver: Tuple[int, ...]
min_pyver_end_position: Tuple[int, ...]
requires: List[str]
except_implementations: str # Type is actually comma separated list of string
exclude_platforms: str # Type is actually comma separated list of string


# mypy need something literal, we can't create this dynamically from TestFileOptions
POSSIBLE_TEST_OPTIONS = {
"min_pyver",
"max_pyver",
"min_pyver_end_position",
"requires",
"except_implementations",
"exclude_platforms",
"exclude_platforms",
}


class FunctionalTestFile:
"""A single functional test case file with options."""

Expand All @@ -28,13 +56,13 @@ class FunctionalTestFile:
def __init__(self, directory: str, filename: str) -> None:
self._directory = directory
self.base = filename.replace(".py", "")
self.options: Dict[str, Union[Tuple[int, ...], List[str]]] = {
self.options: TestFileOptions = {
"min_pyver": (2, 5),
"max_pyver": (4, 0),
"min_pyver_end_position": (3, 8),
"requires": [],
"except_implementations": [],
"exclude_platforms": [],
"except_implementations": "",
"exclude_platforms": "",
}
self._parse_options()

Expand All @@ -51,7 +79,11 @@ def _parse_options(self) -> None:

for name, value in cp.items("testoptions"):
conv = self._CONVERTERS.get(name, lambda v: v)
self.options[name] = conv(value)

assert (
name in POSSIBLE_TEST_OPTIONS
), f"[testoptions]' can only contains one of {POSSIBLE_TEST_OPTIONS}"
self.options[name] = conv(value) # type: ignore[misc]

@property
def option_file(self) -> str:
Expand Down
4 changes: 3 additions & 1 deletion tests/functional/f/fixme.rc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[testoptions]
[MISCELLANEOUS]
# List of note tags to take in consideration, separated by a comma.
notes=XXX,TODO,./TODO
# Regular expression of note tags to take in consideration.
notes-rgx=FIXME(?!.*ISSUE-\d+)|TO.*DO
2 changes: 1 addition & 1 deletion tests/functional/r/regression/regression_issue_4631.rc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[testoptions]
[MASTER]
limit-inference-results=0
2 changes: 1 addition & 1 deletion tests/functional/t/too/too_few_public_methods_excluded.rc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[testoptions]
[DESIGN]
min-public-methods=10 # to combat inherited methods

exclude-too-few-public-methods=json.*,^.*Control$
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[testoptions]
[DESIGN]
max-parents=2
ignored-parents=functional.t.too.too_many_ancestors_ignored_parents.E
2 changes: 1 addition & 1 deletion tests/functional/t/too/too_many_statements.rc
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[testoptions]
[DESIGN]
max-statements=5

0 comments on commit df20ded

Please sign in to comment.