import datetime

from hypothesis import given
from hypothesis import strategies as st
from sqlalchemy import select

from nextline_rdb.db import DB

from .. import Model, Run
from ..strategies import st_model_run


@given(st.data())
async def test_repr(data: st.DataObject) -> None:
    async with DB(use_migration=False, model_base_class=Model) as db:
        async with db.session.begin() as session:
            model = data.draw(st_model_run(generate_traces=False))
            session.add(model)

        async with db.session() as session:
            rows = await session.scalars(select(Run))
            for row in rows:
                repr_ = repr(row)
                assert Run, datetime  # type: ignore[truthy-function]
                assert repr_ == repr(eval(repr_))
