Example #1
0
class TestLoggingEventHandling(unittest.TestCase):
    def setUp(self):
        self.mock_ctx = MockContext()
        self.cli_logging = CLILogging('clitest', cli_ctx=self.mock_ctx)

    def test_cli_ctx_type_error(self):
        with self.assertRaises(TypeError):
            CLILogging('myclitest', cli_ctx=object())

    def test_logging_argument_registrations(self):
        parser_arg_group_mock = mock.MagicMock()
        self.mock_ctx.raise_event(EVENT_PARSER_GLOBAL_CREATE,
                                  arg_group=parser_arg_group_mock)
        parser_arg_group_mock.add_argument.assert_any_call(
            CLILogging.VERBOSE_FLAG,
            dest=mock.ANY,
            action=mock.ANY,
            help=mock.ANY)
        parser_arg_group_mock.add_argument.assert_any_call(
            CLILogging.DEBUG_FLAG,
            dest=mock.ANY,
            action=mock.ANY,
            help=mock.ANY)

    def test_logging_arguments_removed(self):
        arguments = [CLILogging.VERBOSE_FLAG, CLILogging.DEBUG_FLAG]
        self.mock_ctx.raise_event(EVENT_INVOKER_PRE_CMD_TBL_CREATE,
                                  args=arguments)
        # After the event is raised, the arguments should have been removed
        self.assertFalse(arguments)
Example #2
0
class TestLoggingEventHandling(unittest.TestCase):
    def setUp(self):
        self.mock_ctx = MockContext()
        self.cli_logging = CLILogging('clitest', cli_ctx=self.mock_ctx)

    def test_cli_ctx_type_error(self):
        with self.assertRaises(TypeError):
            CLILogging('myclitest', cli_ctx=object())

    def test_logging_argument_registrations(self):
        parser_arg_group_mock = mock.MagicMock()
        self.mock_ctx.raise_event(EVENT_PARSER_GLOBAL_CREATE, arg_group=parser_arg_group_mock)
        parser_arg_group_mock.add_argument.assert_any_call(CLILogging.VERBOSE_FLAG, dest=mock.ANY, action=mock.ANY,
                                                           help=mock.ANY)
        parser_arg_group_mock.add_argument.assert_any_call(CLILogging.DEBUG_FLAG, dest=mock.ANY, action=mock.ANY,
                                                           help=mock.ANY)
Example #3
0
class TestQueryEventHandling(unittest.TestCase):

    def setUp(self):
        self.mock_ctx = MockContext()
        self.cli_query = CLIQuery(cli_ctx=self.mock_ctx)

    def test_cli_ctx_type_error(self):
        with self.assertRaises(TypeError):
            CLIQuery(cli_ctx=object())

    def test_query_argument_registrations(self):
        parser_arg_group_mock = mock.MagicMock()
        self.mock_ctx.raise_event(EVENT_PARSER_GLOBAL_CREATE, arg_group=parser_arg_group_mock)
        parser_arg_group_mock.add_argument.assert_any_call('--query',
                                                           metavar=mock.ANY,
                                                           dest=mock.ANY,
                                                           help=mock.ANY,
                                                           type=mock.ANY)