Skip to content

Commit

Permalink
Fix typos in tests; verify test matches expected test transformer wit…
Browse files Browse the repository at this point in the history
…h test timestamp string
  • Loading branch information
ptmcg committed Sep 28, 2024
1 parent e6ae70b commit 79df496
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion logmerger/timestamp_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class YMDHMSZ(TimestampedLineTransformer):
# log files with timestamp "YYYY-MM-DD HH:MM:SS"
timestamp_pattern = r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}\s?(?:Z|[+-]\d{4})"
pattern = fr"(({timestamp_pattern})\s)"
strptime_format = datetime.fromisoformat
strptime_format = lambda _, s: datetime.strptime(s, "%Y-%m-%d %H:%M:%S%z")
has_timezone = True

def __init__(self):
Expand Down
11 changes: 7 additions & 4 deletions tests/test_timestamp_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
local_tz = local_time.tzinfo


def _test_timestamp_format_parsing(string_date: str, expected_datetime: datetime):
def _test_timestamp_format_parsing(string_date: str, expected_transformer_class_name: str, expected_datetime: datetime) -> None:
transformer = TimestampedLineTransformer.make_transformer_from_sample_line(
string_date
)

# assert that we got the expected transformer
assert type(transformer).__name__ == expected_transformer_class_name

try:
parsed_datetime, _ = transformer(string_date)
except ValueError as ve:
Expand Down Expand Up @@ -62,12 +65,12 @@ def _test_timestamp_format_parsing(string_date: str, expected_datetime: datetime
),
(
"YMDHMSZ",
"2023-07-14T08:00:01Z Log",
"2023-07-14 08:00:01Z Log",
datetime(2023, 7, 14, 8, 0, 1, tzinfo=timezone.utc),
),
(
"YMDHMSZ",
"2023-07-14T08:00:01+0200 Log",
"2023-07-14 08:00:01+0200 Log",
datetime(2023, 7, 14, 8, 0, 1, tzinfo=timezone(timedelta(hours=2))),
),
(
Expand Down Expand Up @@ -154,4 +157,4 @@ def _test_timestamp_format_parsing(string_date: str, expected_datetime: datetime
],
)
def test_timestamp_format_parsing(tz_class: str, string_date: str, expected_datetime: datetime):
_test_timestamp_format_parsing(string_date, expected_datetime)
_test_timestamp_format_parsing(string_date, tz_class, expected_datetime)

0 comments on commit 79df496

Please sign in to comment.