Files
docling-core/tests/test_base.py
Cesar Berrospi Ramis a59c38c1da chore: rename test folder to tests (#739)
test: rename 'test' folder to 'tests'

To align with other Docling repositories, use 'tests' for test modules.

Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
2026-09-04 10:49:52 +02:00

41 lines
1.3 KiB
Python

"""Test the pydantic models in module data_types.base.py."""
from datetime import datetime, timezone
import pytest
from pydantic import BaseModel, ValidationError
from docling_core.types.base import StrictDateTime
def test_strict_date_time() -> None:
"""Validate data with StrictDateTime model."""
class Model(BaseModel):
published: StrictDateTime
# allowed formats
Model(published=datetime.now(tz=timezone.utc))
data = Model(published="2022-12-01T03:49:20.724435+00:00")
assert data.published.isoformat() == "2022-12-01T03:49:20.724435+00:00"
data = Model(published="2022-12-01T03:49:20.724435+03:00")
assert data.published.isoformat() == "2022-12-01T03:49:20.724435+03:00"
data = Model(published="2022-12-01T03:49:20.724435Z")
assert data.published.isoformat() == "2022-12-01T03:49:20.724435+00:00"
data = Model(published="2022-12-01T03:49:20")
assert data.published.isoformat() == "2022-12-01T03:49:20"
data = Model(published="2022-12-01")
assert data.published.isoformat() == "2022-12-01T00:00:00"
# invalid formats
with pytest.raises(ValidationError, match="published"):
Model(published="03:49:20")
with pytest.raises(ValidationError, match="published"):
Model(published=1679616000.0)