You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
import pytest
|
|
from datetime import datetime, timedelta
|
|
from src.utils import parse_relative_expression, parse_date_string
|
|
|
|
def test_parse_relative_expression_days():
|
|
# Test T, T+n, T-n
|
|
result = parse_relative_expression("T")
|
|
assert result is not None
|
|
assert isinstance(result, datetime)
|
|
|
|
result_plus = parse_relative_expression("T+5")
|
|
assert result_plus is not None
|
|
|
|
result_minus = parse_relative_expression("T-3")
|
|
assert result_minus is not None
|
|
|
|
def test_parse_relative_expression_invalid():
|
|
assert parse_relative_expression("abc") is None
|
|
assert parse_relative_expression("123") is None
|
|
assert parse_relative_expression("T++1") is None
|
|
|
|
def test_parse_date_string_formats():
|
|
# Test various ISO and common formats
|
|
dt = parse_date_string("2024-11-08")
|
|
assert dt.year == 2024
|
|
assert dt.month == 11
|
|
assert dt.day == 8
|
|
|
|
dt = parse_date_string("08-11-2024")
|
|
assert dt.year == 2024
|
|
assert dt.month == 11
|
|
assert dt.day == 8
|
|
|
|
def test_parse_date_string_invalid():
|
|
with pytest.raises(ValueError):
|
|
parse_date_string("invalid-date")
|