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,105 +1,134 @@
''' '''
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)
@dataclass
class TestData:
"""Test Data"""
# for future tests
# waka_json: dict | None = None
bar_percent: tuple[float] | None = None
graph_blocks: tuple[str] | None = None
waka_graphs: tuple[list[str]] | None = None
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 = ([
"░░░░░░░░░░░░░░░░░░░░░░░░░",
"█████████████████████████",
"████████████▒░░░░░░░░░░░░",
"████████████▓░░░░░░░░░░░░",
"██████▒░░░░░░░░░░░░░░░░░░",
"██████████████████▓░░░░░░",
"▓░░░░░░░░░░░░░░░░░░░░░░░░",
"██▒░░░░░░░░░░░░░░░░░░░░░░",
"██████████████████████░░░",
"█████████████████████▓░░░",
"█░░░░░░░░░░░░░░░░░░░░░░░░",
"█▒░░░░░░░░░░░░░░░░░░░░░░░"
],
[
"⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪",
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪",
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪"
],
[
"⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑤⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑤⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩③⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑧⓪⓪⓪⓪⓪⓪",
"⑧⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑤⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑧⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑧⓪⓪⓪",
"⑩②⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩②⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪"
])
# self.dummy_readme = cleandoc("""
# My Test Readme Start
# <!--START_SECTION:waka-->
# <!--END_SECTION:waka-->
# My Test Readme End
# """)
class TestMain(unittest.TestCase): class TestMain(unittest.TestCase):
"""Testing Main Module"""
def test_make_graph(self): def test_make_graph(self) -> None:
'''Tests the make_graph function''' """Test graph maker"""
def test(percent: float, block: str, result: str): for idx, grb in enumerate(tds.graph_blocks):
self.assertEqual(make_graph(percent, block), result, for jdy, bpc in enumerate(tds.bar_percent):
f"{percent}% should return {result}") self.assertEqual(
blocks = ["░▒▓█", "⚪⚫", "⓪①②③④⑤⑥⑦⑧⑨⑩"] prime.make_graph(grb, bpc, 25),
percents = [0, 100, 49.999, 50, 25, 75, 3.14, tds.waka_graphs[idx][jdy]
9.901, 87.334, 87.333, 4.666, 4.667] )
graphGroup = [["░░░░░░░░░░░░░░░░░░░░░░░░░",
"█████████████████████████",
"████████████▒░░░░░░░░░░░░",
"████████████▓░░░░░░░░░░░░",
"██████▒░░░░░░░░░░░░░░░░░░",
"██████████████████▓░░░░░░",
"▓░░░░░░░░░░░░░░░░░░░░░░░░",
"██▒░░░░░░░░░░░░░░░░░░░░░░",
"██████████████████████░░░",
"█████████████████████▓░░░",
"█░░░░░░░░░░░░░░░░░░░░░░░░",
"█▒░░░░░░░░░░░░░░░░░░░░░░░"],
["⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪⚪⚪⚪",
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪",
"⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚫⚪⚪⚪",
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪",
"⚫⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪⚪"],
["⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑤⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑤⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩③⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑧⓪⓪⓪⓪⓪⓪",
"⑧⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑤⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑧⓪⓪⓪",
"⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑩⑧⓪⓪⓪",
"⑩②⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪",
"⑩②⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪⓪"]]
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): def test_make_title(self) -> None:
'''Tests generate_new_readme method from main.py''' """Test title maker"""
dummy_readme = '''My Readme Start self.assertRegex(
<!--START_SECTION:waka--> prime.make_title('2022-01-11T23:18:19Z', '2021-12-09T10:22:06Z'),
<!--END_SECTION:waka--> r'From: \d{2} \w{3,9} \d{4} - To: \d{2} \w{3,9} \d{4}'
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): # Known test limits
'''Tests decode_readme method from main.py''' # # prep_content() and churn():
dummy_data = base64.b64encode(bytes('Some Data From GitHub', 'utf-8')) # requires additional modifications such as changing
expected_result = 'Some Data From GitHub' # globally passed values to parametrically passing them
actual_result = decode_readme(dummy_data) # # fetch_stats(): would required HTTP Authentication
self.assertEqual(actual_result, expected_result)
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()