Skip to content

Commit 1154183

Browse files
committed
added pytest
1 parent 50afd3b commit 1154183

File tree

6 files changed

+59
-7
lines changed

6 files changed

+59
-7
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@ jobs:
1313
uses: obervinov/_templates/.github/workflows/[email protected]
1414
flake8:
1515
uses: obervinov/_templates/.github/workflows/[email protected]
16+
pytest:
17+
uses: obervinov/_templates/.github/workflows/pytest.yml@added-trivy
1618
package-version:
1719
uses: obervinov/_templates/.github/workflows/[email protected]

messages/messages.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(
2727
"""
2828
self.config_path = config_path
2929
with open(self.config_path, 'r', encoding='UTF-8') as config_json:
30-
self.data = json.loads(config_json)
30+
self.data = json.load(config_json)
3131
config_json.close()
3232

3333

@@ -79,10 +79,8 @@ def render_progressbar(
7979
:default current_count: 0
8080
"""
8181
procentage = math.ceil((current_count / total_count) * 100)
82-
progressbar_response = (
83-
'\r[',
84-
'\u25FE' * int(procentage),
85-
'\u25AB' * int((100 - procentage)),
86-
f']{str(procentage)}%'
82+
progressbar = (
83+
f"\r[{emoji.emojize(':black_medium-small_square:') * int(procentage)}"
84+
f"{emoji.emojize(':white_medium_square:') * int((100 - procentage))}]{str(procentage)}%"
8785
)
88-
return progressbar_response
86+
return progressbar

tests/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
This is just a special file that tells pip that your main module is in this folder
3+
No need to add anything here. Feel free to delete this line when you make your own package
4+
Leave it empty
5+
"""

tests/configs/messages.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"templates":{"test_message": {"text": "Hi, <b>{0}</b>! {1}\nAccess for your account - allowed {2}", "args": ["username", ":raised_hand:", ":unlocked:"]}}}

tests/test_render_progressbar.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""
2+
This test is needed to test the rendering of progressbar with emojis.
3+
"""
4+
from messages.messages import Messages
5+
6+
messages = Messages('tests/configs/messages.json')
7+
8+
TARGET_RESULT = (
9+
"\r[◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾"
10+
"◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️"
11+
"◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️◻️]19%"
12+
)
13+
14+
def test_render_progressbar():
15+
"""
16+
Functions for approving the result between TARGET_RESULT and the response from the module.
17+
"""
18+
response = messages.render_progressbar(100, 19)
19+
assert response == TARGET_RESULT
20+
21+
22+
if __name__ == "__main__":
23+
test_render_progressbar()
24+
print("Rendering progressbar - passed")

tests/test_render_template.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""
2+
This test is needed to test the rendering of messages with emojis.
3+
"""
4+
from messages.messages import Messages
5+
6+
messages = Messages('tests/configs/messages.json')
7+
8+
TARGET_RESULT = (
9+
"Hi, <b>pytest</b>! ✋\n"
10+
"Access for your account - allowed 🔓"
11+
)
12+
13+
def test_render_template():
14+
"""
15+
Functions for approving the result between TARGET_RESULT and the response from the module.
16+
"""
17+
response = messages.render_template('test_message', username='pytest')
18+
assert response == TARGET_RESULT
19+
20+
if __name__ == "__main__":
21+
test_render_template()
22+
print("Rendering template - passed")

0 commit comments

Comments
 (0)