|
4 | 4 |
|
5 | 5 | import pytest |
6 | 6 |
|
7 | | -from pymodbus.logging import Log, pymodbus_apply_logging_config |
| 7 | +from pymodbus.logging import ( |
| 8 | + Log, |
| 9 | + pymodbus_apply_logging_config, |
| 10 | + pymodbus_get_last_frames, |
| 11 | +) |
8 | 12 |
|
9 | 13 |
|
10 | 14 | class TestLogging: |
@@ -47,31 +51,73 @@ def test_apply_logging(self): |
47 | 51 | pymodbus_apply_logging_config("info") |
48 | 52 | pymodbus_apply_logging_config(logging.NOTSET) |
49 | 53 | Log.debug("test 1no") |
| 54 | + pymodbus_apply_logging_config(logging.CRITICAL) |
| 55 | + Log.debug("test 1no") |
50 | 56 | pymodbus_apply_logging_config("debug") |
51 | 57 | Log.debug("test 1") |
52 | 58 | Log.debug("test 1") |
53 | 59 | Log.debug("test 1") |
54 | | - pymodbus_apply_logging_config(logging.NOTSET) |
| 60 | + Log.error("get frames") |
| 61 | + Log.critical("get frames") |
| 62 | + pymodbus_apply_logging_config(logging.CRITICAL) |
55 | 63 | Log.warning("test 2no") |
56 | 64 | pymodbus_apply_logging_config("warning") |
57 | 65 | Log.warning("test 2") |
58 | 66 | Log.warning("test 2") |
59 | 67 | Log.warning("test 2") |
60 | | - pymodbus_apply_logging_config(logging.NOTSET) |
| 68 | + pymodbus_apply_logging_config(logging.CRITICAL) |
61 | 69 | Log.critical("test 3no") |
62 | 70 | pymodbus_apply_logging_config("critical") |
63 | 71 | Log.critical("test 3") |
64 | 72 | Log.critical("test 3") |
65 | 73 | Log.critical("test 3") |
66 | | - pymodbus_apply_logging_config(logging.NOTSET) |
| 74 | + pymodbus_apply_logging_config(logging.CRITICAL) |
67 | 75 | Log.error("test 4no") |
68 | 76 | pymodbus_apply_logging_config("error") |
69 | 77 | Log.error("test 4") |
70 | 78 | Log.error("test 4") |
71 | 79 | Log.error("test 4") |
72 | | - pymodbus_apply_logging_config(logging.NOTSET) |
| 80 | + pymodbus_apply_logging_config(logging.CRITICAL) |
73 | 81 | Log.info("test 5no") |
74 | 82 | pymodbus_apply_logging_config("info") |
75 | 83 | Log.info("test 5") |
76 | 84 | Log.info("test 5") |
77 | 85 | Log.info("test 5") |
| 86 | + |
| 87 | + def test_apply_build_no(self): |
| 88 | + """Test pymodbus_apply_logging_config.""" |
| 89 | + with mock.patch("pymodbus.logging.Log.build_msg") as build: |
| 90 | + build.return_value = None |
| 91 | + Log.critical("test 0") |
| 92 | + pymodbus_apply_logging_config("debug") |
| 93 | + Log.debug("test 1") |
| 94 | + pymodbus_apply_logging_config("warning") |
| 95 | + Log.warning("test 2") |
| 96 | + pymodbus_apply_logging_config("critical") |
| 97 | + pymodbus_apply_logging_config("error") |
| 98 | + Log.error("test 4") |
| 99 | + pymodbus_apply_logging_config("info") |
| 100 | + Log.info("test 5") |
| 101 | + |
| 102 | + def test_log_get_frames(self): |
| 103 | + """Test get_frames.""" |
| 104 | + pymodbus_get_last_frames() |
| 105 | + for _ in range(100): |
| 106 | + Log.transport_dump(Log.SEND_DATA, b'678', b'9') |
| 107 | + pymodbus_get_last_frames() |
| 108 | + |
| 109 | + def test_transport_dump(self): |
| 110 | + """Test transport_dump.""" |
| 111 | + pymodbus_apply_logging_config("error") |
| 112 | + Log.transport_dump(Log.SEND_DATA, b'123', b'4') |
| 113 | + for _ in range(100): |
| 114 | + Log.transport_dump(Log.SEND_DATA, b'678', b'9') |
| 115 | + pymodbus_apply_logging_config("debug") |
| 116 | + Log.transport_dump(Log.SEND_DATA, b'123', b'4') |
| 117 | + |
| 118 | + def test_build_frame_log_line(self): |
| 119 | + """Test build_frame_log_line.""" |
| 120 | + Log.build_frame_log_line(Log.SEND_DATA, b'123', b'4') |
| 121 | + Log.build_frame_log_line(Log.RECV_DATA, b'123', b'4') |
| 122 | + Log.build_frame_log_line("Unknown", b'123', b'4') |
| 123 | + |
0 commit comments