Skip to content

Commit

Permalink
rewriting a test to save some time
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mkeller committed Jun 1, 2022
1 parent e9ff947 commit 2f89fcb
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions test/integ/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,41 +572,33 @@ def test_variant(conn, db_parameters):


@pytest.mark.skipolddriver
def test_geography(conn, db_parameters):
def test_geography(conn_cnx):
"""Variant including JSON object."""
name_geo = random_string(5, "test_geography_")
with conn() as cnx:
cnx.cursor().execute(
f"""\
create table {name_geo} (geo geography)
"""
)
cnx.cursor().execute(
f"""\
insert into {name_geo} values ('POINT(0 0)'), ('LINESTRING(1 1, 2 2)')
"""
)
expected_data = [
{"coordinates": [0, 0], "type": "Point"},
{"coordinates": [[1, 1], [2, 2]], "type": "LineString"},
]

try:
with conn() as cnx:
c = cnx.cursor()
c.execute("alter session set GEOGRAPHY_OUTPUT_FORMAT='geoJson'")
with conn_cnx(
session_parameters={
"GEOGRAPHY_OUTPUT_FORMAT": "geoJson",
},
) as cnx:
with cnx.cursor() as cur:
cur.execute(f"create temporary table {name_geo} (geo geography)")
cur.execute(
f"insert into {name_geo} values ('POINT(0 0)'), ('LINESTRING(1 1, 2 2)')"
)
expected_data = [
{"coordinates": [0, 0], "type": "Point"},
{"coordinates": [[1, 1], [2, 2]], "type": "LineString"},
]

with cnx.cursor() as cur:
# Test with GEOGRAPHY return type
result = c.execute(f"select * from {name_geo}")
result = cur.execute(f"select * from {name_geo}")
metadata = result.description
assert FIELD_ID_TO_NAME[metadata[0].type_code] == "GEOGRAPHY"
data = result.fetchall()
for raw_data in data:
row = json.loads(raw_data[0])
assert row in expected_data
finally:
with conn() as cnx:
cnx.cursor().execute(f"drop table {name_geo}")


def test_invalid_bind_data_type(conn_cnx):
Expand Down

0 comments on commit 2f89fcb

Please sign in to comment.