Skip to content

Commit fedcfd3

Browse files
committed
[tool] fix(deprecation): move pythonjsonlogger.jsonlogger to pythonjsonlogger.json (#212)
1 parent 58abf4c commit fedcfd3

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

pyoaev/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from typing import Any, Callable, Dict, Iterator, List, Optional, Tuple, Union
99

1010
import requests
11-
from pythonjsonlogger import jsonlogger
11+
from pythonjsonlogger.json import JsonFormatter
1212

1313

1414
class _StdoutStream:
@@ -116,7 +116,7 @@ def validate_attrs(
116116
)
117117

118118

119-
class CustomJsonFormatter(jsonlogger.JsonFormatter):
119+
class CustomJsonFormatter(JsonFormatter):
120120
def add_fields(self, log_record, record, message_dict):
121121
super(CustomJsonFormatter, self).add_fields(log_record, record, message_dict)
122122
if not log_record.get("timestamp"):

test/test_utils.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import importlib
2+
import unittest
3+
import warnings
4+
5+
from pythonjsonlogger.json import JsonFormatter
6+
7+
import pyoaev.utils as module
8+
9+
10+
class TestUtils(unittest.TestCase):
11+
def test_custom_json_formatter_inherits_non_deprecated_formatter(self):
12+
self.assertTrue(issubclass(module.CustomJsonFormatter, JsonFormatter))
13+
14+
def test_reloading_utils_does_not_raise_jsonlogger_deprecation_warning(self):
15+
with warnings.catch_warnings(record=True) as caught:
16+
warnings.simplefilter("always")
17+
importlib.reload(module)
18+
19+
deprecation_messages = [
20+
str(warning.message)
21+
for warning in caught
22+
if issubclass(warning.category, DeprecationWarning)
23+
]
24+
self.assertFalse(
25+
any(
26+
"pythonjsonlogger.jsonlogger has been moved" in message
27+
for message in deprecation_messages
28+
)
29+
)
30+
31+
32+
if __name__ == "__main__":
33+
unittest.main()
34+

0 commit comments

Comments
 (0)