Skip to content

Commit

Permalink
fxi
Browse files Browse the repository at this point in the history
  • Loading branch information
dycw committed Sep 15, 2024
1 parent a5aaa21 commit aa6207a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
17 changes: 13 additions & 4 deletions src/tests/test_loguru.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from hypothesis import given
from loguru import logger
from loguru._defaults import LOGURU_FORMAT
from loguru._recattrs import RecordFile, RecordLevel, RecordProcess, RecordThread
from pytest import CaptureFixture, mark, param, raises

Expand Down Expand Up @@ -37,7 +38,7 @@
make_slack_sink,
make_slack_sink_async,
)
from utilities.text import strip_and_dedent
from utilities.text import ensure_str, strip_and_dedent

if TYPE_CHECKING:
from collections.abc import Callable
Expand Down Expand Up @@ -222,15 +223,23 @@ def test_exit_explicit(self, *, capsys: CaptureFixture) -> None:
assert search(expected2, line2), line2

def test_exit_duration(self, *, capsys: CaptureFixture) -> None:
handler: HandlerConfiguration = {"sink": sys.stdout, "level": LogLevel.TRACE}
default_format = ensure_str(LOGURU_FORMAT)
handler: HandlerConfiguration = {
"sink": sys.stdout,
"level": LogLevel.TRACE,
"format": f"{default_format} | {{extra}}",
}
_ = logger.configure(handlers=[cast(dict[str, Any], handler)])

assert func_test_log_exit_duration(1) == 2
out = capsys.readouterr().out
line1, line2 = out.splitlines()
expected1 = self.trace + r"func_test_log_exit_duration:\d+ - ➢$"
expected1 = self.trace + r"func_test_log_exit_duration:\d+ - ➢ | {}$"
assert search(expected1, line1), line1
expected2 = self.trace + r"func_test_log_exit_duration:\d+ - ✔$"
expected2 = (
self.trace
+ r"func_test_log_exit_duration:\d+ - ✔ | {'⏲': \d:\d{2}:\d{2}\.\d{6}}$"
)
assert search(expected2, line2), line2


Expand Down
4 changes: 2 additions & 2 deletions src/tests/test_loguru_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def func_test_log_exit_explicit(x: int, /) -> int:


def func_test_log_exit_duration(x: int, /) -> int:
with log(exit_duration=0.01):
sleep(0.02)
with log(exit_duration=0.0):
sleep(0.01)
return x + 1


Expand Down
2 changes: 1 addition & 1 deletion src/utilities/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from __future__ import annotations

__version__ = "0.55.2"
__version__ = "0.55.3"
2 changes: 1 addition & 1 deletion src/utilities/loguru.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def log(
assert_never(never)
logger_exit = logger if exit_bind is None else logger.bind(**exit_bind)
logger_exit.opt(depth=depth).log(
exit_level_use, exit_message, timer=timer
exit_level_use, exit_message, **{"⏲": timer}
)


Expand Down

0 comments on commit aa6207a

Please sign in to comment.