Some checks failed
CI/CD Pipeline / Code Quality Checks (push) Failing after 6m9s
CI/CD Pipeline / Security Scanning (push) Successful in 26s
CI/CD Pipeline / Tests (3.11) (push) Failing after 5m24s
CI/CD Pipeline / Tests (3.12) (push) Failing after 5m23s
CI/CD Pipeline / Build Docker Image (push) Has been skipped
CI/CD Pipeline / Deploy to Staging (push) Has been skipped
CI/CD Pipeline / Deploy to Production (push) Has been skipped
CI/CD Pipeline / Notification (push) Successful in 1s
49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
"""Tests for utility functions."""
|
|
|
|
from datetime import timedelta
|
|
|
|
import pytest
|
|
|
|
from guardden.utils import parse_duration
|
|
|
|
|
|
class TestParseDuration:
|
|
"""Tests for the parse_duration function."""
|
|
|
|
def test_parse_seconds(self) -> None:
|
|
"""Test parsing seconds."""
|
|
assert parse_duration("30s") == timedelta(seconds=30)
|
|
assert parse_duration("1s") == timedelta(seconds=1)
|
|
|
|
def test_parse_minutes(self) -> None:
|
|
"""Test parsing minutes."""
|
|
assert parse_duration("5m") == timedelta(minutes=5)
|
|
assert parse_duration("30m") == timedelta(minutes=30)
|
|
|
|
def test_parse_hours(self) -> None:
|
|
"""Test parsing hours."""
|
|
assert parse_duration("1h") == timedelta(hours=1)
|
|
assert parse_duration("24h") == timedelta(hours=24)
|
|
|
|
def test_parse_days(self) -> None:
|
|
"""Test parsing days."""
|
|
assert parse_duration("7d") == timedelta(days=7)
|
|
assert parse_duration("1d") == timedelta(days=1)
|
|
|
|
def test_parse_weeks(self) -> None:
|
|
"""Test parsing weeks."""
|
|
assert parse_duration("2w") == timedelta(weeks=2)
|
|
assert parse_duration("1w") == timedelta(weeks=1)
|
|
|
|
def test_invalid_format(self) -> None:
|
|
"""Test invalid duration formats."""
|
|
assert parse_duration("invalid") is None
|
|
assert parse_duration("") is None
|
|
assert parse_duration("10") is None
|
|
assert parse_duration("abc") is None
|
|
|
|
def test_case_insensitive(self) -> None:
|
|
"""Test that parsing is case insensitive."""
|
|
assert parse_duration("1H") == timedelta(hours=1)
|
|
assert parse_duration("30M") == timedelta(minutes=30)
|