Skip to content

Commit

Permalink
type extras.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gnikonorov committed Dec 21, 2020
1 parent cbfcf61 commit dd258ea
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions src/pytest_html/extras.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# type: ignore
from typing import Dict
from typing import Optional

FORMAT_HTML = "html"
FORMAT_IMAGE = "image"
Expand All @@ -11,7 +12,13 @@
FORMAT_VIDEO = "video"


def extra(content, format_type, name=None, mime_type=None, extension=None):
def extra(
content: str,
format_type: str,
name: Optional[str] = None,
mime_type: Optional[str] = None,
extension: Optional[str] = None,
) -> Dict[str, Optional[str]]:
return {
"name": name,
"format_type": format_type,
Expand All @@ -21,41 +28,51 @@ def extra(content, format_type, name=None, mime_type=None, extension=None):
}


def html(content):
def html(content: str) -> Dict[str, Optional[str]]:
return extra(content, FORMAT_HTML)


def image(content, name="Image", mime_type="image/png", extension="png"):
def image(
content: str,
name: str = "Image",
mime_type: str = "image/png",
extension: str = "png",
) -> Dict[str, Optional[str]]:
return extra(content, FORMAT_IMAGE, name, mime_type, extension)


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


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


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


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


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


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


def video(content, name="Video", mime_type="video/mp4", extension="mp4"):
def video(
content: str,
name: str = "Video",
mime_type: str = "video/mp4",
extension: str = "mp4",
) -> Dict[str, Optional[str]]:
return extra(content, FORMAT_VIDEO, name, mime_type, extension)


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

0 comments on commit dd258ea

Please sign in to comment.