-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from walefy/test-initials
test: write some testes
- Loading branch information
Showing
13 changed files
with
489 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
omit = tests/*,db/database.py,__init__.py | ||
|
||
[report] | ||
show_missing = True | ||
show_missing = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typing import Literal | ||
|
||
|
||
class TestItem: | ||
passed: bool | ||
name: str | ||
|
||
def __init__(self, name: str, passed: Literal['passed', 'failed']): | ||
self.name = name | ||
self.passed = passed == 'passed' | ||
|
||
def __str__(self) -> str: | ||
return f' TestItem (name = {self.name}, passed = {self.passed})' | ||
|
||
|
||
def generate_report(): | ||
tests: list[TestItem] = [] | ||
|
||
with open('report.txt', 'r') as file: | ||
for line in file.readlines(): | ||
if line.startswith('test'): | ||
test = line.split(' ') | ||
test_name = test[0].split('::')[1] | ||
test_passed = test[1].lower() | ||
test = TestItem(test_name, test_passed) | ||
tests.append(test) | ||
|
||
if line.strip().endswith('[100%]'): | ||
break | ||
|
||
with open('report.md', 'w') as file: | ||
file.write('*name* | *passed*\n') | ||
file.write('--- | :---:\n') | ||
for test in tests: | ||
file.write(f'{test.name} | {"✅" if test.passed else "❌"}\n') | ||
|
||
|
||
generate_report() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import pytest | ||
|
||
from utils import get_nested_value | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_get_nested_value(): | ||
list_key = ('a', 'b', 'c') | ||
entry_dict = {'a': {'b': {'c': 'test'}}} | ||
|
||
assert get_nested_value(list_key, entry_dict) == 'test' | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_get_nested_value_with_nonexistent_key(): | ||
list_key = ('a', 'b', 'd') | ||
dict_test = {'a': {'b': {'c': 'cheguei'}}} | ||
|
||
with pytest.raises(ValueError): | ||
get_nested_value(list_key, dict_test) | ||
|
||
with pytest.raises(ValueError): | ||
get_nested_value(list_key, {'a': {'b': 'c'}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import tempfile | ||
from os import path | ||
|
||
import pytest | ||
|
||
from utils import Logger | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_logger_class(): | ||
temp_folder = tempfile.mkdtemp('logs') | ||
|
||
logger = Logger(folder=temp_folder) | ||
logger.log('test') | ||
|
||
with open(logger.path_to_file, 'r') as file: | ||
assert file.read() == 'test\n' | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_logger_class_with_nonexistent_folder(): | ||
temp_folder = tempfile.mkdtemp('test') | ||
|
||
logger = Logger(folder=temp_folder + '/logs') | ||
logger.log('test') | ||
|
||
with open(logger.path_to_file, 'r') as file: | ||
assert file.read() == 'test\n' | ||
|
||
assert path.exists(temp_folder + '/logs') |
Oops, something went wrong.