maint: follows google pydocstyle

This commit is contained in:
Jovial Joe Jayarson 2023-06-13 19:40:52 +05:30
parent 9bee9ba11b
commit 82c9408d6d
2 changed files with 33 additions and 52 deletions

65
main.py
View File

@ -1,25 +1,20 @@
""" """WakaReadme : WakaTime progress visualizer.
WakaReadme : WakaTime progress visualizer
=========================================
Wakatime Metrics on your Profile Readme. Wakatime Metrics on your Profile Readme.
Title: Title:
------
```txt ```txt
From: 15 February, 2022 - To: 22 February, 2022 From: 15 February, 2022 - To: 22 February, 2022
```` ````
Byline: Byline:
-------
```txt ```txt
Total: 34 hrs 43 mins Total: 34 hrs 43 mins
``` ```
Body: Body:
-----
```txt ```txt
Python 27 hrs 29 mins 77.83 % Python 27 hrs 29 mins 77.83 %
@ -29,7 +24,7 @@ TOML 1 hr 48 mins ⣿⣤⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀
Other 35 mins 01.68 % Other 35 mins 01.68 %
``` ```
#### Contents = Title + Byline + Body Contents := Title + Byline + Body
""" """
# standard # standard
@ -85,18 +80,25 @@ except ImportError as im_err:
def strtobool(val: str | bool): def strtobool(val: str | bool):
""" """Strtobool.
strtobool
---------
PEP 632 https://www.python.org/dev/peps/pep-0632/ is depreciating distutils. PEP 632 https://www.python.org/dev/peps/pep-0632/ is depreciating distutils.
This is from the official source code with slight modifications. This is from the official source code with slight modifications.
Converts a string representation of truth to True or False. Converts a string representation of truth to `True` or `False`.
- True values are `'y', 'yes', 't', 'true', 'on', and '1'`. Args:
- False values are `'n', 'no', 'f', 'false', 'off', and '0'`. val:
- Raises `ValueError` if `val` is anything else. Value to be converted to bool.
Returns:
(Literal[True]):
If `val` is any of 'y', 'yes', 't', 'true', 'on', or '1'.
(Literal[False]):
If `val` is any of 'n', 'no', 'f', 'false', 'off', and '0'.
Raises:
ValueError: If `val` is anything else.
""" """
if isinstance(val, bool): if isinstance(val, bool):
return val return val
@ -117,10 +119,7 @@ def strtobool(val: str | bool):
@dataclass(slots=True) @dataclass(slots=True)
class WakaInput: class WakaInput:
""" """WakaReadme Input Env Variables."""
WakaReadme Input Env Variables
------------------------------
"""
# constants # constants
prefix_length: int = 16 prefix_length: int = 16
@ -152,10 +151,7 @@ class WakaInput:
stop_at_other: str | bool = os.getenv("INPUT_STOP_AT_OTHER") or False stop_at_other: str | bool = os.getenv("INPUT_STOP_AT_OTHER") or False
def validate_input(self): def validate_input(self):
""" """Validate Input Env Variables."""
Validate Input Env Variables
----------------------------
"""
logger.debug("Validating input variables") logger.debug("Validating input variables")
if not self.gh_token or not self.waka_key or not self.api_base_url or not self.repository: if not self.gh_token or not self.waka_key or not self.api_base_url or not self.repository:
logger.error("Invalid inputs") logger.error("Invalid inputs")
@ -217,9 +213,7 @@ class WakaInput:
def make_title(dawn: str | None, dusk: str | None, /): def make_title(dawn: str | None, dusk: str | None, /):
""" """WakaReadme Title.
WakaReadme Title
----------------
Makes title for WakaReadme. Makes title for WakaReadme.
""" """
@ -240,9 +234,7 @@ def make_title(dawn: str | None, dusk: str | None, /):
def make_graph(block_style: str, percent: float, gr_len: int, lg_nm: str = "", /): def make_graph(block_style: str, percent: float, gr_len: int, lg_nm: str = "", /):
""" """WakaReadme Graph.
WakaReadme Graph
----------------
Makes time graph from the API's data. Makes time graph from the API's data.
""" """
@ -259,9 +251,7 @@ def make_graph(block_style: str, percent: float, gr_len: int, lg_nm: str = "", /
def prep_content(stats: dict[str, Any], language_count: int = 5, stop_at_other: bool = False, /): def prep_content(stats: dict[str, Any], language_count: int = 5, stop_at_other: bool = False, /):
""" """WakaReadme Prepare Markdown.
WakaReadme Prepare Markdown
---------------------------
Prepared markdown content from the fetched statistics. Prepared markdown content from the fetched statistics.
``` ```
@ -328,9 +318,7 @@ def prep_content(stats: dict[str, Any], language_count: int = 5, stop_at_other:
def fetch_stats(): def fetch_stats():
""" """WakaReadme Fetch Stats.
WakaReadme Fetch Stats
----------------------
Returns statistics as JSON string. Returns statistics as JSON string.
""" """
@ -371,9 +359,7 @@ def fetch_stats():
def churn(old_readme: str, /): def churn(old_readme: str, /):
""" """WakaReadme Churn.
WakaReadme Churn
----------------
Composes WakaTime stats within markdown code snippet. Composes WakaTime stats within markdown code snippet.
""" """
@ -410,10 +396,7 @@ def churn(old_readme: str, /):
def genesis(): def genesis():
""" """Run Program."""
Run Program
-----------
"""
logger.debug("Connecting to GitHub") logger.debug("Connecting to GitHub")
gh_connect = Github(wk_i.gh_token) gh_connect = Github(wk_i.gh_token)
# since a validator is being used casting to string here is okay # since a validator is being used casting to string here is okay

View File

@ -1,6 +1,4 @@
""" """Unit Tests."""
Tests for the main.py
"""
# standard # standard
from importlib import import_module from importlib import import_module
@ -26,7 +24,7 @@ except ImportError as err:
@dataclass @dataclass
class TestData: class TestData:
"""Test Data""" """Test Data."""
# for future tests # for future tests
# waka_json: dict[str, dict[str, Any]] = field( # waka_json: dict[str, dict[str, Any]] = field(
@ -38,7 +36,7 @@ class TestData:
dummy_readme: str = "" dummy_readme: str = ""
def populate(self) -> None: def populate(self) -> None:
"""Populate Test Data""" """Populate Test Data."""
# for future tests # for future tests
# with open( # with open(
# file=Path(__file__).parent / "sample_data.json", # file=Path(__file__).parent / "sample_data.json",
@ -105,10 +103,10 @@ class TestData:
class TestMain(unittest.TestCase): class TestMain(unittest.TestCase):
"""Testing Main Module""" """Testing Main Module."""
def test_make_graph(self) -> None: def test_make_graph(self) -> None:
"""Test graph maker""" """Test graph maker."""
if not tds.graph_blocks or not tds.waka_graphs or not tds.bar_percent: if not tds.graph_blocks or not tds.waka_graphs or not tds.bar_percent:
raise AssertionError("Data population failed") raise AssertionError("Data population failed")
@ -118,14 +116,14 @@ class TestMain(unittest.TestCase):
self.assertEqual(prime.make_graph(grb, bpc, 25), tds.waka_graphs[idx][jdy]) self.assertEqual(prime.make_graph(grb, bpc, 25), tds.waka_graphs[idx][jdy])
def test_make_title(self) -> None: def test_make_title(self) -> None:
"""Test title maker""" """Test title maker."""
self.assertRegex( self.assertRegex(
prime.make_title("2022-01-11T23:18:19Z", "2021-12-09T10:22:06Z"), prime.make_title("2022-01-11T23:18:19Z", "2021-12-09T10:22:06Z"),
r"From: \d{2} \w{3,9} \d{4} - To: \d{2} \w{3,9} \d{4}", r"From: \d{2} \w{3,9} \d{4} - To: \d{2} \w{3,9} \d{4}",
) )
def test_strtobool(self) -> None: def test_strtobool(self) -> None:
"""Test string to bool""" """Test string to bool."""
self.assertTrue(prime.strtobool("Yes")) self.assertTrue(prime.strtobool("Yes"))
self.assertFalse(prime.strtobool("nO")) self.assertFalse(prime.strtobool("nO"))
self.assertTrue(prime.strtobool(True)) self.assertTrue(prime.strtobool(True))