fix: update tests, lists known issues, sep data & logic
This commit is contained in:
parent
c1064d56ae
commit
9486a673b8
@ -1,7 +1,9 @@
|
||||
language: python
|
||||
python:
|
||||
- "3.7"
|
||||
- "3.10"
|
||||
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:
|
||||
- python -m unittest discover
|
||||
- poetry run python -m unittest discover
|
||||
|
@ -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
11346
tests/template.json
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,29 +1,47 @@
|
||||
'''
|
||||
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 datetime
|
||||
import base64
|
||||
import sys
|
||||
import os
|
||||
|
||||
try:
|
||||
# For travis build which uses
|
||||
prime = import_module('main')
|
||||
# works when running as
|
||||
# python -m unittest discover
|
||||
from main import make_graph, generate_new_readme, decode_readme
|
||||
except Exception as e:
|
||||
print("Error: missing 'main.py'\nTrying absolute import...")
|
||||
except ImportError as err:
|
||||
print(err)
|
||||
# sys.exit(1)
|
||||
|
||||
class TestMain(unittest.TestCase):
|
||||
|
||||
def test_make_graph(self):
|
||||
'''Tests the make_graph function'''
|
||||
def test(percent: float, block: str, result: str):
|
||||
self.assertEqual(make_graph(percent, block), result,
|
||||
f"{percent}% should return {result}")
|
||||
blocks = ["░▒▓█", "⚪⚫", "⓪①②③④⑤⑥⑦⑧⑨⑩"]
|
||||
percents = [0, 100, 49.999, 50, 25, 75, 3.14,
|
||||
9.901, 87.334, 87.333, 4.666, 4.667]
|
||||
graphGroup = [["░░░░░░░░░░░░░░░░░░░░░░░░░",
|
||||
@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 = ([
|
||||
"░░░░░░░░░░░░░░░░░░░░░░░░░",
|
||||
"█████████████████████████",
|
||||
"████████████▒░░░░░░░░░░░░",
|
||||
"████████████▓░░░░░░░░░░░░",
|
||||
@ -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):
|
||||
'''Tests generate_new_readme method from main.py'''
|
||||
dummy_readme = '''My Readme Start
|
||||
<!--START_SECTION:waka-->
|
||||
<!--END_SECTION:waka-->
|
||||
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)
|
||||
# self.dummy_readme = cleandoc("""
|
||||
# My Test Readme Start
|
||||
# <!--START_SECTION:waka-->
|
||||
# <!--END_SECTION:waka-->
|
||||
# My Test Readme End
|
||||
# """)
|
||||
|
||||
def test_decode_readme(self):
|
||||
'''Tests decode_readme method from main.py'''
|
||||
dummy_data = base64.b64encode(bytes('Some Data From GitHub', 'utf-8'))
|
||||
expected_result = 'Some Data From GitHub'
|
||||
actual_result = decode_readme(dummy_data)
|
||||
self.assertEqual(actual_result, expected_result)
|
||||
|
||||
class TestMain(unittest.TestCase):
|
||||
"""Testing Main Module"""
|
||||
|
||||
def test_make_graph(self) -> None:
|
||||
"""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 __package__ is None:
|
||||
import sys
|
||||
# because test_main.py is one level below main.py
|
||||
# python test/test_main.py
|
||||
sys.path.append(os.path.dirname(
|
||||
os.path.dirname(os.path.abspath(__file__))))
|
||||
from main import make_graph, generate_new_readme, decode_readme
|
||||
else:
|
||||
# Later on if WakaReadme is implemetaion as package
|
||||
# python -m tests/test_main
|
||||
from ..main import make_graph, generate_new_readme, decode_readme
|
||||
try:
|
||||
sys.path.insert(0, os.path.abspath(
|
||||
os.path.join(os.path.dirname(__file__), '..')
|
||||
))
|
||||
import main as prime
|
||||
# works when running as
|
||||
# python tests/test_main.py
|
||||
except ImportError as im_er:
|
||||
print(im_er)
|
||||
sys.exit(1)
|
||||
unittest.main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user