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:
parent
59c5854cd1
commit
55aaf85a2f
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
#generated when running the tests
|
||||
__pycache__/
|
7
.travis.yml
Normal file
7
.travis.yml
Normal file
@ -0,0 +1,7 @@
|
||||
language: python
|
||||
python:
|
||||
- "3.7"
|
||||
install:
|
||||
- pip install -r requirements.txt
|
||||
script:
|
||||
- python -m unittest discover
|
11
README.md
11
README.md
@ -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.
|
||||
```
|
||||
|
||||
## 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
|
||||
|
2
main.py
2
main.py
@ -70,7 +70,7 @@ def get_stats() -> str:
|
||||
|
||||
|
||||
def decode_readme(data: str) -> str:
|
||||
'''Decode the contets of old readme'''
|
||||
'''Decode the contents of old readme'''
|
||||
decoded_bytes = base64.b64decode(data)
|
||||
return str(decoded_bytes, 'utf-8')
|
||||
|
||||
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
31
tests/test_main.py
Normal file
31
tests/test_main.py
Normal 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()
|
Loading…
x
Reference in New Issue
Block a user