fix: update tests, lists known issues, sep data & logic

This commit is contained in:
Jovial Joe Jayarson 2022-02-25 09:54:27 +05:30
parent c1064d56ae
commit 9486a673b8
4 changed files with 11478 additions and 92 deletions

View File

@ -1,7 +1,9 @@
language: python language: python
python: python:
- "3.7" - "3.10"
install: install:
- pip install -r requirements.txt - curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python - --version 1.1.13
- poetry shell
- poetry install
script: script:
- python -m unittest discover - poetry run python -m unittest discover

View File

@ -0,0 +1,9 @@
"""
Initialize test module
"""
# standard
import logging
# comment to enable logging w/ tests
logging.disable(logging.CRITICAL)

11346
tests/template.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -1,29 +1,47 @@
''' '''
Tests for the main.py Tests for the main.py
''' '''
from importlib import import_module
from dataclasses import dataclass
# from inspect import cleandoc
# from json import loads
import unittest import unittest
import datetime import sys
import base64
import os import os
try: try:
# For travis build which uses prime = import_module('main')
# works when running as
# python -m unittest discover # python -m unittest discover
from main import make_graph, generate_new_readme, decode_readme except ImportError as err:
except Exception as e: print(err)
print("Error: missing 'main.py'\nTrying absolute import...") # sys.exit(1)
class TestMain(unittest.TestCase):
def test_make_graph(self): @dataclass
'''Tests the make_graph function''' class TestData:
def test(percent: float, block: str, result: str): """Test Data"""
self.assertEqual(make_graph(percent, block), result, # for future tests
f"{percent}% should return {result}") # waka_json: dict | None = None
blocks = ["░▒▓█", "⚪⚫", "⓪①②③④⑤⑥⑦⑧⑨⑩"] bar_percent: tuple[float] | None = None
percents = [0, 100, 49.999, 50, 25, 75, 3.14, graph_blocks: tuple[str] | None = None
9.901, 87.334, 87.333, 4.666, 4.667] waka_graphs: tuple[list[str]] | None = None
graphGroup = [["░░░░░░░░░░░░░░░░░░░░░░░░░", dummy_readme: str = ''
def populate(self) -> None:
"""Populate Test Data"""
# for future tests
# with open(file='tests/template.json', mode='rt', encoding='utf-8') as wkf:
# self.waka_json = loads(wkf.read())
self.bar_percent = (
0, 100, 49.999, 50, 25, 75, 3.14, 9.901, 87.334, 87.333, 4.666, 4.667
)
self.graph_blocks = ("░▒▓█", "⚪⚫", "⓪①②③④⑤⑥⑦⑧⑨⑩")
self.waka_graphs = ([
"░░░░░░░░░░░░░░░░░░░░░░░░░",
"█████████████████████████", "█████████████████████████",
"████████████▒░░░░░░░░░░░░", "████████████▒░░░░░░░░░░░░",
"████████████▓░░░░░░░░░░░░", "████████████▓░░░░░░░░░░░░",
@ -34,8 +52,10 @@ class TestMain(unittest.TestCase):
"██████████████████████░░░", "██████████████████████░░░",
"█████████████████████▓░░░", "█████████████████████▓░░░",
"█░░░░░░░░░░░░░░░░░░░░░░░░", "█░░░░░░░░░░░░░░░░░░░░░░░░",
"█▒░░░░░░░░░░░░░░░░░░░░░░░"], "█▒░░░░░░░░░░░░░░░░░░░░░░░"
["⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪", ],
[
"⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫", "⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪", "⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪", "⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
@ -46,8 +66,10 @@ class TestMain(unittest.TestCase):
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪", "⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪", "⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪",
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪", "⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪"], "⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪"
["⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪", ],
[
"⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩", "⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑤⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪", "⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑤⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑤⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪", "⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑤⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
@ -58,48 +80,55 @@ class TestMain(unittest.TestCase):
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑧⓪⓪⓪", "⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑧⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑧⓪⓪⓪", "⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑧⓪⓪⓪",
"⑩②⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪", "⑩②⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩②⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪"]] "⑩②⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪"
for i, graphs in enumerate(graphGroup): ])
os.environ["INPUT_BLOCKS"] = blocks[i]
for j, graph in enumerate(graphs):
test(percents[j], blocks[i], graph)
def test_generate_new_readme(self): # self.dummy_readme = cleandoc("""
'''Tests generate_new_readme method from main.py''' # My Test Readme Start
dummy_readme = '''My Readme Start # <!--START_SECTION:waka-->
<!--START_SECTION:waka--> # <!--END_SECTION:waka-->
<!--END_SECTION:waka--> # My Test Readme End
My Readme End''' # """)
dummy_stats = '''```text
Python 24 hrs 15 mins 100.00 %
```'''
expected_generated_readme = '''My Readme Start
<!--START_SECTION:waka-->\n```text
Python 24 hrs 15 mins 100.00 %
```\n<!--END_SECTION:waka-->
My Readme End
'''
expected_generated_readme = expected_generated_readme.strip()
actual_generated_readme = generate_new_readme(dummy_stats, dummy_readme)
self.assertEqual(actual_generated_readme, expected_generated_readme)
def test_decode_readme(self):
'''Tests decode_readme method from main.py''' class TestMain(unittest.TestCase):
dummy_data = base64.b64encode(bytes('Some Data From GitHub', 'utf-8')) """Testing Main Module"""
expected_result = 'Some Data From GitHub'
actual_result = decode_readme(dummy_data) def test_make_graph(self) -> None:
self.assertEqual(actual_result, expected_result) """Test graph maker"""
for idx, grb in enumerate(tds.graph_blocks):
for jdy, bpc in enumerate(tds.bar_percent):
self.assertEqual(
prime.make_graph(grb, bpc, 25),
tds.waka_graphs[idx][jdy]
)
def test_make_title(self) -> None:
"""Test title maker"""
self.assertRegex(
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}'
)
# Known test limits
# # prep_content() and churn():
# requires additional modifications such as changing
# globally passed values to parametrically passing them
# # fetch_stats(): would required HTTP Authentication
tds = TestData()
tds.populate()
if __name__ == '__main__': if __name__ == '__main__':
if __package__ is None: try:
import sys sys.path.insert(0, os.path.abspath(
# because test_main.py is one level below main.py os.path.join(os.path.dirname(__file__), '..')
# python test/test_main.py ))
sys.path.append(os.path.dirname( import main as prime
os.path.dirname(os.path.abspath(__file__)))) # works when running as
from main import make_graph, generate_new_readme, decode_readme # python tests/test_main.py
else: except ImportError as im_er:
# Later on if WakaReadme is implemetaion as package print(im_er)
# python -m tests/test_main sys.exit(1)
from ..main import make_graph, generate_new_readme, decode_readme
unittest.main() unittest.main()