Skip to content

Commit 90ef596

Browse files
committed
type hints
1 parent f220659 commit 90ef596

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

‎pyproject.toml‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,8 @@ extend-ignore = ["E203", "W503"]
5757
attackmate = { path = "../attackmate", editable = true }
5858

5959
[[tool.mypy.overrides]]
60-
modules = [
61-
"test.*",
62-
"test_commands"
63-
]
64-
# Allows to use @pytest.fixture without mypy complaining
60+
# Use a wildcard to cover the entire test directory
61+
module = "test.*"
6562
disallow_untyped_decorators = false
66-
# Allows to skip "-> None" on test functions
6763
disallow_untyped_defs = false
68-
# Allows to skip type hints for arguments in fixtures
6964
check_untyped_defs = false

‎test/units/test_main.py‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# mypy: ignore-errors
12
import pytest
23
from httpx import AsyncClient, ASGITransport
34
from unittest.mock import patch
@@ -6,14 +7,18 @@
67

78
@pytest.fixture
89
def patch_dependencies():
9-
with patch('attackmate_api_server.main.get_user_hash') as mock_get_user_hash, \
10-
patch('attackmate_api_server.main.verify_password') as mock_verify_password, \
11-
patch('attackmate_api_server.main.create_access_token', return_value='mock_access_token') \
12-
as mock_create_access_token, \
13-
patch('attackmate_api_server.routers.commands.get_persistent_instance') \
14-
as mock_get_persistent_instance, \
15-
patch('attackmate_api_server.routers.commands.varstore_to_state_model',
16-
return_value={'state': 'data'}) as mock_varstore_to_state:
10+
with patch(
11+
'attackmate_api_server.main.get_user_hash'
12+
) as mock_get_user_hash, patch(
13+
'attackmate_api_server.main.verify_password'
14+
) as mock_verify_password, patch(
15+
'attackmate_api_server.main.create_access_token', return_value='mock_access_token'
16+
) as mock_create_access_token, patch(
17+
'attackmate_api_server.routers.commands.get_persistent_instance'
18+
) as mock_get_persistent_instance, patch(
19+
'attackmate_api_server.routers.commands.varstore_to_state_model',
20+
return_value={'state': 'data'}
21+
) as mock_varstore_to_state:
1722
yield {
1823
'get_user_hash': mock_get_user_hash,
1924
'verify_password': mock_verify_password,
@@ -24,14 +29,14 @@ def patch_dependencies():
2429

2530

2631
@pytest.mark.asyncio
27-
async def test_root_endpoint():
32+
async def test_root_endpoint() -> None:
2833
async with AsyncClient(transport=ASGITransport(app=app), base_url='http://test') as client:
2934
response = await client.get('/')
3035
assert response.status_code == 200
3136

3237

3338
@pytest.mark.asyncio
34-
async def test_login_success(patch_dependencies):
39+
async def test_login_success(patch_dependencies) -> None:
3540
patch_dependencies['get_user_hash'].return_value = 'hashed_password'
3641
patch_dependencies['verify_password'].return_value = True
3742

@@ -46,7 +51,7 @@ async def test_login_success(patch_dependencies):
4651

4752

4853
@pytest.mark.asyncio
49-
async def test_login_failure_user_not_found(patch_dependencies):
54+
async def test_login_failure_user_not_found(patch_dependencies) -> None:
5055
patch_dependencies['get_user_hash'].return_value = None
5156

5257
async with AsyncClient(transport=ASGITransport(app=app), base_url='http://test') as client:
@@ -62,7 +67,7 @@ async def test_login_failure_user_not_found(patch_dependencies):
6267

6368

6469
@pytest.mark.asyncio
65-
async def test_login_failure_invalid_password(patch_dependencies):
70+
async def test_login_failure_invalid_password(patch_dependencies) -> None:
6671
patch_dependencies['get_user_hash'].return_value = 'hashed_password'
6772
patch_dependencies['verify_password'].return_value = False
6873

0 commit comments

Comments
 (0)