Skip to content

Commit

Permalink
Added Logot.clear() method (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
etianen authored Jan 27, 2024
1 parent 003a0f8 commit 040bbcb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Import the :mod:`logot` API in your tests:

.. automethod:: assert_not_logged

.. automethod:: clear

.. autoattribute:: DEFAULT_LEVEL

.. autoattribute:: DEFAULT_LOGGER
Expand Down
7 changes: 7 additions & 0 deletions logot/_logot.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ def capturing(
logger = validate_logger(logger)
return _Capturing(self, _Handler(self, levelno=levelno), logger=logger)

def clear(self) -> None:
"""
Clears any captured logs.
"""
with self._lock:
self._queue.clear()

def assert_logged(self, log: Logged) -> None:
"""
Fails *immediately* if the expected ``log`` pattern has not arrived.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "logot"
version = "0.1.0"
version = "0.1.1"
description = "Log-based testing"
authors = ["Dave Hall <dave@etianen.com>"]
license = "MIT"
Expand Down
6 changes: 6 additions & 0 deletions tests/test_logot.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def test_capturing() -> None:
logger.setLevel(logging.NOTSET)


def test_clear(logot: Logot) -> None:
logger.info("foo bar")
logot.clear()
logot.assert_not_logged(logged.info("foo bar"))


def test_assert_logged_pass(logot: Logot) -> None:
logger.info("foo bar")
logot.assert_logged(logged.info("foo bar"))
Expand Down

0 comments on commit 040bbcb

Please sign in to comment.