From 6489f78edd438e787e57bebc747994ec44838014 Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Fri, 22 Dec 2017 20:57:28 -0800 Subject: [PATCH] mypy: Improve test_dialogflow.py, to pass with strict-optional. --- zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py b/zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py index 41fcd23..5f4424c 100644 --- a/zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py +++ b/zulip_bots/zulip_bots/bots/dialogflow/test_dialogflow.py @@ -27,8 +27,12 @@ class MockHttplibRequest(): @contextmanager def mock_dialogflow(test_name: str, bot_name: str) -> Any: response_data = read_bot_fixture_data(bot_name, test_name) - df_request = response_data.get('request') - df_response = response_data.get('response') + try: + df_request = response_data['request'] + df_response = response_data['response'] + except KeyError: + print("ERROR: 'request' or 'response' field not found in fixture.") + raise with patch('apiai.ApiAI.text_request') as mock_text_request: request = MockTextRequest()