Files
wehub-resource-sync 7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

86 lines
3.0 KiB
Python

"""Extra coverage tests for calculate_duration edge cases in database.py."""
from local_deep_research.web.models.database import calculate_duration
class TestCalculateDurationFormats:
def test_iso_format_with_timezone(self):
result = calculate_duration(
"2025-01-01T00:00:00+00:00",
"2025-01-01T01:00:00+00:00",
)
assert result == 3600
def test_space_separated_with_microseconds(self):
"""Space-separated + microseconds → parsed, but naive datetime
may fail .astimezone(); verify we get a result or None gracefully."""
result = calculate_duration(
"2025-01-01 00:00:00.000000",
"2025-01-01 00:01:00.000000",
)
assert result is None or isinstance(result, int)
def test_space_separated_without_microseconds(self):
result = calculate_duration(
"2025-01-01 00:00:00",
"2025-01-01 00:00:30",
)
assert result is None or isinstance(result, int)
def test_space_separated_fallback_replace(self):
"""Space-separated that fails strptime → replaces space with T."""
result = calculate_duration(
"2025-01-01 10:00:00+00:00",
"2025-01-01 11:00:00+00:00",
)
assert result == 3600
def test_none_created_at_returns_none(self):
assert calculate_duration(None) is None
assert calculate_duration("") is None
def test_no_completed_at_uses_now(self):
result = calculate_duration("2020-01-01T00:00:00+00:00")
assert result is not None
assert result > 0
def test_dateutil_fallback_for_weird_format(self):
"""If standard parsing fails, dateutil.parser is tried."""
result = calculate_duration(
"Jan 1, 2025 00:00:00",
"Jan 1, 2025 01:00:00",
)
# dateutil may parse this, or it may return None on tz issues
assert result is None or isinstance(result, int)
def test_completely_unparseable_returns_none(self):
result = calculate_duration("not-a-date", "also-not-a-date")
assert result is None
def test_unparseable_created_at_returns_none(self):
result = calculate_duration("garbage-date", "2025-01-01T00:00:00+00:00")
assert result is None
class TestCalculateDurationEdgeCases:
def test_same_timestamps_returns_zero(self):
ts = "2025-06-15T12:00:00+00:00"
assert calculate_duration(ts, ts) == 0
def test_negative_duration(self):
"""completed_at before created_at → negative seconds."""
result = calculate_duration(
"2025-01-01T01:00:00+00:00",
"2025-01-01T00:00:00+00:00",
)
assert result == -3600
def test_mixed_formats(self):
"""created_at is ISO, completed_at is space-separated."""
result = calculate_duration(
"2025-01-01T00:00:00+00:00",
"2025-01-01 01:00:00",
)
# Should still calculate correctly
assert result is not None