Skip to content

Commit faa0947

Browse files
committed
🎃Add some tests for modules
1 parent d4378d2 commit faa0947

File tree

11 files changed

+97
-5
lines changed

11 files changed

+97
-5
lines changed

‎main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from loguru import logger
44

5-
from unella.modules.audit_generator import AuditGenerator
5+
from unella.audit_generator import AuditGenerator
66

77
PROJECT_TO_AUDIT = "/home/tevak/dev/jwt_tool"
88

‎pyproject.toml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,15 @@ ignore = [
6161
"S602", # subprocess.run with shell=True
6262
]
6363
line-length = 120
64-
src = ["unella", ]
64+
src = ["unella", ]
65+
66+
67+
[tool.coverage.run]
68+
omit = ["*/tests/*"]
69+
70+
[tool.coverage.report]
71+
exclude_lines = [
72+
'pragma: no cover',
73+
'if TYPE_CHECKING:',
74+
'raise NotImplementedError.*',
75+
]

‎tests/conftest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import pathlib
2+
3+
current_dir = pathlib.Path(__file__).parent
4+
ROOT_DIR = current_dir.parent

‎tests/modules/__init__.py

Whitespace-only changes.

‎tests/modules/test_mypy.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from tests.conftest import ROOT_DIR
2+
from unella.modules.mypy.main import MypyReport
3+
4+
5+
def test_mypy_report():
6+
report = MypyReport(ROOT_DIR)
7+
report.perform_analysis()
8+
results = report.get_results()
9+
10+
assert len(results["most_messages"]) >= 1
11+
assert len(results["most_messages_categories"]) >= 1
12+
assert len(results["files_most_messages"]) >= 1
13+
14+
# check the format of the first message for each
15+
for result in [results["most_messages"], results["most_messages_categories"], results["files_most_messages"]]:
16+
msg, occurence = result[0]
17+
assert isinstance(msg, str)
18+
assert isinstance(occurence, int)

‎tests/modules/test_ruff.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from tests.conftest import ROOT_DIR
2+
from unella.modules.ruff.main import RuffReport
3+
4+
5+
def test_ruff_report():
6+
report = RuffReport(ROOT_DIR)
7+
report.perform_analysis()
8+
first_entry, *entries = report.get_results()
9+
10+
assert isinstance(first_entry["code"], str)
11+
assert isinstance(first_entry["count"], int)
12+
assert isinstance(first_entry["fixable"], bool)
13+
assert isinstance(first_entry["message"], str)

‎tests/modules/test_structure.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from tests.conftest import ROOT_DIR
2+
from unella.modules.structure.main import StructureReport
3+
4+
5+
def test_structure_report():
6+
report = StructureReport(ROOT_DIR)
7+
report.perform_analysis()
8+
results = report.get_results()
9+
10+
assert results["has_tests"] is True
11+
assert results["uses_pytest"] is True
12+
assert results["is_git_repository"] is True
13+
assert results["has_precommit_file"] is False
14+
assert results["structure"] is not None
15+
dependencies = results["dependencies"]
16+
assert dependencies["requirements.txt"] is True
17+
assert dependencies["pipenv"] is False
18+
assert dependencies["poetry"] is False
19+
assert dependencies["pip-tools"] is True
20+
assert dependencies["setuptools"] is False

‎tests/modules/test_vulture.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from tests.conftest import ROOT_DIR
2+
from unella.modules.vulture.main import VultureReport
3+
4+
5+
def test_vulture_report():
6+
report = VultureReport(ROOT_DIR)
7+
report.perform_analysis()
8+
first_entry, *entries = report.get_results()
9+
10+
assert isinstance(first_entry["confidence"], str)
11+
assert isinstance(first_entry["file_path"], str)
12+
assert isinstance(first_entry["line"], str)
13+
assert isinstance(first_entry["msg"], str)
File renamed without changes.

‎unella/modules/mypy/main.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,19 @@
22
import subprocess
33
from collections import Counter
44
from dataclasses import dataclass
5+
from typing import TypedDict
56

67
from unella.modules.generic import Report
78

89
MYPY_LINE_REGEX = r"(?P<file_path>.*):\d+: (?P<msg_type>error|warning):(?P<msg>.*)\[(?P<msg_category>[\w_-]+)\]"
910

1011

12+
class ResultDict(TypedDict):
13+
files_most_messages: list | None
14+
most_messages: list | None
15+
most_messages_categories: list | None
16+
17+
1118
@dataclass
1219
class MypyReport(Report):
1320
_cmd_output: str | None = None
@@ -46,7 +53,7 @@ def perform_analysis(self) -> None:
4653

4754
self._cmd_output = output
4855

49-
def get_results(self) -> dict:
56+
def get_results(self) -> ResultDict:
5057
return {
5158
"files_most_messages": self._file_most_messages,
5259
"most_messages": self._most_messages,

0 commit comments

Comments
 (0)