Coverage for tests / test_advanced / test_datetime / test_tutorial004.py: 100%
16 statements
« prev ^ index » next coverage.py v7.13.0, created at 2026-11-09 00:02 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2026-11-09 00:02 +0000
1import importlib 1abcdefghi
2from io import StringIO 1abcdefghi
3from types import ModuleType 1abcdefghi
5import pytest 1abcdefghi
6from alembic.migration import MigrationContext 1abcdefghi
7from alembic.operations import Operations 1abcdefghi
10@pytest.fixture( 1abcdefghi
11 name="mod",
12 params=[
13 pytest.param("tutorial004_py310"),
14 ],
15)
16def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefghi
17 return importlib.import_module(f"docs_src.advanced.datetime.{request.param}") 1abcdefghi
20def test_tutorial(mod: ModuleType) -> None: 1abcdefghi
21 output = StringIO() 1jklmnopqr
22 context = MigrationContext.configure( 1jklmnopqr
23 dialect_name="postgresql",
24 opts={"as_sql": True, "output_buffer": output},
25 )
26 with Operations.context(context): 1jklmnopqr
27 mod.upgrade() 1jklmnopqr
28 mod.downgrade() 1jklmnopqr
30 assert output.getvalue() == ( 1jklmnopqr
31 "ALTER TABLE event ALTER COLUMN created_at TYPE TIMESTAMP WITH TIME ZONE "
32 "USING created_at AT TIME ZONE 'UTC';\n\n"
33 "ALTER TABLE event ALTER COLUMN created_at TYPE TIMESTAMP WITHOUT TIME ZONE "
34 "USING created_at AT TIME ZONE 'UTC';\n\n"
35 )