Skip to content

Commit

Permalink
Merge pull request #10 from igrek51/9-test-failure-in-context-logger
Browse files Browse the repository at this point in the history
Add fallback case to Timezone unit test
  • Loading branch information
igrek51 authored Jul 27, 2024
2 parents 8a62f94 + 04d4fd9 commit 1c8e498
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

PYTHON_INTERPRETER ?= python3
OUTPUT_README = README.md
SHELL := /bin/bash

venv:
python3 -m venv venv &&\
Expand Down
9 changes: 7 additions & 2 deletions tests/sublog/test_context_logger.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
from time import tzset
import time

from nuclear.sublog import logger, error_handler, init_logs
from tests.asserts import MockIO
Expand All @@ -8,6 +9,7 @@
def test_context_logger():
os.environ['TZ'] = 'Europe/Warsaw'
tzset()
tz_utc = time.timezone == 0 # in case timezone chanve didn't take effect
init_logs()
logger.debug('42')
with MockIO() as mockio:
Expand All @@ -21,7 +23,10 @@ def test_context_logger():
logger.debug('42')

# datetime
mockio.assert_match('^\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\] ')
if tz_utc:
mockio.assert_match('^\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\Z] ')
else:
mockio.assert_match('^\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\] ')
# log level
mockio.assert_match(' DEBUG ')
# message with context
Expand Down Expand Up @@ -55,7 +60,7 @@ def test_root_context_logger():
mockio.assert_match_uncolor(' logged in, request_id=3735936685 user=igrek page=home$')
mockio.assert_match_uncolor(' im a root, request_id=3735936685 user=igrek$')
mockio.assert_match_uncolor(
' I\'m a pickle, cause=RuntimeError traceback=.+:47$')
' I\'m a pickle, cause=RuntimeError traceback=.+:52$')
mockio.assert_match_uncolor(' logged out, request_id=3735936685$')
mockio.assert_match_uncolor(' exited$')

Expand Down

0 comments on commit 1c8e498

Please sign in to comment.