From 0ea49c96edd26af00f320a9a215410dc6ab2b28c Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Sat, 9 Jun 2018 20:39:03 -0700 Subject: [PATCH] bot tests: import patch in incrementor & monkeytestit as in other tests. This makes the code more compact and consistent. --- .../zulip_bots/bots/incrementor/test_incrementor.py | 4 ++-- .../zulip_bots/bots/monkeytestit/test_monkeytestit.py | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/incrementor/test_incrementor.py b/zulip_bots/zulip_bots/bots/incrementor/test_incrementor.py index 7125504..20ceb31 100644 --- a/zulip_bots/zulip_bots/bots/incrementor/test_incrementor.py +++ b/zulip_bots/zulip_bots/bots/incrementor/test_incrementor.py @@ -1,4 +1,4 @@ -from unittest import mock +from unittest.mock import patch from zulip_bots.test_lib import ( get_bot_message_handler, @@ -19,7 +19,7 @@ class TestIncrementorBot(BotTestCase, DefaultTests): bot.initialize(bot_handler) bot.handle_message(message, bot_handler) - with mock.patch('zulip_bots.simple_lib.SimpleMessageServer.update') as m: + with patch('zulip_bots.simple_lib.SimpleMessageServer.update') as m: bot.handle_message(message, bot_handler) bot.handle_message(message, bot_handler) bot.handle_message(message, bot_handler) diff --git a/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py b/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py index f29e4db..b1f79b6 100644 --- a/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py +++ b/zulip_bots/zulip_bots/bots/monkeytestit/test_monkeytestit.py @@ -1,4 +1,5 @@ -from unittest import mock, skipIf +from unittest.mock import patch +from unittest import skipIf from sys import version_info @@ -18,7 +19,7 @@ class TestMonkeyTestitBot(BotTestCase, DefaultTests): content='', type='stream', ) - with mock.patch.object(self.monkeytestit_class, 'initialize', return_value=None): + with patch.object(self.monkeytestit_class, 'initialize', return_value=None): with self.mock_config_info({'api_key': "magic"}): res = self.get_response(message) self.assertTrue("Unknown command" in res['content']) @@ -28,7 +29,7 @@ class TestMonkeyTestitBot(BotTestCase, DefaultTests): content='check https://website.com', type='stream', ) - with mock.patch.object(self.monkeytestit_class, 'initialize', return_value=None): + with patch.object(self.monkeytestit_class, 'initialize', return_value=None): with self.mock_config_info({'api_key': "magic"}): with self.mock_http_conversation('website_result_fail'): res = self.get_response(message) @@ -39,7 +40,7 @@ class TestMonkeyTestitBot(BotTestCase, DefaultTests): content='check https://website.com', type='stream', ) - with mock.patch.object(self.monkeytestit_class, 'initialize', return_value=None): + with patch.object(self.monkeytestit_class, 'initialize', return_value=None): with self.mock_config_info({'api_key': "magic"}): with self.mock_http_conversation('website_result_success'): res = self.get_response(message)