mypy: Improve typing of dialogflow and salesforce tests.
MODIFY
zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py
zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py
@@ -4,28 +4,28 @@ from contextlib import contextmanager
from unittest.mock import patch
-from typing import Any, ByteString
+from typing import Iterator, ByteString
import json
+class MockHttplibRequest():
+ def __init__(self, response: str) -> None:
+ self.response = response
+
+ def read(self) -> ByteString:
+ return json.dumps(self.response).encode()
+
class MockTextRequest():
def __init__(self) -> None:
self.session_id = ""
self.query = ""
self.response = ""
- def getresponse(self) -> Any:
+ def getresponse(self) -> MockHttplibRequest:
return MockHttplibRequest(self.response)
-class MockHttplibRequest():
- def __init__(self, response: str) -> None:
- self.response = response
-
- def read(self) -> ByteString:
- return json.dumps(self.response).encode()
-
@contextmanager
-def mock_dialogflow(test_name: str, bot_name: str) -> Any:
+def mock_dialogflow(test_name: str, bot_name: str) -> Iterator[None]:
response_data = read_bot_fixture_data(bot_name, test_name)
try:
df_request = response_data['request']

MODIFY
zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py
zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py
@@ -2,11 +2,11 @@ from zulip_bots.test_lib import BotTestCase, DefaultTests, StubBotHandler, read_
from simple_salesforce.exceptions import SalesforceAuthenticationFailed
from contextlib import contextmanager
from unittest.mock import patch
-from typing import Any, Dict
+from typing import Any, Dict, Iterator
@contextmanager
-def mock_salesforce_query(test_name: str, bot_name: str) -> Any:
+def mock_salesforce_query(test_name: str, bot_name: str) -> Iterator[None]:
response_data = read_bot_fixture_data(bot_name, test_name)
sf_response = response_data.get('response')
@@ -16,7 +16,7 @@ def mock_salesforce_query(test_name: str, bot_name: str) -> Any:
@contextmanager
-def mock_salesforce_auth(is_success: bool) -> Any:
+def mock_salesforce_auth(is_success: bool) -> Iterator[None]:
if is_success:
with patch('simple_salesforce.api.Salesforce.__init__') as mock_sf_init:
mock_sf_init.return_value = None
@@ -31,7 +31,7 @@ def mock_salesforce_auth(is_success: bool) -> Any:
@contextmanager
-def mock_salesforce_commands_types() -> Any:
+def mock_salesforce_commands_types() -> Iterator[None]:
with patch('zulip_bots.bots.salesforce.utils.commands', mock_commands), \
patch('zulip_bots.bots.salesforce.utils.object_types', mock_object_types):
yield

mypy: Improve typing of dialogflow and salesforce tests.