Skip to content

Commit

Permalink
Use Final for constants
Browse files Browse the repository at this point in the history
Signed-off-by: Tsuyoshi Hombashi <[email protected]>
  • Loading branch information
thombashi committed Jan 2, 2025
1 parent 1a228c6 commit bc85437
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 41 deletions.
13 changes: 8 additions & 5 deletions pytest_md_report/__version__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
__author__ = "Tsuyoshi Hombashi"
__copyright__ = f"Copyright 2020, {__author__}"
__license__ = "MIT License"
from typing import Final


__author__: Final = "Tsuyoshi Hombashi"
__copyright__: Final = f"Copyright 2020, {__author__}"
__license__: Final = "MIT License"
__version__ = "0.6.2"
__maintainer__ = __author__
__email__ = "[email protected]"
__maintainer__: Final = __author__
__email__: Final = "[email protected]"
49 changes: 25 additions & 24 deletions pytest_md_report/_const.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from enum import Enum, unique
from textwrap import dedent
from typing import Final

from pytablewriter.writer.text import MarkdownFlavor
from tcolorpy import AnsiFGColor


COLOR_NAMES = "/".join([style.name.lower() for style in list(AnsiFGColor)])
COLOR_NAMES: Final = "/".join([style.name.lower() for style in list(AnsiFGColor)])


class Header:
FILEPATH = "filepath"
TESTFUNC = "function"
SUBTOTAL = "SUBTOTAL"
FILEPATH: Final = "filepath"
TESTFUNC: Final = "function"
SUBTOTAL: Final = "SUBTOTAL"


class ColorPolicy(Enum):
Expand All @@ -21,39 +22,39 @@ class ColorPolicy(Enum):


class ZerosRender:
NUMBER = "number"
EMPTY = "empty"
LIST = (NUMBER, EMPTY)
NUMBER: Final = "number"
EMPTY: Final = "empty"
LIST: Final = (NUMBER, EMPTY)


class FGColor:
SUCCESS = "SUCCESS"
ERROR = "ERROR"
SKIP = "SKIP"
GRAYOUT = "GRAYOUT"
SUCCESS: Final = "SUCCESS"
ERROR: Final = "ERROR"
SKIP: Final = "SKIP"
GRAYOUT: Final = "GRAYOUT"


class BGColor:
EVEN_ROW = "#202020"
ODD_ROW = "black"
TOTAL_ROW = "#000000"
EVEN_ROW: Final = "#202020"
ODD_ROW: Final = "black"
TOTAL_ROW: Final = "#000000"


class Default:
COLOR_POLICY = ColorPolicy.AUTO
MARGIN = 1
MARKDOWN_FLAVOR = MarkdownFlavor.COMMON_MARK
ZEROS = ZerosRender.NUMBER
COLOR_POLICY: Final = ColorPolicy.AUTO
MARGIN: Final = 1
MARKDOWN_FLAVOR: Final = MarkdownFlavor.COMMON_MARK
ZEROS: Final = ZerosRender.NUMBER
EXCLUDE_RESULTS: list[str] = []

class FGColor:
SUCCESS = "light_green"
ERROR = "light_red"
SKIP = "light_yellow"
GRAYOUT = "light_black"
SUCCESS: Final = "light_green"
ERROR: Final = "light_red"
SKIP: Final = "light_yellow"
GRAYOUT: Final = "light_black"


OPTION_PREFIX = "md-report"
OPTION_PREFIX: Final = "md-report"


@unique
Expand Down Expand Up @@ -195,4 +196,4 @@ def __init__(self, name: str, help_msg: str) -> None:


class HelpMsg:
EXTRA_MSG_TEMPLATE = " you can also specify the value with {} environment variable."
EXTRA_MSG_TEMPLATE: Final = " you can also specify the value with {} environment variable."
16 changes: 8 additions & 8 deletions pytest_md_report/_style_filter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional, cast
from typing import Any, Final, Optional, cast

from pytablewriter.style import Cell, Style
from pytablewriter.writer import AbstractTableWriter
Expand Down Expand Up @@ -34,11 +34,11 @@ def retrieve_fg_bg_color(self, base_color: str) -> tuple[str, Optional[str]]:

def style_filter(cell: Cell, **kwargs: Any) -> Optional[Style]:
writer = cast(AbstractTableWriter, kwargs["writer"])
color_policy = cast(ColorPolicy, kwargs["color_policy"])
color_map = kwargs["color_map"]
num_rows = cast(int, kwargs["num_rows"])
headers = writer.headers
header = headers[cell.col]
color_policy: Final = cast(ColorPolicy, kwargs["color_policy"])
color_map: Final = kwargs["color_map"]
num_rows: Final = cast(int, kwargs["num_rows"])
headers: Final = writer.headers
header: Final = headers[cell.col]
fg_color = None
bg_color = None

Expand Down Expand Up @@ -105,10 +105,10 @@ def style_filter(cell: Cell, **kwargs: Any) -> Optional[Style]:
def col_separator_style_filter(
left_cell: Optional[Cell], right_cell: Optional[Cell], **kwargs: dict[str, Any]
) -> Optional[Style]:
num_rows = cast(int, kwargs["num_rows"])
num_rows: Final = cast(int, kwargs["num_rows"])
fg_color = None
bg_color = None
row = left_cell.row if left_cell else cast(Cell, right_cell).row
row: Final = left_cell.row if left_cell else cast(Cell, right_cell).row

if row == num_rows - 1:
bg_color = BGColor.TOTAL_ROW
Expand Down
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os.path
import re
from typing import Final

import setuptools


MODULE_NAME = "pytest-md-report"
REPOSITORY_URL = f"https://github.com/thombashi/{MODULE_NAME:s}"
REQUIREMENT_DIR = "requirements"
ENCODING = "utf8"
MODULE_NAME: Final = "pytest-md-report"
REPOSITORY_URL: Final = f"https://github.com/thombashi/{MODULE_NAME:s}"
REQUIREMENT_DIR: Final = "requirements"
ENCODING: Final = "utf8"

pkg_info: dict[str, str] = {}

Expand Down

0 comments on commit bc85437

Please sign in to comment.