Skip to content

Commit 927096a

Browse files
committed
Add mypy to CI pipeline and begin typing effort
1 parent cc80986 commit 927096a

File tree

11 files changed

+73
-17
lines changed

11 files changed

+73
-17
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ repos:
4444
additional_dependencies:
4545
4646
args: [src]
47+
- repo: https://github.com/pre-commit/mirrors-mypy
48+
rev: v0.790
49+
hooks:
50+
- id: mypy
51+
files: ^(src/pytest_html|testing)
4752
- repo: local
4853
hooks:
4954
- id: rst

setup.cfg

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
11
[bdist_wheel]
22
universal = 0
3+
4+
[mypy]
5+
check_untyped_defs = True
6+
disallow_any_generics = True
7+
disallow_incomplete_defs = True
8+
disallow_untyped_calls = True
9+
disallow_untyped_decorators = True
10+
disallow_untyped_defs = True
11+
ignore_missing_imports = True
12+
no_implicit_optional = True
13+
no_implicit_reexport = True
14+
show_error_codes = True
15+
strict_equality = True
16+
warn_redundant_casts = True
17+
warn_return_any = True
18+
warn_unreachable = True
19+
warn_unused_configs = True

src/pytest_html/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
try:
2-
from . import __version
2+
from . import __version # type: ignore
33

44
__version__ = __version.version
55
except ImportError:

src/pytest_html/extras.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# This Source Code Form is subject to the terms of the Mozilla Public
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
from typing import Dict
5+
from typing import Optional
46

57
FORMAT_HTML = "html"
68
FORMAT_IMAGE = "image"
@@ -10,7 +12,13 @@
1012
FORMAT_VIDEO = "video"
1113

1214

13-
def extra(content, format_type, name=None, mime_type=None, extension=None):
15+
def extra(
16+
content: str,
17+
format_type: str,
18+
name: Optional[str] = None,
19+
mime_type: Optional[str] = None,
20+
extension: Optional[str] = None,
21+
) -> Dict[str, Optional[str]]:
1422
return {
1523
"name": name,
1624
"format_type": format_type,
@@ -20,41 +28,51 @@ def extra(content, format_type, name=None, mime_type=None, extension=None):
2028
}
2129

2230

23-
def html(content):
31+
def html(content: str) -> Dict[str, Optional[str]]:
2432
return extra(content, FORMAT_HTML)
2533

2634

27-
def image(content, name="Image", mime_type="image/png", extension="png"):
35+
def image(
36+
content: str,
37+
name: str = "Image",
38+
mime_type: str = "image/png",
39+
extension: str = "png",
40+
) -> Dict[str, Optional[str]]:
2841
return extra(content, FORMAT_IMAGE, name, mime_type, extension)
2942

3043

31-
def png(content, name="Image"):
44+
def png(content: str, name: str = "Image") -> Dict[str, Optional[str]]:
3245
return image(content, name, mime_type="image/png", extension="png")
3346

3447

35-
def jpg(content, name="Image"):
48+
def jpg(content: str, name: str = "Image") -> Dict[str, Optional[str]]:
3649
return image(content, name, mime_type="image/jpeg", extension="jpg")
3750

3851

39-
def svg(content, name="Image"):
52+
def svg(content: str, name: str = "Image") -> Dict[str, Optional[str]]:
4053
return image(content, name, mime_type="image/svg+xml", extension="svg")
4154

4255

43-
def json(content, name="JSON"):
56+
def json(content: str, name: str = "JSON") -> Dict[str, Optional[str]]:
4457
return extra(content, FORMAT_JSON, name, "application/json", "json")
4558

4659

47-
def text(content, name="Text"):
60+
def text(content: str, name: str = "Text") -> Dict[str, Optional[str]]:
4861
return extra(content, FORMAT_TEXT, name, "text/plain", "txt")
4962

5063

51-
def url(content, name="URL"):
64+
def url(content: str, name: str = "URL") -> Dict[str, Optional[str]]:
5265
return extra(content, FORMAT_URL, name)
5366

5467

55-
def video(content, name="Video", mime_type="video/mp4", extension="mp4"):
68+
def video(
69+
content: str,
70+
name: str = "Video",
71+
mime_type: str = "video/mp4",
72+
extension: str = "mp4",
73+
) -> Dict[str, Optional[str]]:
5674
return extra(content, FORMAT_VIDEO, name, mime_type, extension)
5775

5876

59-
def mp4(content, name="Video"):
77+
def mp4(content: str, name: str = "Video") -> Dict[str, Optional[str]]:
6078
return video(content, name)

src/pytest_html/hooks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This Source Code Form is subject to the terms of the Mozilla Public
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
# type: ignore
45

56

67
def pytest_html_report_title(report):

src/pytest_html/html_report.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# type: ignore
12
import bisect
23
import datetime
34
import json

src/pytest_html/outcome.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
from typing import Optional
2+
13
from py.xml import html
24

35

46
class Outcome:
5-
def __init__(self, outcome, total=0, label=None, test_result=None, class_html=None):
7+
def __init__(
8+
self,
9+
outcome: str,
10+
total: int = 0,
11+
label: Optional[str] = None,
12+
test_result: Optional[str] = None,
13+
class_html: Optional[str] = None,
14+
) -> None:
615
self.outcome = outcome
716
self.label = label or outcome
817
self.class_html = class_html or outcome
@@ -12,7 +21,7 @@ def __init__(self, outcome, total=0, label=None, test_result=None, class_html=No
1221
self.generate_checkbox()
1322
self.generate_summary_item()
1423

15-
def generate_checkbox(self):
24+
def generate_checkbox(self) -> None:
1625
checkbox_kwargs = {"data-test-result": self.test_result.lower()}
1726
if self.total == 0:
1827
checkbox_kwargs["disabled"] = "true"
@@ -27,7 +36,7 @@ def generate_checkbox(self):
2736
**checkbox_kwargs,
2837
)
2938

30-
def generate_summary_item(self):
39+
def generate_summary_item(self) -> None:
3140
self.summary_item = html.span(
3241
f"{self.total} {self.label}", class_=self.class_html
3342
)

src/pytest_html/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# This Source Code Form is subject to the terms of the Mozilla Public
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
# type: ignore
45
import os
56

67
import pytest

src/pytest_html/result.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# type: ignore
12
import json
23
import os
34
import re

src/pytest_html/util.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import importlib
22
from functools import lru_cache
3+
from types import ModuleType
4+
from typing import Optional
35

46

57
@lru_cache()
6-
def ansi_support():
8+
def ansi_support() -> Optional[ModuleType]:
79
try:
810
# from ansi2html import Ansi2HTMLConverter, style # NOQA
911
return importlib.import_module("ansi2html")
1012
except ImportError:
1113
# ansi2html is not installed
12-
pass
14+
return None

0 commit comments

Comments
 (0)