From 2baf31330bcd51b99cbe65e2b8740f537ff88519 Mon Sep 17 00:00:00 2001 From: nicobo Date: Sun, 7 Feb 2021 16:34:49 +0100 Subject: [PATCH] + unit testing options --- tests/test_options.py | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/test_options.py diff --git a/tests/test_options.py b/tests/test_options.py new file mode 100644 index 0000000..06e617b --- /dev/null +++ b/tests/test_options.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +import unittest +import argparse +import os + +# Own classes +from nicobot.helpers import * +from nicobot.bot import Bot +from nicobot.bot import ArgsHelper as BotArgsHelper +from nicobot.askbot import Config as AskbotConfig +from nicobot.jabber import arg_parser as jabber_arg_parser +from nicobot.signalcli import ArgsHelper as SignalArgsHelper + + +class TestOptions(unittest.TestCase): + + def setUp(self): + self.parser = argparse.ArgumentParser( + parents=[ BotArgsHelper().parser(), jabber_arg_parser(), SignalArgsHelper().parser() ], + description='Testing CLI options', + formatter_class=argparse.ArgumentDefaultsHelpFormatter ) + + def test_config_path_default(self): + + # Using AskbotConfig but it could be another one as long as this test is not askbot-specific + config = AskbotConfig() + args = [] + config = parse_args_2pass( self.parser, args, config ) + self.assertTrue( len(config.config_dirs) == 1 ) + self.assertEqual( os.path.realpath(os.getcwd()), os.path.realpath(config.config_dirs[0]) ) + + def test_config_path_custom(self): + + # Using AskbotConfig but it could be another one as long as this test is not askbot-specific + config = AskbotConfig() + args = [ '--config-dir', '/tmp/nicobot' ] + config = parse_args_2pass( self.parser, args, config ) + self.assertTrue( len(config.config_dirs) == 1 ) + self.assertEqual( os.path.realpath('/tmp/nicobot'), os.path.realpath(config.config_dirs[0]) ) + + def test_config_path_default_and_custom(self): + + # Using AskbotConfig but it could be another one as long as this test is not askbot-specific + config = AskbotConfig() + args = [ '--config-dir', '/etc/nicobot', '/tmp/nicobot' ] + config = parse_args_2pass( self.parser, args, config ) + self.assertTrue( len(config.config_dirs) == 2 ) + self.assertEqual( os.path.realpath('/etc/nicobot'), os.path.realpath(config.config_dirs[0]) ) + self.assertEqual( os.path.realpath('/tmp/nicobot'), os.path.realpath(config.config_dirs[1]) ) + + +if __name__ == '__main__': + unittest.main()