Skip to content

Commit

Permalink
unescape html characters in templates, hide error codes so tests work…
Browse files Browse the repository at this point in the history
…, run CI in 3.11
  • Loading branch information
jakkdl committed Mar 27, 2023
1 parent 2a4fcd4 commit dfa01aa
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
# TODO: remove `7.1` in the next release
pytest-version: ["~=6.2", "~=7.1", "~=7.2"]

Expand Down
2 changes: 1 addition & 1 deletion pytest_mypy_plugins/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def construct_mapping(self, node: yaml.MappingNode, deep: bool = False) -> Dict[
mapping = super().construct_mapping(node, deep=deep)
# Add 1 so line numbering starts at 1
starting_line = node.start_mark.line + 1
for (title_node, contents_node) in node.value:
for title_node, contents_node in node.value:
if title_node.value == "main":
starting_line = title_node.start_mark.line + 1
mapping["__line__"] = starting_line
Expand Down
3 changes: 1 addition & 2 deletions pytest_mypy_plugins/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def flush_errors(new_messages: List[str], serious: bool) -> None:
build.build(sources, options, flush_errors=flush_errors, fscache=fscache)

except SystemExit as sysexit:
return sysexit.code
return sysexit.code if isinstance(sysexit.code, int) else 1
finally:
fscache.flush()

Expand Down Expand Up @@ -241,7 +241,6 @@ def runtest(self) -> None:
temp_dir = tempfile.TemporaryDirectory(prefix="pytest-mypy-", dir=self.root_directory)

except (FileNotFoundError, PermissionError, NotADirectoryError) as e:

raise TypecheckAssertionError(
error_message=f"Testing base directory {self.root_directory} must exist and be writable"
) from e
Expand Down
2 changes: 2 additions & 0 deletions pytest_mypy_plugins/tests/test-parametrized.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@
out: |
main:2: note: Revealed type is "{{ rt }}"
main:4: error: Unsupported operand types for / ("str" and "int")
mypy_config: |
hide_error_codes = True
2 changes: 2 additions & 0 deletions pytest_mypy_plugins/tests/test-paths-from-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
content: |
def extra_fn() -> None:
pass
mypy_config: |
hide_error_codes = True
6 changes: 5 additions & 1 deletion pytest_mypy_plugins/tests/test-simple-cases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
main: |
a = 1
a.lower() # E: "int" has no attribute "lower"
mypy_config: |
hide_error_codes = True
- case: custom_mypy_config_strict_optional_true_set
Expand Down Expand Up @@ -88,6 +90,8 @@
main: |
a = 1
a.lower() # E: "int" has no attribute "lower"
mypy_config: |
hide_error_codes = True
- case: fail_if_message_does_not_match
expect_fail: yes
Expand All @@ -101,4 +105,4 @@
a = 'abc'
reveal_type(a)
out: |
main:2: note: Some other message
main:2: note: Some other message
11 changes: 11 additions & 0 deletions pytest_mypy_plugins/tests/test_parametrized_html_escape.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- case: gt_in_rt
parametrized:
- val: bool
rt: def (builtins.object =) -> builtins.bool
main: |
reveal_type({{ val }}) # N: Revealed type is "{{ rt }}"
- case: gt_in_comment
main: |
reveal_type(bool) # N: Revealed type is "def (builtins.object =) -> builtins.bool"
5 changes: 4 additions & 1 deletion pytest_mypy_plugins/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Borrowed from Pew.
# See https://github.com/berdario/pew/blob/master/pew/_utils.py#L82
import contextlib
import html
import inspect
import io
import os
Expand Down Expand Up @@ -352,7 +353,9 @@ def extract_output_matchers_from_out(out: str, params: Mapping[str, Any], regex:


def render_template(template: str, data: Mapping[str, Any]) -> str:
return chevron.render(template=template, data={k: v if v is not None else "None" for k, v in data.items()})
return html.unescape(
chevron.render(template=template, data={k: v if v is not None else "None" for k, v in data.items()})
)


def get_func_first_lnum(attr: Callable[..., None]) -> Optional[Tuple[int, List[str]]]:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Typing :: Typed",
],
)

0 comments on commit dfa01aa

Please # to comment.