-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from RTnhN/main
Add testing for timestamp formats and CI action workflow
- Loading branch information
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |