mirror of
https://github.com/wassname/geopandas.git
synced 2026-09-20 12:50:47 +08:00
Adds tests for the read_postgis methods. A tests/util.py is introduced containing some of the common code for downloading the NYC boroughs file, managing the existence of psycopg2, and connecting to a database.
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import unittest
|
|
|
|
from geopandas import GeoDataFrame, read_postgis, read_file
|
|
import tests.util
|
|
|
|
class TestIO(unittest.TestCase):
|
|
def setUp(self):
|
|
nybb_filename = tests.util.download_nybb()
|
|
self.df = read_file('/nybb_13a/nybb.shp', vfs='zip://' + nybb_filename)
|
|
|
|
def test_read_postgis_default(self):
|
|
con = tests.util.connect('test_geopandas')
|
|
if con is None or not tests.util.create_db(self.df):
|
|
raise unittest.case.SkipTest()
|
|
|
|
try:
|
|
sql = "SELECT * FROM nybb;"
|
|
df = read_postgis(sql, con)
|
|
finally:
|
|
con.close()
|
|
|
|
tests.util.validate_boro_df(self, df)
|
|
|
|
def test_read_postgis_custom_geom_col(self):
|
|
con = tests.util.connect('test_geopandas')
|
|
if con is None or not tests.util.create_db(self.df):
|
|
raise unittest.case.SkipTest()
|
|
|
|
try:
|
|
sql = """SELECT
|
|
borocode, boroname, shape_leng, shape_area,
|
|
geom AS __geometry__
|
|
FROM nybb;"""
|
|
df = read_postgis(sql, con, geom_col='__geometry__')
|
|
finally:
|
|
con.close()
|
|
|
|
tests.util.validate_boro_df(self, df)
|