From cd76a3cf5a2b5053bddf2e31a47d80a76c75ec24 Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Sat, 9 Jun 2018 20:25:28 -0700 Subject: [PATCH] mypy: Improve typing of dialogflow and salesforce tests. --- .../bots/dialogflow/test_dialogflow.py | 22 +++++++++---------- .../bots/salesforce/test_salesforce.py | 8 +++---- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py b/zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py index 9472a68..560a4b0 100644 --- a/zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py +++ b/zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py @@ -4,19 +4,10 @@ from contextlib import contextmanager from unittest.mock import patch -from typing import Any, ByteString +from typing import Iterator, ByteString import json -class MockTextRequest(): - def __init__(self) -> None: - self.session_id = "" - self.query = "" - self.response = "" - - def getresponse(self) -> Any: - return MockHttplibRequest(self.response) - class MockHttplibRequest(): def __init__(self, response: str) -> None: self.response = response @@ -24,8 +15,17 @@ class MockHttplibRequest(): 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) -> MockHttplibRequest: + return MockHttplibRequest(self.response) + @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'] diff --git a/zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py b/zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py index cf494f1..656f29a 100644 --- a/zulip_bots/zulip_bots/bots/salesforce/test_salesforce.py +++ b/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