From 18157095c4ba26d3104fe8c1e2d94dd613cf0eaa Mon Sep 17 00:00:00 2001 From: derAnfaenger Date: Thu, 7 Sep 2017 10:04:21 +0200 Subject: [PATCH] zulip_bots: Add unittests for run.py. These are tests that assert the correct argument parsing; the successful execution of bots is not verified. --- zulip_bots/zulip_bots/test_run.py | 46 +++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 zulip_bots/zulip_bots/test_run.py diff --git a/zulip_bots/zulip_bots/test_run.py b/zulip_bots/zulip_bots/test_run.py new file mode 100644 index 0000000..6871e60 --- /dev/null +++ b/zulip_bots/zulip_bots/test_run.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +from __future__ import absolute_import + +import importlib +import os +import zulip_bots.run +import six +import unittest +import zulip + +from importlib import import_module +from unittest import TestCase + +if six.PY2: + import mock + from mock import patch +else: + from unittest import mock + from unittest.mock import patch + +class TestDefaultArguments(TestCase): + + our_dir = os.path.dirname(__file__) + path_to_bot = os.path.abspath(os.path.join(our_dir, 'bots/giphy/giphy.py')) + + @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): + 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, + quiet=False) + + @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): + 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, + quiet=False) + +if __name__ == '__main__': + unittest.main()