Coverage for tests/test_advanced/test_datetime/test_tutorial004.py: 100%
16 statements
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-16 00:02 +0000
« prev ^ index » next coverage.py v7.17.2, created at 2026-11-16 00:02 +0000
1import importlib 1abcdefghijklm
2from io import StringIO 1abcdefghijklm
3from types import ModuleType 1abcdefghijklm
5import pytest 1abcdefghijklm
6from alembic.migration import MigrationContext 1abcdefghijklm
7from alembic.operations import Operations 1abcdefghijklm
10@pytest.fixture( 1abcdefghijklm
11 name="mod",
12 params=[
13 pytest.param("tutorial004"),
14 ],
15)
16def get_module(request: pytest.FixtureRequest) -> ModuleType: 1abcdefghijklm
17 return importlib.import_module(f"docs_src.advanced.datetime.{request.param}") 1abcdefghijklm
20def test_tutorial(mod: ModuleType) -> None: 1abcdefghijklm
21 output = StringIO() 1nopqrstuvwxyz
22 context = MigrationContext.configure( 1nopqrstuvwxyz
23 dialect_name="postgresql",
24 opts={"as_sql": True, "output_buffer": output},
25 )
26 with Operations.context(context): 1nopqrstuvwxyz
27 mod.upgrade() 1nopqrstuvwxyz
28 mod.downgrade() 1nopqrstuvwxyz
30 assert output.getvalue() == ( 1nopqrstuvwxyz
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 )