Skip to content

Commit f3f07fd

Browse files
Fix mypy and pylint issues in tests (#108)
1 parent 3234bf8 commit f3f07fd

File tree

7 files changed

+115
-97
lines changed

7 files changed

+115
-97
lines changed

tests/batch/test_batch_job.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33

44
import pytest
55

6-
from hume import BatchJob, BatchJobDetails, BatchJobState, BatchJobStatus
6+
from hume import BatchJob, BatchJobDetails, BatchJobState, BatchJobStatus, HumeClientException
77
from hume.models import ModelType
88
from hume.models.config import FaceConfig
9-
from hume import HumeClientException
109

1110

12-
@pytest.fixture(scope="function")
13-
def batch_client() -> Mock:
11+
@pytest.fixture(name="batch_client", scope="function")
12+
def batch_client_fixture() -> Mock:
1413
mock_client = Mock()
1514
job_details = BatchJobDetails(
1615
configs={
@@ -32,34 +31,34 @@ def batch_client() -> Mock:
3231
@pytest.mark.batch
3332
class TestBatchJob:
3433

35-
def test_job_id(self, batch_client: Mock):
34+
def test_job_id(self, batch_client: Mock) -> None:
3635
mock_job_id = "mock-job-id"
3736
job = BatchJob(batch_client, mock_job_id)
3837
assert job.id == mock_job_id
3938

40-
def test_invalid_await_timeout(self, batch_client: Mock):
39+
def test_invalid_await_timeout(self, batch_client: Mock) -> None:
4140
job = BatchJob(batch_client, "mock-job-id")
4241

4342
message = "timeout must be at least 1 second"
4443
with pytest.raises(ValueError, match=re.escape(message)):
4544
job.await_complete(timeout=0)
4645

47-
def test_get_details(self, batch_client: Mock):
46+
def test_get_details(self, batch_client: Mock) -> None:
4847
job = BatchJob(batch_client, "mock-job-id")
4948
details = job.get_details()
5049
assert details.state.status == BatchJobStatus.FAILED
5150

52-
def test_get_status(self, batch_client: Mock):
51+
def test_get_status(self, batch_client: Mock) -> None:
5352
job = BatchJob(batch_client, "mock-job-id")
5453
status = job.get_status()
5554
assert status == BatchJobStatus.FAILED
5655

57-
def test_await_complete(self, batch_client: Mock):
56+
def test_await_complete(self, batch_client: Mock) -> None:
5857
job = BatchJob(batch_client, "mock-job-id")
5958
details = job.await_complete()
6059
assert details.state.status == BatchJobStatus.FAILED
6160

62-
def test_raise_on_failed(self, batch_client: Mock):
61+
def test_raise_on_failed(self, batch_client: Mock) -> None:
6362
job = BatchJob(batch_client, "mock-job-id")
6463
message = "BatchJob mock-job-id failed."
6564
with pytest.raises(HumeClientException, match=re.escape(message)):
Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
import json
2+
from datetime import datetime
23
from pathlib import Path
4+
from typing import Optional
35

46
import pytest
57

68
from hume import BatchJobDetails, BatchJobStatus
79

810

9-
@pytest.fixture(scope="function")
10-
def completed_details() -> BatchJobDetails:
11+
@pytest.fixture(name="completed_details", scope="function")
12+
def completed_details_fixture() -> BatchJobDetails:
1113
response_filepath = Path(__file__).parent / "data" / "details-response-completed.json"
1214
with response_filepath.open() as f:
1315
response = json.load(f)
1416
return BatchJobDetails.from_response(response)
1517

1618

17-
@pytest.fixture(scope="function")
18-
def queued_details() -> BatchJobDetails:
19+
@pytest.fixture(name="queued_details", scope="function")
20+
def queued_details_fixture() -> BatchJobDetails:
1921
response_filepath = Path(__file__).parent / "data" / "details-response-queued.json"
2022
with response_filepath.open() as f:
2123
response = json.load(f)
2224
return BatchJobDetails.from_response(response)
2325

2426

25-
@pytest.fixture(scope="function")
26-
def failed_details() -> BatchJobDetails:
27+
@pytest.fixture(name="failed_details", scope="function")
28+
def failed_details_fixture() -> BatchJobDetails:
2729
response_filepath = Path(__file__).parent / "data" / "details-response-failed.json"
2830
with response_filepath.open() as f:
2931
response = json.load(f)
@@ -33,31 +35,35 @@ def failed_details() -> BatchJobDetails:
3335
@pytest.mark.batch
3436
class TestBatchJobDetails:
3537

36-
def test_queued_status(self, queued_details: BatchJobDetails):
38+
def test_queued_status(self, queued_details: BatchJobDetails) -> None:
3739
assert queued_details.get_status() == BatchJobStatus.QUEUED
3840

39-
def test_completed(self, completed_details: BatchJobDetails):
41+
def test_completed(self, completed_details: BatchJobDetails) -> None:
4042
assert completed_details.get_status() == BatchJobStatus.COMPLETED
4143
assert completed_details.configs is not None
4244
assert completed_details.urls is not None
4345
assert completed_details.files is not None
4446
assert completed_details.callback_url is not None
4547
assert completed_details.notify is not None
4648

47-
def test_job_time_completed(self, completed_details: BatchJobDetails):
48-
assert completed_details.get_created_time().strftime('%Y-%m-%d %H:%M:%S') == '2022-08-15 20:20:10'
49-
assert completed_details.get_started_time().strftime('%Y-%m-%d %H:%M:%S') == '2022-08-15 20:20:12'
50-
assert completed_details.get_ended_time().strftime('%Y-%m-%d %H:%M:%S') == '2022-08-15 20:20:15'
49+
def test_job_time_completed(self, completed_details: BatchJobDetails) -> None:
50+
self.check_time(completed_details.get_created_time(), "2022-08-15 20:20:10")
51+
self.check_time(completed_details.get_started_time(), "2022-08-15 20:20:12")
52+
self.check_time(completed_details.get_ended_time(), "2022-08-15 20:20:15")
5153
assert completed_details.get_run_time_ms() == 3000
5254

53-
def test_job_time_failed(self, failed_details: BatchJobDetails):
54-
assert failed_details.get_created_time().strftime('%Y-%m-%d %H:%M:%S') == '2022-08-15 20:20:11'
55-
assert failed_details.get_started_time().strftime('%Y-%m-%d %H:%M:%S') == '2022-08-15 20:20:14'
56-
assert failed_details.get_ended_time().strftime('%Y-%m-%d %H:%M:%S') == '2022-08-15 20:20:16'
55+
def test_job_time_failed(self, failed_details: BatchJobDetails) -> None:
56+
self.check_time(failed_details.get_created_time(), "2022-08-15 20:20:11")
57+
self.check_time(failed_details.get_started_time(), "2022-08-15 20:20:14")
58+
self.check_time(failed_details.get_ended_time(), "2022-08-15 20:20:16")
5759
assert failed_details.get_run_time_ms() == 2000
5860

59-
def test_job_time_queued(self, queued_details: BatchJobDetails):
60-
assert queued_details.get_created_time().strftime('%Y-%m-%d %H:%M:%S') == '2022-08-15 20:20:15'
61+
def test_job_time_queued(self, queued_details: BatchJobDetails) -> None:
62+
self.check_time(queued_details.get_created_time(), "2022-08-15 20:20:15")
6163
assert queued_details.get_started_time() is None
6264
assert queued_details.get_ended_time() is None
6365
assert queued_details.get_run_time_ms() is None
66+
67+
def check_time(self, date: Optional[datetime], formatted_date: str) -> None:
68+
assert date is not None
69+
assert date.strftime("%Y-%m-%d %H:%M:%S") == formatted_date

tests/batch/test_batch_job_state.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
@pytest.mark.batch
77
class TestBatchJobState:
88

9-
def test_create(self):
9+
def test_create(self) -> None:
1010
state = BatchJobState(
1111
status=BatchJobStatus.COMPLETED,
1212
created_timestamp_ms=1,

tests/batch/test_batch_job_status.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,40 @@
88
@pytest.mark.batch
99
class TestBatchJobStatus:
1010

11-
def test_update(self):
11+
def test_update(self) -> None:
1212
# Note: If another status is added to the enum make sure to update parametrized tests below:
1313
# - test_continuity
1414
# - test_is_terminal
1515
assert len(BatchJobStatus) == 4
1616

17-
@pytest.mark.parametrize("status_str", [
18-
"COMPLETED",
19-
"FAILED",
20-
"IN_PROGRESS",
21-
"QUEUED",
22-
])
23-
def test_continuity(self, status_str: str):
17+
@pytest.mark.parametrize(
18+
"status_str",
19+
[
20+
"COMPLETED",
21+
"FAILED",
22+
"IN_PROGRESS",
23+
"QUEUED",
24+
],
25+
)
26+
def test_continuity(self, status_str: str) -> None:
2427
assert BatchJobStatus[status_str].value == status_str
2528

26-
def test_from_str(self):
29+
def test_from_str(self) -> None:
2730
assert BatchJobStatus.from_str("COMPLETED") == BatchJobStatus.COMPLETED
2831

29-
def test_from_str_fail(self):
32+
def test_from_str_fail(self) -> None:
3033
message = "Unknown status 'COMPLETE'"
3134
with pytest.raises(ValueError, match=re.escape(message)):
3235
BatchJobStatus.from_str("COMPLETE")
3336

34-
@pytest.mark.parametrize("status, is_terminal", [
35-
(BatchJobStatus.COMPLETED, True),
36-
(BatchJobStatus.FAILED, True),
37-
(BatchJobStatus.IN_PROGRESS, False),
38-
(BatchJobStatus.QUEUED, False),
39-
])
40-
def test_is_terminal(self, status: BatchJobStatus, is_terminal: bool):
37+
@pytest.mark.parametrize(
38+
"status, is_terminal",
39+
[
40+
(BatchJobStatus.COMPLETED, True),
41+
(BatchJobStatus.FAILED, True),
42+
(BatchJobStatus.IN_PROGRESS, False),
43+
(BatchJobStatus.QUEUED, False),
44+
],
45+
)
46+
def test_is_terminal(self, status: BatchJobStatus, is_terminal: bool) -> None:
4147
assert BatchJobStatus.is_terminal(status) == is_terminal

tests/batch/test_hume_batch_client.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
from hume.models.config import BurstConfig, FaceConfig, LanguageConfig, ProsodyConfig
88

99

10-
@pytest.fixture(scope="function")
11-
def batch_client(monkeypatch: MonkeyPatch) -> HumeBatchClient:
10+
@pytest.fixture(name="batch_client", scope="function")
11+
def batch_client_fixture(monkeypatch: MonkeyPatch) -> HumeBatchClient:
1212
mock_submit_request = MagicMock(return_value="temp-job-value")
1313
monkeypatch.setattr(HumeBatchClient, "_submit_job", mock_submit_request)
1414
client = HumeBatchClient("0000-0000-0000-0000", timeout=15)
@@ -19,7 +19,7 @@ def batch_client(monkeypatch: MonkeyPatch) -> HumeBatchClient:
1919
@pytest.mark.batch
2020
class TestHumeBatchClient:
2121

22-
def test_face(self, batch_client: HumeBatchClient):
22+
def test_face(self, batch_client: HumeBatchClient) -> None:
2323
mock_url = "mock-url"
2424
config = FaceConfig(fps_pred=5, prob_threshold=0.24, identify_faces=True, min_face_size=78)
2525
job = batch_client.submit_job([mock_url], [config])
@@ -40,7 +40,7 @@ def test_face(self, batch_client: HumeBatchClient):
4040
None,
4141
)
4242

43-
def test_burst(self, batch_client: HumeBatchClient):
43+
def test_burst(self, batch_client: HumeBatchClient) -> None:
4444
mock_url = "mock-url"
4545
config = BurstConfig()
4646
job = batch_client.submit_job([mock_url], [config])
@@ -56,7 +56,7 @@ def test_burst(self, batch_client: HumeBatchClient):
5656
None,
5757
)
5858

59-
def test_prosody(self, batch_client: HumeBatchClient):
59+
def test_prosody(self, batch_client: HumeBatchClient) -> None:
6060
mock_url = "mock-url"
6161
config = ProsodyConfig(identify_speakers=True)
6262
job = batch_client.submit_job([mock_url], [config])
@@ -74,7 +74,7 @@ def test_prosody(self, batch_client: HumeBatchClient):
7474
None,
7575
)
7676

77-
def test_language(self, batch_client: HumeBatchClient):
77+
def test_language(self, batch_client: HumeBatchClient) -> None:
7878
mock_url = "mock-url"
7979
config = LanguageConfig(granularity="word", identify_speakers=True)
8080
job = batch_client.submit_job([mock_url], [config])
@@ -93,7 +93,7 @@ def test_language(self, batch_client: HumeBatchClient):
9393
None,
9494
)
9595

96-
def test_language_with_raw_text(self, batch_client: HumeBatchClient):
96+
def test_language_with_raw_text(self, batch_client: HumeBatchClient) -> None:
9797
mock_text = "Test!"
9898
config = LanguageConfig(granularity="word", identify_speakers=True)
9999
job = batch_client.submit_job([], [config], text=[mock_text])
@@ -113,11 +113,11 @@ def test_language_with_raw_text(self, batch_client: HumeBatchClient):
113113
None,
114114
)
115115

116-
def test_get_job(self, batch_client: HumeBatchClient):
116+
def test_get_job(self, batch_client: HumeBatchClient) -> None:
117117
job = batch_client.get_job("mock-job-id")
118118
assert job.id == "mock-job-id"
119119

120-
def test_files(self, batch_client: HumeBatchClient):
120+
def test_files(self, batch_client: HumeBatchClient) -> None:
121121
mock_filepath = "my-audio.mp3"
122122
config = ProsodyConfig(identify_speakers=True)
123123
job = batch_client.submit_job(None, [config], files=[mock_filepath])
@@ -130,22 +130,23 @@ def test_files(self, batch_client: HumeBatchClient):
130130
"prosody": {
131131
"identify_speakers": True,
132132
},
133-
}
133+
},
134134
},
135-
['my-audio.mp3'],
135+
["my-audio.mp3"],
136136
)
137137

138-
def test_get_multipart_form_data(self, batch_client: HumeBatchClient, tmp_path_factory: TempPathFactory):
138+
def test_get_multipart_form_data(self, batch_client: HumeBatchClient, tmp_path_factory: TempPathFactory) -> None:
139139
dirpath = tmp_path_factory.mktemp("multipart")
140140
filepath = dirpath / "my-audio.mp3"
141141
with filepath.open("w") as f:
142142
f.write("I can't believe this test passed!")
143143

144144
request_body = {"mock": "body"}
145145
filepaths = [filepath]
146+
# pylint: disable=protected-access
146147
result = batch_client._get_multipart_form_data(request_body, filepaths)
147148

148149
assert result == [
149-
('file', ('my-audio.mp3', b"I can't believe this test passed!")),
150-
('json', b'{"mock": "body"}'),
150+
("file", ("my-audio.mp3", b"I can't believe this test passed!")),
151+
("json", b'{"mock": "body"}'),
151152
]

0 commit comments

Comments
 (0)