Added Tests (#23)

* Fixed Spelling mistake

* Added UnitTesting

* Removed pycache

* Updated Readme to include testing info

* Added gititnore

* Added Travis for Testing
This commit is contained in:
Ashraf Ali 2020-07-27 17:19:32 +01:00 committed by GitHub
parent 59c5854cd1
commit 55aaf85a2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 52 additions and 1 deletions

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

View File

@ -111,6 +111,17 @@ jobs:
USERNAME: <username> # optional, it will automatically use the username of the owner of the repository who's executing the workflow. USERNAME: <username> # optional, it will automatically use the username of the owner of 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 ## 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 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

View File

@ -70,7 +70,7 @@ def get_stats() -> str:
def decode_readme(data: str) -> str: def decode_readme(data: str) -> str:
'''Decode the contets of old readme''' '''Decode the contents of old readme'''
decoded_bytes = base64.b64decode(data) decoded_bytes = base64.b64decode(data)
return str(decoded_bytes, 'utf-8') return str(decoded_bytes, 'utf-8')

0
tests/__init__.py Normal file
View File

31
tests/test_main.py Normal file
View File

@ -0,0 +1,31 @@
'''
Tests for the main.py
'''
from main import make_graph
import unittest
class TestMain(unittest.TestCase):
def test_make_graph(self):
'''Tests the make_graph function'''
self.assertEqual(make_graph(0), "░░░░░░░░░░░░░░░░░░░░░░░░░",
"0% should return ░░░░░░░░░░░░░░░░░░░░░░░░░")
self.assertEqual(make_graph(100), "█████████████████████████",
"100% should return █████████████████████████")
self.assertEqual(make_graph(50), "████████████░░░░░░░░░░░░░",
"50% should return ████████████░░░░░░░░░░░░░")
self.assertEqual(make_graph(25), "██████░░░░░░░░░░░░░░░░░░░",
"25% should return ██████░░░░░░░░░░░░░░░░░░░")
self.assertEqual(make_graph(75), "██████████████████░░░░░░░",
"75% should return ██████████████████░░░░░░░")
self.assertEqual(make_graph(3.14), "░░░░░░░░░░░░░░░░░░░░░░░░░",
"3.14% should return ░░░░░░░░░░░░░░░░░░░░░░░░░")
self.assertEqual(make_graph(9.901), "██░░░░░░░░░░░░░░░░░░░░░░░",
"9.901% should return ██░░░░░░░░░░░░░░░░░░░░░░░")
self.assertEqual(make_graph(87.5), "██████████████████████░░░",
"87.5% should return ██████████████████████░░░")
if __name__ == '__main__':
unittest.main()