Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
khvn26 committed Mar 28, 2024
1 parent 399ea81 commit fe2b905
Showing 1 changed file with 4 additions and 44 deletions.
48 changes: 4 additions & 44 deletions api/tests/unit/util/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
from util.logging import JsonFormatter


def test_json_formatter():
def test_json_formatter__outputs_expected():
json_formatter = JsonFormatter()

log_record = logging.LogRecord(
name="test_logger",
level=logging.INFO,
pathname="test.py",
lineno=42,
msg="This is a test.",
args=(),
msg="This is a test message with args: %s and %s",
args=("arg1", "arg2"),
exc_info=None,
)
formatted_message = json_formatter.format(log_record)
Expand All @@ -25,44 +25,4 @@ def test_json_formatter():
assert "logger_name" in json_message
assert "process_id" in json_message
assert "thread_name" in json_message


def test_json_formatter_with_old_style_placeholders():
json_formatter = JsonFormatter()

log_record = logging.LogRecord(
name="test_logger",
level=logging.INFO,
pathname="example.py",
lineno=42,
msg="This is a test with old-style placeholders: %s and %s",
args=("arg1", "arg2"),
exc_info=None,
)

formatted_message = json_formatter.format(log_record)
parsed_json = json.loads(formatted_message)
assert (
parsed_json["message"]
== "This is a test with old-style placeholders: arg1 and arg2"
)


def test_json_formatter_arguments_with_new_style_placeholders():
json_formatter = JsonFormatter()
log_record = logging.LogRecord(
name="test_logger",
level=logging.INFO,
pathname="example.py",
lineno=42,
msg="This is a test with new-style placeholders: {} and {}",
args=("arg1", "arg2"),
exc_info=None,
)

formatted_message = json_formatter.format(log_record)
parsed_json = json.loads(formatted_message)
assert (
parsed_json["message"]
== "This is a test with new-style placeholders: arg1 and arg2"
)
assert json_message["message"] == "This is a test message with args: arg1 and arg2"

0 comments on commit fe2b905

Please sign in to comment.