|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
| 3 | +import sys |
| 4 | + |
3 | 5 | import pytest |
4 | 6 | from _pytest.fixtures import FixtureRequest |
| 7 | +from geoalchemy2 import Geography, Geometry |
5 | 8 | from sqlalchemy import BIGINT, PrimaryKeyConstraint |
6 | 9 | from sqlalchemy.dialects import postgresql |
7 | 10 | from sqlalchemy.dialects.postgresql import JSON, JSONB |
@@ -1706,3 +1709,44 @@ class TestDomainJson(Base): |
1706 | 1709 | foo: Mapped[Optional[dict]] = mapped_column(DOMAIN('domain_json', {domain_type.__name__}(astext_type=Text(length=128)), not_null=False)) |
1707 | 1710 | """, |
1708 | 1711 | ) |
| 1712 | + |
| 1713 | + |
| 1714 | +@pytest.mark.skipif( |
| 1715 | + sys.version_info < (3, 10), |
| 1716 | + reason="This test assumes GeoAlchemy2 0.18.x and above, which does not support python 3.9", |
| 1717 | +) |
| 1718 | +@pytest.mark.parametrize("engine", ["postgresql"], indirect=["engine"]) |
| 1719 | +def test_geoalchemy2_types(generator: CodeGenerator) -> None: |
| 1720 | + Table( |
| 1721 | + "spatial_table", |
| 1722 | + generator.metadata, |
| 1723 | + Column("id", INTEGER, primary_key=True), |
| 1724 | + Column("geom", Geometry("POINT", srid=4326, dimension=2), nullable=False), |
| 1725 | + Column("geog", Geography("POLYGON", dimension=2)), |
| 1726 | + ) |
| 1727 | + |
| 1728 | + validate_code( |
| 1729 | + generator.generate(), |
| 1730 | + """\ |
| 1731 | +from typing import Any, Optional |
| 1732 | +
|
| 1733 | +from geoalchemy2.types import Geography, Geometry |
| 1734 | +from sqlalchemy import Index, Integer |
| 1735 | +from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column |
| 1736 | +
|
| 1737 | +class Base(DeclarativeBase): |
| 1738 | + pass |
| 1739 | +
|
| 1740 | +
|
| 1741 | +class SpatialTable(Base): |
| 1742 | + __tablename__ = 'spatial_table' |
| 1743 | + __table_args__ = ( |
| 1744 | + Index('idx_spatial_table_geog', 'geog'), |
| 1745 | + Index('idx_spatial_table_geom', 'geom') |
| 1746 | + ) |
| 1747 | +
|
| 1748 | + id: Mapped[int] = mapped_column(Integer, primary_key=True) |
| 1749 | + geom: Mapped[Any] = mapped_column(Geometry('POINT', 4326, 2, from_text='ST_GeomFromEWKT', name='geometry', nullable=False), nullable=False) |
| 1750 | + geog: Mapped[Optional[Any]] = mapped_column(Geography('POLYGON', dimension=2, from_text='ST_GeogFromText', name='geography')) |
| 1751 | +""", |
| 1752 | + ) |
0 commit comments