Beispiel #1
0
 def __init__(self, level: LogLevel = LogLevel.NOTSET) -> None:
     """
     Initializes the instance - basically setting the formatter to None
     and the filter list to empty.
     """
     Filterer.__init__(self)
     self._level = check_level(level)
     self.formatter: Formatter = _default_formatter
Beispiel #2
0
    def test_remove_filter_doesnt_raises_an_error_if_filter_not_in_filters(
            self):
        filter = Filter()
        filterer = Filterer()

        try:
            filterer.remove_filter(filter)
        except Exception as e:
            self.fail(f"Shouldn't raise an error. Error: {e}")
Beispiel #3
0
    def test_filter_returns_true_if_all_filters_pass(self):
        filterer = Filterer()
        filterer.filters = [
            Mock(return_value=True),
            Mock(return_value=True),
            Mock(return_value=True),
        ]
        record = Mock()

        self.assertTrue(filterer.filter(record))

        for filter in filterer.filters:
            filter.assert_called_with(record)
Beispiel #4
0
 def __init__(
     self,
     level: LogLevel = LogLevel.NOTSET,
     *,
     loop: Optional[AbstractEventLoop] = None,
 ) -> None:
     """
     Initializes the instance - basically setting the formatter to None
     and the filter list to empty.
     """
     Filterer.__init__(self)
     self._level = check_level(level)
     self.formatter: Optional[Formatter] = None
     self._loop: Optional[asyncio.AbstractEventLoop] = loop
Beispiel #5
0
    def test_filter_returns_false_if_a_filter_fails(self):
        filterer = Filterer()
        filterer.filters = [
            Mock(return_value=True),
            Mock(return_value=False),
            Mock(return_value=True),
        ]
        record = Mock()

        self.assertFalse(filterer.filter(record))

        filterer.filters[0].assert_called_with(record)
        filterer.filters[1].assert_called_with(record)
        filterer.filters[2].assert_not_called()
Beispiel #6
0
    def test_remove_filter_removes_a_registered_filter(self):
        filter = Filter()
        filterer = Filterer()

        filterer.add_filter(filter)
        filterer.remove_filter(filter)

        self.assertEqual(filterer.filters, [])
Beispiel #7
0
    def test_add_filter_adds_filter_only_once(self):
        filter = Filter()
        filterer = Filterer()

        filterer.add_filter(filter)
        self.assertEqual(filterer.filters, [filter])

        filterer.add_filter(filter)
        self.assertEqual(filterer.filters, [filter])