zulip_bots: Python3 style for types, obey pep8.
MODIFY
zulip_bots/zulip_bots/run.py
zulip_bots/zulip_bots/run.py
@@ -6,7 +6,6 @@ import sys
import os
from os.path import basename, splitext
-if False:
from typing import Any, Optional, Text
from zulip_bots.lib import (
@@ -18,8 +17,8 @@ from zulip_bots.provision import provision_bot
current_dir = os.path.dirname(os.path.abspath(__file__))
-def import_module_from_source(path, name=None):
- # type: (Text, Optional[Text]) -> Any
+
+def import_module_from_source(path: Text, name: Optional[Text]=None) -> Any:
if not name:
name = splitext(basename(path))[0]
@@ -39,8 +38,8 @@ def import_module_from_source(path, name=None):
return module
-def parse_args():
- # type: () -> argparse.Namespace
+
+def parse_args() -> argparse.Namespace:
usage = '''
zulip-run-bot <bot_name> --config-file ~/zuliprc
zulip-run-bot --help
@@ -76,8 +75,7 @@ def parse_args():
return args
-def exit_gracefully_if_zulip_config_file_does_not_exist(config_file):
- # type: (str) -> None
+def exit_gracefully_if_zulip_config_file_does_not_exist(config_file: str) -> None:
if not os.path.exists(config_file):
print('''
ERROR: %s does not exist.
@@ -88,8 +86,8 @@ def exit_gracefully_if_zulip_config_file_does_not_exist(config_file):
''' % (config_file,))
sys.exit(1)
-def exit_gracefully_if_bot_config_file_does_not_exist(bot_config_file):
- # type: (str) -> None
+
+def exit_gracefully_if_bot_config_file_does_not_exist(bot_config_file: str) -> None:
if bot_config_file is None:
# This is a common case, just so succeed quietly. (Some
# bots don't have third party configuration.)
@@ -103,8 +101,8 @@ def exit_gracefully_if_bot_config_file_does_not_exist(bot_config_file):
''' % (bot_config_file,))
sys.exit(1)
-def main():
- # type: () -> None
+
+def main() -> None:
args = parse_args()
if os.path.isfile(args.bot):
bot_path = os.path.abspath(args.bot)

MODIFY
zulip_bots/zulip_bots/test_run.py
zulip_bots/zulip_bots/test_run.py
@@ -10,6 +10,7 @@ from unittest import TestCase
from unittest import mock
from unittest.mock import patch
+
class TestDefaultArguments(TestCase):
our_dir = os.path.dirname(__file__)
@@ -17,8 +18,7 @@ class TestDefaultArguments(TestCase):
@patch('sys.argv', ['zulip-run-bot', 'giphy', '--config-file', '/foo/bar/baz.conf'])
@patch('zulip_bots.run.run_message_handler_for_bot')
- def test_argument_parsing_with_bot_name(self, mock_run_message_handler_for_bot):
- # type: (mock.Mock) -> None
+ def test_argument_parsing_with_bot_name(self, mock_run_message_handler_for_bot: mock.Mock) -> None:
with patch('zulip_bots.run.exit_gracefully_if_zulip_config_file_does_not_exist'):
zulip_bots.run.main()
@@ -30,8 +30,7 @@ class TestDefaultArguments(TestCase):
@patch('sys.argv', ['zulip-run-bot', path_to_bot, '--config-file', '/foo/bar/baz.conf'])
@patch('zulip_bots.run.run_message_handler_for_bot')
- def test_argument_parsing_with_bot_path(self, mock_run_message_handler_for_bot):
- # type: (mock.Mock) -> None
+ def test_argument_parsing_with_bot_path(self, mock_run_message_handler_for_bot: mock.Mock) -> None:
with patch('zulip_bots.run.exit_gracefully_if_zulip_config_file_does_not_exist'):
zulip_bots.run.main()
@@ -42,8 +41,7 @@ class TestDefaultArguments(TestCase):
lib_module=mock.ANY,
quiet=False)
- def test_adding_bot_parent_dir_to_sys_path_when_bot_name_specified(self):
- # type: () -> None
+ def test_adding_bot_parent_dir_to_sys_path_when_bot_name_specified(self) -> None:
bot_name = 'any_bot_name'
expected_bot_dir_path = os.path.join(
os.path.dirname(zulip_bots.run.__file__),
@@ -53,8 +51,7 @@ class TestDefaultArguments(TestCase):
self._test_adding_bot_parent_dir_to_sys_path(bot_qualifier=bot_name, bot_dir_path=expected_bot_dir_path)
@patch('os.path.isfile', return_value=True)
- def test_adding_bot_parent_dir_to_sys_path_when_bot_path_specified(self, mock_os_path_isfile):
- # type: (mock.Mock) -> None
+ def test_adding_bot_parent_dir_to_sys_path_when_bot_path_specified(self, mock_os_path_isfile: mock.Mock) -> None:
bot_path = '/path/to/bot'
expected_bot_dir_path = '/path/to'
self._test_adding_bot_parent_dir_to_sys_path(bot_qualifier=bot_path, bot_dir_path=expected_bot_dir_path)
@@ -69,12 +66,11 @@ class TestDefaultArguments(TestCase):
self.assertIn(bot_dir_path, sys.path)
+
class TestBotLib(TestCase):
- def test_extract_query_without_mention(self):
- # type: () -> None
+ def test_extract_query_without_mention(self) -> None:
- def test_message(name, message, expected_return):
- # type: (str, str, Optional[str]) -> None
+ def test_message(name: str, message: str, expected_return: Optional[str]) -> None:
mock_client = mock.MagicMock()
mock_client.full_name = name
mock_message = {'content': message}

zulip_bots: Python3 style for types, obey pep8.