Files
geopandas/tests/test_io.py
T
Jacob Wasserman 4df3679546 Add tests for io functions.
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.
2013-10-12 12:14:59 -04:00

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)