51 Commits

Author SHA1 Message Date
Athul Cyriac Ajay
1f2d0f1334 Merge pull request #39 from malkam03/hotfix-default-branch
Support default branches with names other than master
2020-09-14 21:22:17 +05:30
Athul Cyriac Ajay
08467f1de5 Merge pull request #38 from malkam03/dev
Add support for parametrized blocks
2020-09-14 21:18:26 +05:30
Malcolm Davis Steele
2e05fe3bf2 Support default branches with names other than master. Fixes athul/waka-readme#34. 2020-09-13 03:56:42 -06:00
Malcolm Davis
c5aaa5ad5d Add support for parametrized blocks
- Modify action to support input of block string
- Modify make graph function to support parametrized blocks
- Add tests for parametrized blocks
- Update README with new issue
- Fix some format errors and typos
2020-09-13 03:16:27 -06:00
Athul Cyriac Ajay
ec79c6dacb Merge pull request #37 from gautamkrishnar/patch-2
Ignoring zero graph, fixes: #35
2020-09-09 00:15:00 +05:30
Gautam krishna R
edf6e1715e using single quotes 2020-09-08 13:51:27 +05:30
Gautam krishna R
8605a9760e Ignoring zero graph, fixes: #35 2020-09-08 12:16:10 +05:30
Athul Cyriac Ajay
27fc6f7586 Merge pull request #32 from saltbo/develop
feat: support custom repository
2020-08-23 14:39:15 +05:30
saltbo
8a3ea94195 feat: support custom repository 2020-08-23 14:04:56 +08:00
Athul Cyriac Ajay
aaff45b1d4 Merge pull request #30 from ouuan/accurate-graph
feat: more accurate graph
2020-08-16 15:50:54 +05:30
Athul Cyriac Ajay
b37bede506 Merge pull request #29 from RyuaNerin/for-text-centering
Insert space at the end of each line for text centering
2020-08-16 15:32:15 +05:30
Yufan You
215367a2ad refactor: remove duplicate codes in the tests 2020-08-16 16:08:06 +08:00
Yufan You
d827cb172d feat: more accurate graph 2020-08-16 15:57:38 +08:00
RyuaNerin
73c1050f48 Insert space at the end of each line for text centering 2020-08-16 16:39:45 +09:00
Athul Cyriac Ajay
d0c740a1a1 Why only the language stats and not other data from the API? 2020-08-03 14:24:55 +05:30
Athul Cyriac Ajay
6f4f9c9933 Create FUNDING.yml 2020-08-03 14:07:33 +05:30
Athul Cyriac Ajay
442c0dae4d Add flag to specify a commit message of user's choice (#25)
* Make commit message configurable
Fixes #24

* Update Readme for Commit_message flag

Make commit message configurable #24
2020-08-02 17:50:23 +05:30
Athul Cyriac Ajay
fa74a6bca2 Add Travis Build Status 2020-07-27 22:07:39 +05:30
Ashraf Ali
55aaf85a2f Added Tests (#23)
* Fixed Spelling mistake

* Added UnitTesting

* Removed pycache

* Updated Readme to include testing info

* Added gititnore

* Added Travis for Testing
2020-07-27 21:49:32 +05:30
Athul Cyriac Ajay
59c5854cd1 Merge pull request #22 from MetLee/master
Fixed a typo
2020-07-23 22:14:26 +05:30
MetLee
21e5b9c804 Fixed a typo 2020-07-24 00:39:34 +08:00
Stanley
67a3568c75 added more detailed readme (#21)
* added more detailed readme

* Update README.md

Co-authored-by: Athul Cyriac Ajay <athul8720@gmail.com>

Co-authored-by: Athul Cyriac Ajay <athul8720@gmail.com>
2020-07-23 10:16:03 +05:30
Athul Cyriac Ajay
580f6d4639 Add try-except if an empty list occurs and removed the exit function (#19)
* Add try-except if an empty list occurs and removed the exit fn

Closes #18

* Updated Try-except to print to readme
2020-07-22 22:40:00 +05:30
Jovial Joe Jayarson
fd7a6214c1 Fixes #15: Long Program Name (#16)
* fix: fixes long language issue

* fix: removed reduant line
2020-07-22 15:39:59 +05:30
athul
c487876563 Fixed Error Handler bug 2020-07-21 00:21:44 +05:30
Athul Cyriac Ajay
744bf5ae56 Add a try/except block for catching errors (#14)
* Add a try/except block for catching errors

* Refactored the try/except to catch the GitHub error
2020-07-20 11:18:23 +05:30
athul
0edb69508c Fixed the SHOW_TITLE bug 2020-07-18 21:38:48 +05:30
Athul Cyriac Ajay
5f04a7c728 Merge pull request #12 from athul/flag
Add a Flag for Weeks
2020-07-18 21:34:37 +05:30
athul
610c67b096 Fixed old code problem and add return types 2020-07-18 19:11:04 +05:30
Jovial Joe Jayarson
15c5dbcc49 fix: adds padding to float for neater look (#11) 2020-07-18 12:39:17 +05:30
Athul Cyriac Ajay
96f680b05f Merge pull request #8 from joe733/master
fix: Changed to week streak instead for week of the year
2020-07-18 09:40:51 +05:30
Jovial Joe Jayarson
49b64c7be8 fix: fixed month / year roll-over issue 2020-07-18 09:31:13 +05:30
Jovial Joe Jayarson
0cf0773d1c Merge branch 'master' of https://github.com/joe733/waka-readme 2020-07-18 09:15:59 +05:30
Jovial Joe Jayarson
d0c5208665 fix: added space before % 2020-07-18 09:15:18 +05:30
Jovial Joe Jayarson
b1a69733c8 Merge branch 'master' of https://github.com/joe733/waka-readme 2020-07-18 08:49:59 +05:30
Jovial Joe Jayarson
02b84ff4ca fix: week streak changed to last 7 days from today 2020-07-18 08:49:37 +05:30
Athul Cyriac Ajay
91dec6e35d Merge pull request #6 from joe733/master
feat: Added week #number to dev metrics
2020-07-17 14:02:00 +05:30
Jovial Joe Jayarson
1b5b63412c Merge branch 'master' of https://github.com/joe733/waka-readme 2020-07-17 09:07:16 +05:30
Jovial Joe Jayarson
8d201a6313 feat: Added week span and % 2020-07-17 09:06:56 +05:30
Jovial Joe Jayarson
c6628c271b feat: Added week span 2020-07-17 08:58:18 +05:30
joe733
4d999ae477 fix: one more linting :/ 2020-07-15 12:18:47 +05:30
joe733
b9ef50f20a fix: Redefining name 'stats' from outer scope ln62 2020-07-15 12:18:05 +05:30
joe733
0dc06a87bd fix & feat: added week numbers; applied linting; 2020-07-15 12:12:23 +05:30
Athul Cyriac Ajay
7563a7a8ed Update README.md 2020-07-14 01:17:24 +05:30
Athul Cyriac Ajay
b5c7fff8c3 Added Better Instructions 2020-07-14 01:04:58 +05:30
Athul Cyriac Ajay
d11a3bdb64 Merge pull request #5 from joe733/master
fix: Added WakaTime info; Some tweaks
2020-07-12 22:55:35 +05:30
Jovial Joe Jayarson
96d2a79378 fix: made requested changes. 2020-07-12 22:52:45 +05:30
Jovial Joe Jayarson
7d189fc98d fix: changed numbers to bullets; 2020-07-12 22:39:47 +05:30
Jovial Joe Jayarson
e3100077b1 Merge pull request #1 from joe733/sourcery/master
Sourcery refactored master branch
2020-07-12 22:31:26 +05:30
Jovial Joe Jayarson
79d91bc512 fix: Added WakaTime info; Some tweaks 2020-07-12 22:28:52 +05:30
Sourcery AI
4e3dc0a20a 'Refactored by Sourcery' 2020-07-12 16:25:58 +00:00
8 changed files with 304 additions and 65 deletions

4
.github/FUNDING.yml vendored Normal file
View File

@@ -0,0 +1,4 @@
# These are supported funding model platforms
ko_fi: athulcyriac
custom: https://www.buymeacoffee.com/JeVlc7T

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
#generated when running the tests
__pycache__/

7
.travis.yml Normal file
View File

@@ -0,0 +1,7 @@
language: python
python:
- "3.7"
install:
- pip install -r requirements.txt
script:
- python -m unittest discover

148
README.md
View File

@@ -1,40 +1,66 @@
# Dev Metrics in Readme
# Dev Metrics in Readme [![Build Status](https://travis-ci.com/athul/waka-readme.svg?branch=master)](https://travis-ci.com/athul/waka-readme)
[Wakatime](https://wakatime.com) Weekly Metrics on your Profile Readme:
![Project Preview](https://user-images.githubusercontent.com/8397274/87243943-e6b45c00-c457-11ea-94c9-2aa0bf241be8.png)
---
[WakaTime](https://wakatime.com) Weekly Metrics on your Profile Readme:
## Prep Work
1. You need to update the markdown file(.md) with 2 comments. You can refer [here](#update-your-readme) for updating it.
2. You'll need a WakaTime API Key. You can get that from your WakaTime Account Settings
- You can refer [here](#new-to-wakatime), if you're new to WakaTime
3. **Optional** You'll need a GitHub API Token with `repo` scope from [here](https://github.com/settings/tokens) if you're running the action not in your Profile Repository
- You can use [this](#other-repository-not-profile) example to work it out
4. You need to save the WakaTime API Key (and the GitHub API Token, if you need it) in the repository secrets. You can find that in the Settings of your Repository.Be sure to save those as the following.
- WakaTime-api-key as `WAKATIME_API_KEY = <your wakatime API Key>`and
- The GitHub Access Token as `GH_TOKEN=<your github access token>`
5. You can follow either of the Two Examples according to your needs to get started with.
> I strongly suggest you to run the Action in your Profile Repo since you won't be needing a GitHub Access Token
This Action will run everyday at 00.00 UTC
## Update your Readme
Add a comment to your README like the follows
Add a comment to your `README.md` like this:
```md
<!--START_SECTION:waka-->
<!--END_SECTION:waka-->
```
The lines will be our entrypoints for our metrics.
These lines will be our entry-points for the dev metrics.
## Using it
## New to WakaTime
- Get your Wakatime API Key from your [Account Settings in Wakatime](https://wakatime.com/settings/account) and save it as `WAKATIME_API_KEY = <your wakatime API Key>` in your Repository Secrets
WakaTime gives you an idea of the time you really spent on coding. This helps you boost your productivity and competitive edge.
That's it. The Action runs everyday at 00.00 UTC
- Head over to <https://wakatime.com> and create an account.
- Get your WakaTime API Key from your [Account Settings in WakaTime](https://wakatime.com/settings/account).
- Install the [WakaTime plugin](https://wakatime.com/plugins) in your favourite editor / IDE.
- Paste in your API key to start the analysis.
### Profile Repository
If you're executing the workflow on your Profile Repository (`<username>/<username>`)
_If you're executing the workflow on your Profile Repository (`<username>/<username>`)_
**You wouldn't need an GitHub Access Token since GitHub Actions already makes one for you.**
> You wouldn't need an GitHub Access Token since GitHub Actions already makes one for you.
Here is a sample workflow file for you to get started,
Please follow the steps below:
1. Go to your `<username>/<username>/actions`, hit `New workflow`, `set up a workflow yourself`, delete all the default content github made for you.
2. Copy the following code and paste it to your new workflow you created at step 1:
```yml
name: Waka Readme
on:
workflow_dispatch:
schedule:
# Runs at 12am UTC
- cron: '0 0 * * *'
- cron: "0 0 * * *"
jobs:
update-readme:
@@ -46,13 +72,25 @@ jobs:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
```
### Different Repository than Profile Repository
3. Go to your repo secrets by hitting `Settings => Secrets` tab in your profile repo. You can also enter the url https://github.com/USERNAME/USERNAME/settings/secrets . Please replace the `USERNAME` with your own username.
4. Create a new `Secret`. `Name`: `WAKATIME_API_KEY`, `Value`: Paste the Wakatime API key here. If you don't know what is the key, please go to [Account Settings in WakaTime](https://wakatime.com/settings/account) to find your API Key there.
5. Add a comment to your `README.md` like this:
if you're executing the workflow on another repo other than `<username>/<username>`
```md
<!--START_SECTION:waka-->
<!--END_SECTION:waka-->
```
- You'll need to get a GitHub Access Token with a `repo` scope and save it in the Repo Secrets `GH_TOKEN = <Your GitHub Access Token>`
6. Go to Workflows menu (mentioned in step 1), click `Waka Readme`, click `Run workflow`.
7. Go to your profile page. you will be able to see it.
Here is Sample Worflow File for running it
### Other Repository (not Profile)
_If you're executing the workflow on another repo other than `<username>/<username>`_
You'll need to get a [GitHub Access Token](https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token) with a `repo` scope and save it in the Repo Secrets `GH_TOKEN = <Your GitHub Access Token>`
Here is Sample Workflow File for running it:
```yml
name: Waka Readme
@@ -60,7 +98,7 @@ name: Waka Readme
on:
schedule:
# Runs at 12am UTC
- cron: '0 0 * * *'
- cron: "0 0 * * *"
jobs:
update-readme:
@@ -70,6 +108,80 @@ jobs:
- uses: athul/waka-readme@master
with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
GH_TOKEN: ${{ secrets.GH_TOKEN}}
USERNAME: <username> # optional, it will automaticially use the username that executing the workflow
GH_TOKEN: ${{ secrets.GH_TOKEN }}
REPOSITORY: <username/username> # optional, By default, it will automatically use the repository who's executing the workflow.
```
## Tests
### Running Tests
To run tests simply execute the following in the directory containing main.py:
```python
python -m unittest discover
```
### Contributing Tests
These tests uses the python Unit testing framework, [unittest](https://docs.python.org/3/library/unittest.html)
Since this project is contained all within one file, 'main.py'. You can simply add a function to the TestMain class in tests/test_main.py, similar to the test_graph function.
## Extras
1. If you want to add the week in the Header of your stats, you can add `HEAD_FLAG: true` in your workflow file like this
```yml
- uses: athul/waka-readme@master
with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
SHOW_TITLE: true
```
`SHOW_TITLE` flag can be set to true if you want to display the week number and days in the readme, by default it will be false. Here is an example output with `SHOW_TITLE` set to true.
```text
Week: 10 July, 2020 - 17 July, 2020
Python 8 hrs 52 mins ███████████████████░░░░░░ 75.87 %
Go 1 hr 15 mins ██░░░░░░░░░░░░░░░░░░░░░░░ 10.79 %
Markdown 52 mins █░░░░░░░░░░░░░░░░░░░░░░░░ 07.43 %
Docker 16 mins ░░░░░░░░░░░░░░░░░░░░░░░░░ 02.32 %
YAML 7 mins ░░░░░░░░░░░░░░░░░░░░░░░░░ 01.07 %
```
2. You can specify a commit message to override the default _"Updated the Graph with new Metrics"_. Here is how you do it
```yml
- uses: athul/waka-readme@master
with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
COMMIT_MESSAGE: Updated the Readme
```
If no commit message is specified in the `yml` file, it defaults to _"Updated the Graph with new Metrics"_
3. You can change the block characters to match with the style of your readme. By default the one show in the graphs before is used. Here is how you do it
```yml
- uses: athul/waka-readme@master
with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
BLOCKS: ⣀⣄⣤⣦⣶⣷⣿
```
This will change the graphs to something like this:
```text
Python 8 hrs 52 mins ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣀⣀⣀⣀⣀⣀ 75.87 %
Go 1 hr 15 mins ⣿⣿⣦⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀ 10.79 %
Markdown 52 mins ⣿⣿⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀ 07.43 %
Docker 16 mins ⣤⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀ 02.32 %
YAML 7 mins ⣄⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀ 01.07 %
```
## Why only the language stats and not other data from the API?
I am a fan of minimal designs and the profile readme is a great way to show off your skills and interests. The WakaTime API, gets us a **lot of data** about a person's **coding activity including the editors and Operating Systems you used and the projects you worked on**. Some of these projects maybe secretive and should not be shown out to the public. Using up more data via the Wakatime API will clutter the profile readme and hinder your chances on displaying what you provide **value to the community** like the pinned Repositories. I believe that **Coding Stats is nerdiest of all** since you can tell the community that you are _**exercising these languages or learning a new language**_, this will also show that you spend some amount of time to learn and exercise your development skills. That's what matters in the end :heart:

View File

@@ -1,26 +1,41 @@
name: 'Waka - Readme'
name: "Waka - Readme"
author: Athil Cyriac Ajay
description: 'Add a Wakatime Coding Activity graph in your Readme'
description: "Add a Wakatime Coding Activity graph in your Readme"
inputs:
GH_TOKEN:
description: 'GitHub access token with Repo scope'
description: "GitHub access token with Repo scope"
required: true
default: ${{ github.token }}
WAKATIME_API_KEY:
description: 'Your Wakatime API Key'
description: "Your Wakatime API Key"
required: true
USERNAME:
description: 'Your GitHub username'
default: ${{ github.repository_owner }}
REPOSITORY:
description: "Your GitHub repository"
default: ${{ github.repository }}
required: false
SHOW_TITLE:
description: "Displays the week number and days in Readme as title"
default: false
required: false
COMMIT_MESSAGE:
description: "Add a commit message of your choice"
default: "Updated the Graph with new Metrics"
required: false
BLOCKS:
description: "Add the progress blocks of your choice"
default: "░▒▓█"
required: false
runs:
using: 'docker'
image: 'Dockerfile'
using: "docker"
image: "Dockerfile"
branding:
icon: 'info'
color: 'blue'
icon: "info"
color: "blue"

121
main.py
View File

@@ -1,58 +1,107 @@
import base64
import requests
'''
WakaTime progress visualizer
'''
import re
import os
from github import Github
import base64
import sys
import datetime
import requests
from github import Github, GithubException
START_COMMENT = '<!--START_SECTION:waka-->'
END_COMMENT = '<!--END_SECTION:waka-->'
listReg = f'{START_COMMENT}[\\s\\S]+{END_COMMENT}'
listReg = f"{START_COMMENT}[\\s\\S]+{END_COMMENT}"
user = os.getenv("INPUT_USERNAME")
waka_key = os.getenv("INPUT_WAKATIME_API_KEY")
ghtoken = os.getenv("INPUT_GH_TOKEN")
repository = os.getenv('INPUT_REPOSITORY')
waka_key = os.getenv('INPUT_WAKATIME_API_KEY')
ghtoken = os.getenv('INPUT_GH_TOKEN')
show_title = os.getenv("INPUT_SHOW_TITLE")
commit_message = os.getenv("INPUT_COMMIT_MESSAGE")
blocks = os.getenv("INPUT_BLOCKS")
def makeGraph(percent: float):
done_block = ""
empty_block = ""
pc_rnd = round(percent)
return (f'{done_block*int(pc_rnd/4)}{empty_block*int( 25-int(pc_rnd/4))}')
def this_week() -> str:
'''Returns a week streak'''
week_end = datetime.datetime.today() - datetime.timedelta(days=1)
week_start = week_end - datetime.timedelta(days=7)
print("Week header created")
return f"Week: {week_start.strftime('%d %B, %Y')} - {week_end.strftime('%d %B, %Y')}"
def getStats():
def make_graph(percent: float, blocks: str) -> str:
'''Make progress graph from API graph'''
graph = blocks[len(blocks)-1] * int(percent / 4 + 1 / 6)
remainder_block = int((percent + (len(blocks)-2) /
(len(blocks)-1)) % 4 * (len(blocks)-1) / len(blocks))
if remainder_block > 0:
graph += blocks[remainder_block]
graph += blocks[0] * (25 - len(graph))
return graph
def get_stats() -> str:
'''Gets API data and returns markdown progress'''
data = requests.get(
f"https://wakatime.com/api/v1/users/current/stats/last_7_days?api_key={waka_key}").json()
lang_data = data['data']['languages']
try:
lang_data = data['data']['languages']
except KeyError:
print("Please Add your WakaTime API Key to the Repository Secrets")
sys.exit(1)
data_list = []
for l in lang_data[:5]:
ln = len(l['name'])
ln_text = len(l['text'])
op = f"{l['name']}{' '*(12-ln)}{l['text']}{' '*(20-ln_text)}{makeGraph(l['percent'])} {l['percent']}"
data_list.append(op)
data = " \n".join(data_list)
return ("```text\n"+data+"\n```")
try:
pad = len(max([l['name'] for l in lang_data[:5]], key=len))
except ValueError:
print("The Data seems to be empty. Please wait for a day for the data to be filled in.")
return '```text\nNo Activity tracked this Week\n```'
for lang in lang_data[:5]:
if lang['hours'] == 0 and lang['minutes'] == 0:
continue
lth = len(lang['name'])
ln_text = len(lang['text'])
# following line provides a neat finish
fmt_percent = format(lang['percent'], '0.2f').zfill(5)
data_list.append(
f"{lang['name']}{' '*(pad + 3 - lth)}{lang['text']}{' '*(16 - ln_text)}{make_graph(lang['percent'], blocks)} {fmt_percent} % ")
print("Graph Generated")
data = '\n'.join(data_list)
if show_title == 'true':
print("Stats with Weeks in Title Generated")
return '```text\n'+this_week()+'\n\n'+data+'\n```'
else:
print("Usual Stats Generated")
return '```text\n'+data+'\n```'
def decodeReadme(data: str):
decodedBytes = base64.b64decode(data)
decodedStr = str(decodedBytes, "utf-8")
return decodedStr
def decode_readme(data: str) -> str:
'''Decode the contents of old readme'''
decoded_bytes = base64.b64decode(data)
return str(decoded_bytes, 'utf-8')
def generatenewReadme(stats: str, readme: str):
statsinReadme = f"{START_COMMENT}\n{stats}\n{END_COMMENT}"
newReadme = re.sub(listReg, statsinReadme, readme)
return newReadme
def generate_new_readme(stats: str, readme: str) -> str:
'''Generate a new Readme.md'''
stats_in_readme = f"{START_COMMENT}\n{stats}\n{END_COMMENT}"
return re.sub(listReg, stats_in_readme, readme)
if __name__ == '__main__':
g = Github(ghtoken)
repo = g.get_repo(f"{user}/{user}")
try:
repo = g.get_repo(repository)
except GithubException:
print("Authentication Error. Try saving a GitHub Token in your Repo Secrets or Use the GitHub Actions Token, which is automatically used by the action.")
sys.exit(1)
if len(blocks) < 1:
print("Invalid blocks string. Please provide provide a string with 2 or more characters. Eg. '░▒▓█'")
sys.exit(1)
contents = repo.get_readme()
stats = getStats()
rdmd = decodeReadme(contents.content)
newreadme = generatenewReadme(stats=stats, readme=rdmd)
if newreadme != rdmd:
repo.update_file(path=contents.path, message="Updated with Dev Metrics",
content=newreadme, sha=contents.sha, branch="master")
waka_stats = get_stats()
rdmd = decode_readme(contents.content)
new_readme = generate_new_readme(stats=waka_stats, readme=rdmd)
if new_readme != rdmd:
repo.update_file(path=contents.path, message=commit_message,
content=new_readme, sha=contents.sha)

0
tests/__init__.py Normal file
View File

50
tests/test_main.py Normal file
View File

@@ -0,0 +1,50 @@
'''
Tests for the main.py
'''
from main import make_graph
import unittest
import os
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, 50, 50.001, 25, 75, 3.14,
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)
if __name__ == '__main__':
unittest.main()