fix timezone handling and logging fallback robustness
This commit is contained in:
+37
-3
@@ -5,10 +5,12 @@ Tests inventory reports, completeness reports, duplicate reports, and summary re
|
||||
|
||||
import csv
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
import pytest
|
||||
from io import StringIO
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from vlm.models import SeasonCompleteness, DuplicateGroup, VideoFile, MovieIdentity, SeriesIdentity
|
||||
from vlm.reports import (
|
||||
generate_inventory_report,
|
||||
@@ -205,12 +207,13 @@ class TestInventoryReport:
|
||||
|
||||
def test_timestamp_formatting(self):
|
||||
"""Test that timestamps are formatted as ISO 8601."""
|
||||
naive_local = datetime(2023, 6, 15, 14, 30, 45)
|
||||
files = [
|
||||
VideoFile(
|
||||
Path("/test.mkv"),
|
||||
"test.mkv",
|
||||
1000,
|
||||
datetime(2023, 6, 15, 14, 30, 45),
|
||||
naive_local,
|
||||
"movie"
|
||||
)
|
||||
]
|
||||
@@ -219,7 +222,38 @@ class TestInventoryReport:
|
||||
report = generate_inventory_report(files, "csv", library_root)
|
||||
|
||||
# Check timestamp format
|
||||
assert "2023-06-15T14:30:45" in report
|
||||
expected_utc = naive_local.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S")
|
||||
assert expected_utc in report
|
||||
|
||||
@pytest.mark.skipif(not hasattr(time, "tzset"), reason="tzset not available on this platform")
|
||||
def test_naive_timestamp_is_converted_from_local_to_utc(self, monkeypatch):
|
||||
"""Test report conversion for naive timestamps uses local timezone semantics."""
|
||||
original_tz = os.environ.get("TZ")
|
||||
try:
|
||||
monkeypatch.setenv("TZ", "Etc/GMT-2")
|
||||
time.tzset()
|
||||
|
||||
naive_local = datetime(2023, 6, 15, 14, 30, 45)
|
||||
expected_utc = naive_local.astimezone(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S")
|
||||
|
||||
files = [
|
||||
VideoFile(
|
||||
Path("/test.mkv"),
|
||||
"test.mkv",
|
||||
1000,
|
||||
naive_local,
|
||||
"movie"
|
||||
)
|
||||
]
|
||||
report = generate_inventory_report(files, "json", Path("/test"))
|
||||
data = json.loads(report)
|
||||
assert data["files"][0]["modified_timestamp"] == expected_utc
|
||||
finally:
|
||||
if original_tz is None:
|
||||
monkeypatch.delenv("TZ", raising=False)
|
||||
else:
|
||||
monkeypatch.setenv("TZ", original_tz)
|
||||
time.tzset()
|
||||
|
||||
|
||||
class TestCompletenessReport:
|
||||
|
||||
Reference in New Issue
Block a user