diff --git a/zulip_bots/zulip_bots/run.py b/zulip_bots/zulip_bots/run.py index de22330..5a944c9 100755 --- a/zulip_bots/zulip_bots/run.py +++ b/zulip_bots/zulip_bots/run.py @@ -75,6 +75,18 @@ def parse_args(): return args +def exit_gracefully_if_config_file_does_not_exist(config_file): + # type: (str) -> None + if not os.path.exists(config_file): + print(''' + ERROR: %s does not exist. + + You may need to download a config file from the Zulip app, or + if you have already done that, you need to specify the file + location correctly. + ''' % (config_file,)) + sys.exit(1) + def main(): # type: () -> None args = parse_args() @@ -91,6 +103,8 @@ def main(): if not args.quiet: logging.basicConfig(stream=sys.stdout, level=logging.INFO) + exit_gracefully_if_config_file_does_not_exist(args.config_file) + run_message_handler_for_bot( lib_module=lib_module, config_file=args.config_file, diff --git a/zulip_bots/zulip_bots/test_run.py b/zulip_bots/zulip_bots/test_run.py index 4b4ed63..b27a1ef 100644 --- a/zulip_bots/zulip_bots/test_run.py +++ b/zulip_bots/zulip_bots/test_run.py @@ -29,7 +29,9 @@ class TestDefaultArguments(TestCase): @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 - zulip_bots.run.main() + with patch('zulip_bots.run.exit_gracefully_if_config_file_does_not_exist'): + zulip_bots.run.main() + mock_run_message_handler_for_bot.assert_called_with(bot_name='giphy', config_file='/foo/bar/baz.conf', lib_module=mock.ANY, @@ -39,7 +41,9 @@ class TestDefaultArguments(TestCase): @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 - zulip_bots.run.main() + with patch('zulip_bots.run.exit_gracefully_if_config_file_does_not_exist'): + zulip_bots.run.main() + mock_run_message_handler_for_bot.assert_called_with( bot_name='giphy', config_file='/foo/bar/baz.conf',