Skip to content

Commit

Permalink
Merge pull request #44 from RTnhN/main
Browse files Browse the repository at this point in the history
Add testing for timestamp formats and CI action workflow
  • Loading branch information
ptmcg authored Sep 28, 2024
2 parents f93a5f4 + 143a4d0 commit 297fc54
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/Python Version Testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Version Testing

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
python -m pip install -r requirements.txt
- name: Test with tox
run: tox -e py
68 changes: 68 additions & 0 deletions tests/test_timestamp_formats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import pytest

from datetime import datetime, timezone, timedelta
from logmerger.timestamp_wrapper import TimestampedLineTransformer

local_time = datetime.now().astimezone()
local_tz = local_time.tzinfo


def _test_timestamp_format_parsing(string_date: str, expected_datetime: datetime):
transformer = TimestampedLineTransformer.make_transformer_from_sample_line(
string_date
)

parsed_datetime, _ = transformer(string_date)
parsed_datetime = parsed_datetime.astimezone(timezone.utc)
print(repr(string_date))
print("Parsed time :", parsed_datetime)
print("Expected time:", expected_datetime)
assert parsed_datetime == expected_datetime


@pytest.mark.parametrize(
"string_date, expected_datetime",
[
(
"2023-07-14 08:00:01,000Z Log",
datetime(2023, 7, 14, 8, 0, 1, tzinfo=timezone.utc),
),
(
"2023-07-14 08:00:01,123+0200 Log",
datetime(2023, 7, 14, 8, 0, 1, 123000, tzinfo=timezone(timedelta(hours=2))),
),
(
"2023-07-14 08:00:01.000Z Log",
datetime(2023, 7, 14, 8, 0, 1, tzinfo=timezone.utc),
),
(
"2023-07-14 08:00:01.123+0200 Log",
datetime(2023, 7, 14, 8, 0, 1, 123000, tzinfo=timezone(timedelta(hours=2))),
),
(
"2023-07-14 08:00:01 Log",
datetime(2023, 7, 14, 8, 0, 1, tzinfo=local_tz)),
(
"2023-07-14T08:00:01,000Z Log",
datetime(2023, 7, 14, 8, 0, 1, tzinfo=timezone.utc),
),
(
"Jul 14 08:00:01 Log",
datetime(datetime.now().year, 7, 14, 8, 0, 1, tzinfo=local_tz),
),
(
"1694561169.550987 Log",
datetime.fromtimestamp(1694561169.550987, tz=timezone.utc),
),
(
"1694561169550 Log",
datetime.fromtimestamp(1694561169550 / 1000, tz=timezone.utc),
),
(
"1694561169 Log",
datetime.fromtimestamp(1694561169, tz=timezone.utc),
),
],
)
def test_timestamp_format_parsing(string_date: str, expected_datetime: datetime):
_test_timestamp_format_parsing(string_date, expected_datetime)

0 comments on commit 297fc54

Please sign in to comment.