Skip to content

Commit

Permalink
Logging 100% coverage. (#2248)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Jul 20, 2024
1 parent e6e9e18 commit 063f504
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from pymodbus.logging import Log
from pymodbus.logging import Log, pymodbus_apply_logging_config


class TestLogging:
Expand Down Expand Up @@ -32,10 +32,26 @@ def test_log_simple(self):
[
("string {} {} {}", "string 101 102 103", (101, 102, 103)),
("string {}", "string 0x41 0x42 0x43 0x44", (b"ABCD", ":hex")),
("string {}", "string b'41424344'", (b"ABCD", ":b2a")),
("string {}", "string 125", (125, ":str")),
],
)
def test_log_parms(self, txt, result, params):
"""Test string with parameters (old f-string)."""
log_txt = Log.build_msg(txt, *params)
assert log_txt == result

def test_apply_logging(self):
"""Test pymodbus_apply_logging_config."""

pymodbus_apply_logging_config("debug")
pymodbus_apply_logging_config(logging.NOTSET)
pymodbus_apply_logging_config("debug", "pymodbus.log")
pymodbus_apply_logging_config("info")
Log.info("test")
pymodbus_apply_logging_config("warning")
Log.warning("test")
pymodbus_apply_logging_config("critical")
Log.critical("test")
pymodbus_apply_logging_config("error")
Log.error("test")

0 comments on commit 063f504

Please sign in to comment.