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.

62 lines
1.3 KiB
Python

"""Tests for date text normalization."""
from datetime import datetime, timezone
import pytest
from gimme_job.utils.dates import is_recent, normalize_posted_text
def test_today():
dt = normalize_posted_text("today")
assert dt is not None
assert dt.date() == datetime.now(timezone.utc).date()
def test_just_posted():
dt = normalize_posted_text("Just posted")
assert dt is not None
def test_1_day_ago():
dt = normalize_posted_text("1 day ago")
assert dt is not None
assert dt.date() == datetime.now(timezone.utc).date()
def test_2_days_ago():
dt = normalize_posted_text("2 days ago")
assert dt is not None
def test_hours_ago():
dt = normalize_posted_text("3 hours ago")
assert dt is not None
now = datetime.now(timezone.utc)
diff = now - dt
assert 2.9 * 3600 < diff.total_seconds() < 3.1 * 3600
def test_yesterday():
dt = normalize_posted_text("yesterday")
assert dt is not None
def test_none_input():
assert normalize_posted_text(None) is None
def test_empty_input():
assert normalize_posted_text("") is None
def test_unparseable():
assert normalize_posted_text("some random text") is None
def test_is_recent_today():
assert is_recent("today") is True
def test_is_recent_old():
assert is_recent("5 days ago", max_days=1) is False