Example #1
0
    def test_log_output(self, l):  # pylint: disable=blacklisted-name
        test_input = 'all=file:all'

        if VERBOSE:
            print('log filename %s' % TEST_OUTPUT_LOG)

        PywbemLoggers.create_loggers(test_input, TEST_OUTPUT_LOG)

        my_logger = get_logger(LOG_OPS_CALLS_NAME)

        self.assertNotEqual(
            my_logger, None,
            'Valid named logger %s expected.' % LOG_OPS_CALLS_NAME)
        # for name in PywbemLoggers.loggers:
        #    print(PywbemLoggers.get_logger_info(name))
        max_size = 1000
        result = 'This is fake return data'
        return_name = 'Return'
        if max_size and len(repr(result)) > max_size:
            result = '{:.{sz}s}...' \
                .format(repr(result), sz=max_size)
        else:
            result = '%s' % repr(result)

        my_logger.debug('%s: %s: %s', return_name, 'FakeMethodName', result)

        l.check(('pywbem.ops', 'DEBUG',
                 "Return: FakeMethodName: 'This is fake return data'"))
Example #2
0
 def valid_loggers_create(self,
                          input_str,
                          expected_result,
                          log_filename=None):
     """Common test to do the create loggers and test result."""
     PywbemLoggers.create_loggers(input_str, log_filename)
     self.assertEqual(PywbemLoggers.loggers, expected_result)
Example #3
0
 def parser_error_test(self, param):
     """Test for exception"""
     try:
         # pylint: disable=protected-access
         PywbemLoggers._parse_log_specs(param)
         self.fail('Param should generate exception %s' % param)
     except ValueError:
         pass
Example #4
0
 def test_create_single_logger5(self):
     """
     Create a simple logger from detailed parameter input
     """
     try:
         PywbemLoggers.create_logger('http',
                                     'file',
                                     log_filename=None,
                                     log_detail_level='mi')
         self.fail('Exception expected')
     except ValueError as ve:
         if VERBOSE:
             print('ve %s' % ve)
Example #5
0
 def test_get_logger_default(self):
     """ Test the get_logger function."""
     logger = get_logger(LOG_OPS_CALLS_NAME)
     self.assertEqual(len(logger.handlers), 1)
     log_info = PywbemLoggers.get_logger_info(LOG_OPS_CALLS_NAME)
     self.assertEqual(log_info[2], 'none')
     self.assertEqual(log_info[0], 'min')
Example #6
0
    def test_create_single_logger4(self):
        """
        Create a simple logger from detailed parameter input
        """
        PywbemLoggers.create_logger('all',
                                    'stderr',
                                    log_filename=None,
                                    log_detail_level='min')

        if VERBOSE:
            print('pywbem_loggers dict %s' % PywbemLoggers.loggers)
        expected_result = \
            {'pywbem.http': ('min', 'stderr', None),
             'pywbem.ops': ('min', 'stderr', None)}

        self.assertEqual(PywbemLoggers.loggers, expected_result)
Example #7
0
    def test_create_single_logger2(self):
        """
        Create a simple logger from detailed parameter input
        """
        PywbemLoggers.create_logger('http',
                                    'file',
                                    log_filename=TEST_OUTPUT_LOG,
                                    log_detail_level='min')

        if VERBOSE:
            print('pywbem_loggers dict %s' % PywbemLoggers.loggers)
        expected_result = \
            {'pywbem.http': ('min', 'file', TEST_OUTPUT_LOG)}

        self.assertEqual(
            PywbemLoggers.loggers, expected_result, 'Actual %s, Expected %s' %
            (PywbemLoggers.loggers, expected_result))
Example #8
0
    def test_create_single_logger1(self):
        """
        Create a simple logger
        """
        PywbemLoggers.create_logger('ops',
                                    'file',
                                    log_filename=TEST_OUTPUT_LOG,
                                    log_detail_level='min')

        if VERBOSE:
            print('pywbem_loggers dict %s' % PywbemLoggers.loggers)
        expected_result = \
            {'pywbem.ops': ('min', 'file', TEST_OUTPUT_LOG)}

        # test getting from logger variable
        self.assertEqual(PywbemLoggers.loggers, expected_result)

        # test use of __repr__
        expected_result = 'PywbemLoggers(%s)' % expected_result
        self.assertEqual(('%r' % PywbemLoggers), expected_result)
Example #9
0
 def parser_test(self, param, expected_result):
     """ Common test for successful parsing"""
     # pylint: disable=protected-access
     result = PywbemLoggers._parse_log_specs(param)
     self.assertEqual(result, expected_result)