From bd9bb0a4e836cc242ddc140dc83b734f4d56cee3 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sat, 18 Apr 2020 16:47:57 -0700 Subject: [PATCH] cleanup: Fix indentation. Signed-off-by: Anders Kaseorg --- .../jabber/jabber_mirror_backend.py | 6 +-- .../bots/beeminder/test_beeminder.py | 12 ++--- .../bots/dropbox_share/dropbox_share.py | 48 +++++++++---------- .../zulip_bots/bots/flock/test_flock.py | 8 ++-- .../google_translate/test_google_translate.py | 16 +++---- .../zulip_bots/bots/merels/libraries/game.py | 2 +- .../zulip_bots/bots/youtube/test_youtube.py | 18 +++---- zulip_bots/zulip_bots/tests/test_run.py | 6 +-- 8 files changed, 58 insertions(+), 58 deletions(-) diff --git a/zulip/integrations/jabber/jabber_mirror_backend.py b/zulip/integrations/jabber/jabber_mirror_backend.py index 8fa56f8..18158f4 100755 --- a/zulip/integrations/jabber/jabber_mirror_backend.py +++ b/zulip/integrations/jabber/jabber_mirror_backend.py @@ -292,9 +292,9 @@ def get_rooms(zulipToJabber: ZulipToJabberBot) -> List[str]: rooms = [] # type: List[str] for stream_info in stream_infos: - stream = stream_info['name'] - if stream.endswith("/xmpp"): - rooms.append(stream_to_room(stream)) + stream = stream_info['name'] + if stream.endswith("/xmpp"): + rooms.append(stream_to_room(stream)) return rooms def config_error(msg: str) -> None: diff --git a/zulip_bots/zulip_bots/bots/beeminder/test_beeminder.py b/zulip_bots/zulip_bots/bots/beeminder/test_beeminder.py index c2ac3cd..909a365 100644 --- a/zulip_bots/zulip_bots/bots/beeminder/test_beeminder.py +++ b/zulip_bots/zulip_bots/bots/beeminder/test_beeminder.py @@ -23,12 +23,12 @@ following the syntax shown below :smile:.\n \ def test_bot_responds_to_empty_message(self) -> None: with self.mock_config_info(self.normal_config), \ self.mock_http_conversation('test_valid_auth_token'): - self.verify_reply('', self.help_message) + self.verify_reply('', self.help_message) def test_help_message(self) -> None: with self.mock_config_info(self.normal_config), \ self.mock_http_conversation('test_valid_auth_token'): - self.verify_reply('help', self.help_message) + self.verify_reply('help', self.help_message) def test_message_with_daystamp_and_value(self) -> None: bot_response = '[Datapoint](https://www.beeminder.com/aaron/goal) created.' @@ -54,9 +54,9 @@ following the syntax shown below :smile:.\n \ def test_syntax_error(self) -> None: with self.mock_config_info(self.normal_config), \ self.mock_http_conversation('test_valid_auth_token'): - bot_response = "Make sure you follow the syntax.\n You can take a look \ + bot_response = "Make sure you follow the syntax.\n You can take a look \ at syntax by: @mention-botname help" - self.verify_reply("20180303, 50, comment, redundant comment", bot_response) + self.verify_reply("20180303, 50, comment, redundant comment", bot_response) def test_connection_error_when_handle_message(self) -> None: with self.mock_config_info(self.normal_config), \ @@ -84,7 +84,7 @@ right now.\nPlease try again later') with self.mock_config_info(self.normal_config), \ self.mock_http_conversation('test_valid_auth_token'), \ self.mock_http_conversation('test_error'): - self.verify_reply(bot_request, bot_response) + self.verify_reply(bot_request, bot_response) def test_invalid_when_initialize(self) -> None: bot = get_bot_message_handler(self.bot_name) @@ -95,7 +95,7 @@ right now.\nPlease try again later') 'goalname': 'goal'}), \ self.mock_http_conversation('test_invalid_when_initialize'), \ self.assertRaises(bot_handler.BotQuitException): - bot.initialize(bot_handler) + bot.initialize(bot_handler) def test_connection_error_during_initialize(self) -> None: bot = get_bot_message_handler(self.bot_name) diff --git a/zulip_bots/zulip_bots/bots/dropbox_share/dropbox_share.py b/zulip_bots/zulip_bots/bots/dropbox_share/dropbox_share.py index f80bf9f..c38d6c5 100644 --- a/zulip_bots/zulip_bots/bots/dropbox_share/dropbox_share.py +++ b/zulip_bots/zulip_bots/bots/dropbox_share/dropbox_share.py @@ -183,33 +183,33 @@ def dbx_read(client: Any, fn: str) -> str: return msg def dbx_search(client: Any, query: str, folder: str, max_results: str) -> str: - if folder is None: - folder = '' - else: - folder = '/' + folder - if max_results is None: - max_results = '20' - try: - result = client.files_search(folder, query, max_results=int(max_results)) - msg_list = [] - count = 0 - for entry in result.matches: - file_info = entry.metadata - count += 1 - msg_list += [" - " + URL.format(name=file_info.name, path=file_info.path_lower)] - msg = '\n'.join(msg_list) + if folder is None: + folder = '' + else: + folder = '/' + folder + if max_results is None: + max_results = '20' + try: + result = client.files_search(folder, query, max_results=int(max_results)) + msg_list = [] + count = 0 + for entry in result.matches: + file_info = entry.metadata + count += 1 + msg_list += [" - " + URL.format(name=file_info.name, path=file_info.path_lower)] + msg = '\n'.join(msg_list) - except Exception: - msg = "Usage: `search query --mr 10 --fd `\n"\ - "Note:`--mr ` is optional and is used to specify maximun results.\n"\ - " `--fd ` to search in specific folder." + except Exception: + msg = "Usage: `search query --mr 10 --fd `\n"\ + "Note:`--mr ` is optional and is used to specify maximun results.\n"\ + " `--fd ` to search in specific folder." - if msg == '': - msg = "No files/folders found matching your query.\n"\ - "For file name searching, the last token is used for prefix matching"\ - " (i.e. “bat c” matches “bat cave” but not “batman car”)." + if msg == '': + msg = "No files/folders found matching your query.\n"\ + "For file name searching, the last token is used for prefix matching"\ + " (i.e. “bat c” matches “bat cave” but not “batman car”)." - return msg + return msg def dbx_share(client: Any, fn: str): fn = '/' + fn diff --git a/zulip_bots/zulip_bots/bots/flock/test_flock.py b/zulip_bots/zulip_bots/bots/flock/test_flock.py index fdf36a0..6add591 100644 --- a/zulip_bots/zulip_bots/bots/flock/test_flock.py +++ b/zulip_bots/zulip_bots/bots/flock/test_flock.py @@ -41,13 +41,13 @@ right now.\nPlease try again later") bot_response = "No user found. Make sure you typed it correctly." with self.mock_config_info(self.normal_config), \ self.mock_http_conversation('test_no_recipient_found'): - self.verify_reply('david: hello', bot_response) + self.verify_reply('david: hello', bot_response) def test_found_invalid_recipient(self) -> None: bot_response = "Found user is invalid." with self.mock_config_info(self.normal_config), \ self.mock_http_conversation('test_found_invalid_recipient'): - self.verify_reply('david: hello', bot_response) + self.verify_reply('david: hello', bot_response) @patch('zulip_bots.bots.flock.flock.get_recipient_id') def test_message_send_connection_error(self, get_recipient_id: str) -> None: @@ -64,7 +64,7 @@ right now.\nPlease try again later") get_recipient_id.return_value = ["u:userid", None] with self.mock_config_info(self.normal_config), \ self.mock_http_conversation('test_message_send_success'): - self.verify_reply('Rishabh: hi there', bot_response) + self.verify_reply('Rishabh: hi there', bot_response) @patch('zulip_bots.bots.flock.flock.get_recipient_id') def test_message_send_failed(self, get_recipient_id: str) -> None: @@ -72,4 +72,4 @@ right now.\nPlease try again later") get_recipient_id.return_value = ["u:invalid", None] with self.mock_config_info(self.normal_config), \ self.mock_http_conversation('test_message_send_failed'): - self.verify_reply('Rishabh: hi there', bot_response) + self.verify_reply('Rishabh: hi there', bot_response) diff --git a/zulip_bots/zulip_bots/bots/google_translate/test_google_translate.py b/zulip_bots/zulip_bots/bots/google_translate/test_google_translate.py index 8a777c4..bad4d83 100644 --- a/zulip_bots/zulip_bots/bots/google_translate/test_google_translate.py +++ b/zulip_bots/zulip_bots/bots/google_translate/test_google_translate.py @@ -16,11 +16,11 @@ class TestGoogleTranslateBot(BotTestCase, DefaultTests): def _test(self, message, response, http_config_fixture, http_fixture=None): with self.mock_config_info({'key': 'abcdefg'}), \ self.mock_http_conversation(http_config_fixture): - if http_fixture: - with self.mock_http_conversation(http_fixture): - self.verify_reply(message, response) - else: - self.verify_reply(message, response) + if http_fixture: + with self.mock_http_conversation(http_fixture): + self.verify_reply(message, response) + else: + self.verify_reply(message, response) def test_normal(self): self._test('"hello" de', 'Hallo (from Foo Test User)', 'test_languages', 'test_normal') @@ -76,6 +76,6 @@ class TestGoogleTranslateBot(BotTestCase, DefaultTests): def test_connection_error(self): with patch('requests.post', side_effect=ConnectionError()), \ patch('logging.warning'): - self._test('"test" en', - 'Could not connect to Google Translate. .', - 'test_languages') + self._test('"test" en', + 'Could not connect to Google Translate. .', + 'test_languages') diff --git a/zulip_bots/zulip_bots/bots/merels/libraries/game.py b/zulip_bots/zulip_bots/bots/merels/libraries/game.py index 61f1fd4..e47c08b 100644 --- a/zulip_bots/zulip_bots/bots/merels/libraries/game.py +++ b/zulip_bots/zulip_bots/bots/merels/libraries/game.py @@ -91,7 +91,7 @@ def beat(message, topic_name, merels_storage): return unknown_command() if mechanics.get_take_status(topic_name, merels_storage) == 1: - same_player_move = "Take is required to proceed.\n" + same_player_move = "Take is required to proceed.\n" return responses, same_player_move elif match.group(4) is not None and match.group(5) is not None: diff --git a/zulip_bots/zulip_bots/bots/youtube/test_youtube.py b/zulip_bots/zulip_bots/bots/youtube/test_youtube.py index 14d701c..13f69fa 100644 --- a/zulip_bots/zulip_bots/bots/youtube/test_youtube.py +++ b/zulip_bots/zulip_bots/bots/youtube/test_youtube.py @@ -23,7 +23,7 @@ class TestYoutubeBot(BotTestCase, DefaultTests): def test_bot_responds_to_empty_message(self) -> None: with self.mock_config_info(self.normal_config), \ self.mock_http_conversation('test_keyok'): - self.verify_reply('', self.help_content) + self.verify_reply('', self.help_content) def test_single(self) -> None: bot_response = 'Here is what I found for `funny cats` : \n'\ @@ -32,7 +32,7 @@ class TestYoutubeBot(BotTestCase, DefaultTests): with self.mock_config_info(self.normal_config), \ self.mock_http_conversation('test_single'): - self.verify_reply('funny cats', bot_response) + self.verify_reply('funny cats', bot_response) def test_invalid_key(self) -> None: bot = get_bot_message_handler(self.bot_name) @@ -41,7 +41,7 @@ class TestYoutubeBot(BotTestCase, DefaultTests): with self.mock_config_info({'key': 'somethinginvalid', 'number_of_results': '5', 'video_region': 'US'}), \ self.mock_http_conversation('test_invalid_key'), \ self.assertRaises(bot_handler.BotQuitException): - bot.initialize(bot_handler) + bot.initialize(bot_handler) def test_unknown_error(self) -> None: bot = get_bot_message_handler(self.bot_name) @@ -50,7 +50,7 @@ class TestYoutubeBot(BotTestCase, DefaultTests): with self.mock_config_info(self.normal_config), \ self.mock_http_conversation('test_unknown_error'), \ self.assertRaises(HTTPError): - bot.initialize(bot_handler) + bot.initialize(bot_handler) def test_multiple(self) -> None: get_bot_message_handler(self.bot_name) @@ -65,7 +65,7 @@ class TestYoutubeBot(BotTestCase, DefaultTests): with self.mock_config_info(self.normal_config), \ self.mock_http_conversation('test_multiple'): - self.verify_reply('list marvel', bot_response) + self.verify_reply('list marvel', bot_response) def test_noresult(self) -> None: bot_response = 'Oops ! Sorry I couldn\'t find any video for `somethingrandomwithnoresult` ' \ @@ -79,10 +79,10 @@ class TestYoutubeBot(BotTestCase, DefaultTests): help_content = self.help_content with self.mock_config_info(self.normal_config), \ self.mock_http_conversation('test_keyok'): - self.verify_reply('help', help_content) - self.verify_reply('list', help_content) - self.verify_reply('help list', help_content) - self.verify_reply('top', help_content) + self.verify_reply('help', help_content) + self.verify_reply('list', help_content) + self.verify_reply('help list', help_content) + self.verify_reply('top', help_content) def test_connection_error(self) -> None: with self.mock_config_info(self.normal_config), \ diff --git a/zulip_bots/zulip_bots/tests/test_run.py b/zulip_bots/zulip_bots/tests/test_run.py index fff76c3..479955b 100644 --- a/zulip_bots/zulip_bots/tests/test_run.py +++ b/zulip_bots/zulip_bots/tests/test_run.py @@ -73,9 +73,9 @@ class TestDefaultArguments(TestCase): with patch('sys.argv', ['zulip-run-bot', 'bot.module.name', '--config-file', '/path/to/config']): with patch('importlib.import_module', return_value=mock_bot_module) as mock_import_module: with patch('zulip_bots.run.run_message_handler_for_bot'): - with patch('zulip_bots.run.exit_gracefully_if_zulip_config_is_missing'): - zulip_bots.run.main() - mock_import_module.assert_called_once_with(bot_module_name) + with patch('zulip_bots.run.exit_gracefully_if_zulip_config_is_missing'): + zulip_bots.run.main() + mock_import_module.assert_called_once_with(bot_module_name) class TestBotLib(TestCase):