|
24 | 24 | geoalchemy2 = pytest.importorskip("geoalchemy2") |
25 | 25 |
|
26 | 26 |
|
27 | | -# TODO(http://github.com/googleapis/google-cloud-python/issues/17287): Unskip once bug is resolved. |
28 | | -@pytest.mark.skip(reason="Failing in CI with AssertionError.") |
29 | 27 | def test_geoalchemy2_core(faux_conn, last_query): |
30 | 28 | """Make sure GeoAlchemy 2 Core Tutorial works as adapted to only having geometry""" |
31 | 29 | conn = faux_conn |
@@ -101,7 +99,7 @@ def test_geoalchemy2_core(faux_conn, last_query): |
101 | 99 | last_query( |
102 | 100 | "SELECT `lake`.`name` \n" |
103 | 101 | "FROM `lake` \n" |
104 | | - "WHERE ST_Contains(`lake`.`geog`, %(ST_Contains_1:geography)s)", |
| 102 | + "WHERE ST_Contains(`lake`.`geog`, %(ST_Contains_1:STRING)s)", |
105 | 103 | {"ST_Contains_1": "POINT(4 1)"}, |
106 | 104 | ) |
107 | 105 |
|
@@ -183,3 +181,32 @@ def test_calling_st_functions_that_dont_take_geographies(faux_conn, last_query): |
183 | 181 | " AS `ST_GeogFromText_1`", |
184 | 182 | dict(ST_GeogFromText_2="point(0 0)"), |
185 | 183 | ) |
| 184 | + |
| 185 | + |
| 186 | +def test_fixup_st_arguments(): |
| 187 | + from sqlalchemy_bigquery.geography import _fixup_st_arguments, GEOGRAPHY |
| 188 | + from geoalchemy2.functions import ST_Area, GenericFunction |
| 189 | + from sqlalchemy.sql.elements import BindParameter |
| 190 | + |
| 191 | + class DummyCompiler: |
| 192 | + def visit_function(self, element, **kw): |
| 193 | + return "func(param)" |
| 194 | + |
| 195 | + # Case 1: argument.type is not yet GEOGRAPHY |
| 196 | + func_element = ST_Area(BindParameter("param", "point(0 0)")) |
| 197 | + res = _fixup_st_arguments(func_element, DummyCompiler()) |
| 198 | + assert res == "func(param)" |
| 199 | + assert isinstance(func_element.clauses.clauses[0].type, GEOGRAPHY) |
| 200 | + |
| 201 | + # Case 2: argument.type is ALREADY GEOGRAPHY |
| 202 | + func_element2 = ST_Area(BindParameter("param", "point(0 0)", type_=GEOGRAPHY())) |
| 203 | + _fixup_st_arguments(func_element2, DummyCompiler()) |
| 204 | + |
| 205 | + # Case 3: function without specified argument types |
| 206 | + class ST_Unknown(GenericFunction): |
| 207 | + name = "ST_Unknown" |
| 208 | + |
| 209 | + func_element3 = ST_Unknown(BindParameter("param", "point(0 0)")) |
| 210 | + _fixup_st_arguments(func_element3, DummyCompiler()) |
| 211 | + |
| 212 | + |
0 commit comments