Exemplo n.º 1
0
 def test_equal_start(self, logger):
     """Test if a filter blocks a logger which looks equal but isn't."""
     logfilter = log.LogFilter(["eggs"])
     record = self._make_record(logger, "eggsauce")
     assert not logfilter.filter(record)
     logfilter = log.LogFilter("eggs.bacon")
     record = self._make_record(logger, "eggs.baconstrips")
     assert not logfilter.filter(record)
Exemplo n.º 2
0
 def test_matching(self, logger):
     """Test if a filter lets an exactly matching log record through."""
     logfilter = log.LogFilter(["eggs", "bacon"])
     record = self._make_record(logger, "eggs")
     assert logfilter.filter(record)
     record = self._make_record(logger, "bacon")
     assert logfilter.filter(record)
     record = self._make_record(logger, "spam")
     assert not logfilter.filter(record)
     logfilter = log.LogFilter(["eggs.bacon"])
     record = self._make_record(logger, "eggs.bacon")
     assert logfilter.filter(record)
Exemplo n.º 3
0
 def test_matching(self):
     """Test if a filter lets an exactly matching logrecord through."""
     logfilter = log.LogFilter(["eggs", "bacon"])
     record = self._make_record("eggs")
     self.assertTrue(logfilter.filter(record))
     record = self._make_record("bacon")
     self.assertTrue(logfilter.filter(record))
     record = self._make_record("spam")
     self.assertFalse(logfilter.filter(record))
     logfilter = log.LogFilter(["eggs.bacon"])
     record = self._make_record("eggs.bacon")
     self.assertTrue(logfilter.filter(record))
Exemplo n.º 4
0
 def test_child(self, logger):
     """Test if a filter lets through a logger which is a child."""
     logfilter = log.LogFilter(["eggs.bacon", "spam.ham"])
     record = self._make_record(logger, "eggs.bacon.spam")
     assert logfilter.filter(record)
     record = self._make_record(logger, "spam.ham.salami")
     assert logfilter.filter(record)
Exemplo n.º 5
0
 def test_empty(self, logger):
     """Test if an empty filter lets all messages through."""
     logfilter = log.LogFilter(None)
     record = self._make_record(logger, "eggs.bacon.spam")
     assert logfilter.filter(record)
     record = self._make_record(logger, "eggs")
     assert logfilter.filter(record)
Exemplo n.º 6
0
 def test_empty(self):
     """Test if an empty filter lets all messages through."""
     logfilter = log.LogFilter(None)
     record = self._make_record("eggs.bacon.spam")
     self.assertTrue(logfilter.filter(record))
     record = self._make_record("eggs")
     self.assertTrue(logfilter.filter(record))
Exemplo n.º 7
0
    def test_logfilter(self, logger, filters, negated, category, logged):
        """Ensure the multi-record filtering filterer filters multiple records.

        (Blame @toofar for this comment)
        """
        logfilter = log.LogFilter(filters, negated=negated)
        record = self._make_record(logger, category)
        assert logfilter.filter(record) == logged
Exemplo n.º 8
0
    def test_debug_log_filter_cmd(self, monkeypatch, logger, category,
                                  logged_before, logged_after):
        """Test the :debug-log-filter command handler."""
        logfilter = log.LogFilter(["init"])
        monkeypatch.setattr(log, 'console_filter', logfilter)

        record = self._make_record(logger, category)

        assert logfilter.filter(record) == logged_before
        utilcmds.debug_log_filter('url,js')
        assert logfilter.filter(record) == logged_after
Exemplo n.º 9
0
 def test_debug(self, logger):
     """Test if messages more important than debug are never filtered."""
     logfilter = log.LogFilter(["eggs"])
     # First check if the filter works as intended with debug messages
     record = self._make_record(logger, "eggs")
     assert logfilter.filter(record)
     record = self._make_record(logger, "bacon")
     assert not logfilter.filter(record)
     # Then check if info is not filtered
     record = self._make_record(logger, "eggs", level=logging.INFO)
     assert logfilter.filter(record)
     record = self._make_record(logger, "bacon", level=logging.INFO)
     assert logfilter.filter(record)
Exemplo n.º 10
0
 def test_debug(self, logger, category):
     """Test if messages more important than debug are never filtered."""
     logfilter = log.LogFilter(['eggs'])
     record = self._make_record(logger, category, level=logging.INFO)
     assert logfilter.filter(record)
Exemplo n.º 11
0
 def test_logfilter(self, logger, filters, category, logged):
     logfilter = log.LogFilter(filters)
     record = self._make_record(logger, category)
     assert logfilter.filter(record) == logged
Exemplo n.º 12
0
 def test_debug_log_filter_cmd_invalid(self, monkeypatch):
     logfilter = log.LogFilter(set())
     monkeypatch.setattr(log, 'console_filter', logfilter)
     with pytest.raises(cmdutils.CommandError,
                        match='Invalid log category blabla'):
         utilcmds.debug_log_filter('blabla')
Exemplo n.º 13
0
 def test_debug(self, logger, only_debug):
     """Test if messages more important than debug are never filtered."""
     logfilter = log.LogFilter({'eggs'}, only_debug=only_debug)
     record = self._make_record(logger, 'bacon', level=logging.INFO)
     assert logfilter.filter(record) == only_debug
Exemplo n.º 14
0
 def test_logfilter_benchmark(self, logger, benchmark):
     record = self._make_record(logger, 'unfiltered')
     filters = set(log.LOGGER_NAMES)  # Extreme case
     logfilter = log.LogFilter(filters, negated=False)
     benchmark(lambda: logfilter.filter(record))