Exemplo n.º 1
0
    def test__get_version_info_loggers(self):
        mock_loggers = {
            'versionfinder': Mock(),
            'pip': Mock(),
            'git': Mock()
        }

        def se_getLogger(lname):
            return mock_loggers[lname]

        with patch('awslimitchecker.version.logging.getLogger') as mock_logger:
            mock_logger.side_effect = se_getLogger
            with patch.dict(
                'awslimitchecker.version.os.environ', {}, clear=True
            ):
                with patch('awslimitchecker.version.find_version'):
                    version._get_version_info()
        assert mock_logger.mock_calls == [
            call('versionfinder'),
            call('pip'),
            call('git')
        ]
        assert mock_loggers['versionfinder'].mock_calls == [
            call.setLevel(CRITICAL)
        ]
        assert mock_loggers['pip'].mock_calls == [
            call.setLevel(CRITICAL)
        ]
        assert mock_loggers['git'].mock_calls == [
            call.setLevel(CRITICAL)
        ]
Exemplo n.º 2
0
    def test_console_entry_point_verbose2(self):
        argv = ['/tmp/rebuildbot/runner.py', '-vv', 'bktname']
        with patch.object(sys, 'argv', argv):
            with patch('%s.ReBuildBot' % pbm) as mock_bot, \
                 patch('%s.logger' % pbm) as mock_logger, \
                 patch('%s.logging.Formatter' % pbm) as mock_formatter, \
                 patch('%s.capture_handler' % pbm) as mock_cap_handler, \
                 patch('%s.log_capture_string' % pbm) as mock_lcs:
                mock_handler = Mock()
                mock_handler2 = Mock()
                type(mock_logger).handlers = [mock_handler, mock_handler2]
                self.cls.console_entry_point()
        assert mock_bot.mock_calls == [
            call('bktname', s3_prefix='rebuildbot', dry_run=False,
                 date_check=True, run_travis=True, run_local=True,
                 log_buffer=mock_lcs),
            call().run(projects=None)
        ]

        FORMAT = "[%(levelname)s %(filename)s:%(lineno)s - " \
                 "%(name)s.%(funcName)s() ] %(message)s"
        assert mock_formatter.mock_calls == [call(fmt=FORMAT)]
        assert mock_handler.mock_calls == [
            call.setFormatter(mock_formatter.return_value)
        ]
        assert mock_handler2.mock_calls == [
            call.setFormatter(mock_formatter.return_value)
        ]
        assert mock_logger.mock_calls == [
            call.setLevel(logging.DEBUG)
        ]
        assert mock_cap_handler.mock_calls == [
            call.setLevel(logging.DEBUG)
        ]
Exemplo n.º 3
0
    def test_upper_level(self, logger_obj, handler_cls):
        handler = Mock()
        handler.configure_mock(level=logging.INFO)
        handler_cls.return_value = handler

        with log_helpers.QuietLogger(logging.WARNING):
            log_helpers.logger.warning('Test')

        handler.assert_has_calls(
            (call.setLevel(logging.WARNING + 1), call.setLevel(logging.INFO)))

        logger_obj.assert_has_calls((call.warning('Test'), ))
    def test_upper_level(self, logger_obj, handler_cls):
        handler = Mock()
        handler.configure_mock(level=logging.INFO)
        handler_cls.return_value = handler

        with log_helpers.QuietLogger(logging.WARNING):
            log_helpers.logger.warning('Test')

        handler.assert_has_calls((
            call.setLevel(logging.WARNING + 1),
            call.setLevel(logging.INFO)
        ))

        logger_obj.assert_has_calls((call.warning('Test'), ))
Exemplo n.º 5
0
 def test_set_log_level_format(self):
     mock_handler = Mock(spec_set=logging.Handler)
     with patch('%s.logger' % pbm) as mock_logger:
         with patch('%s.logging.Formatter' % pbm) as mock_formatter:
             type(mock_logger).handlers = [mock_handler]
             set_log_level_format(5, 'foo')
     assert mock_formatter.mock_calls == [call(fmt='foo')]
     assert mock_handler.mock_calls == [
         call.setFormatter(mock_formatter.return_value)
     ]
     assert mock_logger.mock_calls == [call.setLevel(5)]
Exemplo n.º 6
0
 def test_console_entry_point_verbose1(self):
     argv = ['/tmp/rebuildbot/runner.py', '-v', 'bktname']
     with patch.object(sys, 'argv', argv):
         with patch('%s.ReBuildBot' % pbm) as mock_bot, \
              patch('%s.logger' % pbm) as mock_logger, \
              patch('%s.capture_handler' % pbm) as mock_cap_handler, \
              patch('%s.log_capture_string' % pbm) as mock_lcs:
             self.cls.console_entry_point()
     assert mock_bot.mock_calls == [
         call('bktname', s3_prefix='rebuildbot', dry_run=False,
              date_check=True, run_travis=True, run_local=True,
              log_buffer=mock_lcs),
         call().run(projects=None)
     ]
     assert mock_logger.mock_calls == [
         call.setLevel(logging.INFO)
     ]
     assert mock_cap_handler.mock_calls == [
         call.setLevel(logging.INFO)
     ]
Exemplo n.º 7
0
 def test_init(self):
     m_pip_logger = Mock()
     with patch('%s.inspect.stack' % pbm, autospec=True) as m_stack:
         with patch('%s.logger' % pbm, autospec=True) as m_logger:
             with patch('%s.logging.getLogger' % pbm,
                        autospec=True) as m_log_pip:
                 m_log_pip.return_value = m_pip_logger
                 cls = VersionFinder('foobar',
                                     package_file='/foo/bar/baz.py')
     assert m_stack.mock_calls == []
     assert cls.package_name == 'foobar'
     assert cls.package_file == '/foo/bar/baz.py'
     assert cls.package_dir == '/foo/bar'
     assert m_logger.mock_calls == [
         call.setLevel(logging.CRITICAL),
         call.debug('Finding package version for: %s', 'foobar'),
         call.debug('Explicit package file: %s', '/foo/bar/baz.py'),
         call.debug('package_dir: /foo/bar')
     ]
     assert m_log_pip.mock_calls == [call('pip')]
     assert m_pip_logger.mock_calls == [call.setLevel(logging.CRITICAL)]
Exemplo n.º 8
0
    def test__get_version_info_loggers(self):
        mock_loggers = {'versionfinder': Mock(), 'pip': Mock(), 'git': Mock()}

        def se_getLogger(lname):
            return mock_loggers[lname]

        with patch('awslimitchecker.version.logging.getLogger') as mock_logger:
            mock_logger.side_effect = se_getLogger
            with patch.dict('awslimitchecker.version.os.environ', {},
                            clear=True):
                with patch('awslimitchecker.version.find_version'):
                    version._get_version_info()
        assert mock_logger.mock_calls == [
            call('versionfinder'),
            call('pip'), call('git')
        ]
        assert mock_loggers['versionfinder'].mock_calls == [
            call.setLevel(CRITICAL)
        ]
        assert mock_loggers['pip'].mock_calls == [call.setLevel(CRITICAL)]
        assert mock_loggers['git'].mock_calls == [call.setLevel(CRITICAL)]
Exemplo n.º 9
0
 def test_set_log_level_format(self):
     mock_handler = Mock(spec_set=logging.Handler)
     with patch('%s.logger' % pbm) as mock_logger:
         with patch('%s.logging.Formatter' % pbm) as mock_formatter:
             type(mock_logger).handlers = [mock_handler]
             set_log_level_format(5, 'foo')
     assert mock_formatter.mock_calls == [
         call(fmt='foo')
     ]
     assert mock_handler.mock_calls == [
         call.setFormatter(mock_formatter.return_value)
     ]
     assert mock_logger.mock_calls == [
         call.setLevel(5)
     ]
Exemplo n.º 10
0
    def test_lower_level(self, logger_obj, handler_cls):
        handler = Mock()
        handler.configure_mock(level=logging.INFO)
        handler_cls.return_value = handler

        with log_helpers.QuietLogger(logging.DEBUG):
            log_helpers.logger.warning('Test')

        handler.assert_has_calls((call.setLevel(logging.INFO), ))

        logger_obj.assert_has_calls((
            call.debug(
                'QuietLogger requested lower level, than is already set. '
                'Not changing level'),
            call.warning('Test'),
        ))
Exemplo n.º 11
0
 def test_set_log_level_format(self):
     mock_log = Mock(spec_set=logging.Logger)
     mock_handler = Mock(spec_set=logging.Handler)
     type(mock_log).handlers = [mock_handler]
     with patch(
         '%s.logging.Formatter' % pbm, autospec=True
     ) as mock_formatter:
         set_log_level_format(mock_log, 5, 'foo')
     assert mock_formatter.mock_calls == [
         call(fmt='foo')
     ]
     assert mock_handler.mock_calls == [
         call.setFormatter(mock_formatter.return_value)
     ]
     assert mock_log.mock_calls == [
         call.setLevel(5)
     ]
    def test_lower_level(self, logger_obj, handler_cls):
        handler = Mock()
        handler.configure_mock(level=logging.INFO)
        handler_cls.return_value = handler

        with log_helpers.QuietLogger(logging.DEBUG):
            log_helpers.logger.warning('Test')

        handler.assert_has_calls((
            call.setLevel(logging.INFO),
        ))

        logger_obj.assert_has_calls((
            call.debug(
                'QuietLogger requested lower level, than is already set. '
                'Not changing level'),
            call.warning('Test'),
        ))