Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lint & format io/iohandlers/tests/*.py #643

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions libpysal/io/iohandlers/tests/test_arcgis_dbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import pytest

from .... import examples as pysal_examples
from ...fileio import FileIO as psopen
from ...fileio import FileIO
from ..arcgis_dbf import ArcGISDbfIO


class Testtest_ArcGISDbfIO:
class TesttestArcGISDbfIO:
def setup_method(self):
self.test_file = test_file = pysal_examples.get_path("arcgis_ohio.dbf")
self.obj = ArcGISDbfIO(test_file, "r")
Expand Down Expand Up @@ -52,10 +52,10 @@ def test_write(self):
f = tempfile.NamedTemporaryFile(suffix=".dbf")
fname = f.name
f.close()
o = psopen(fname, "w", "arcgis_dbf")
o = FileIO(fname, "w", "arcgis_dbf")
o.write(w)
o.close()
f = psopen(fname, "r", "arcgis_dbf")
f = FileIO(fname, "r", "arcgis_dbf")
wnew = f.read()
f.close()
assert wnew.pct_nonzero == w.pct_nonzero
Expand Down
8 changes: 4 additions & 4 deletions libpysal/io/iohandlers/tests/test_arcgis_swm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import pytest

from .... import examples as pysal_examples
from ...fileio import FileIO as psopen
from ...fileio import FileIO
from ..arcgis_swm import ArcGISSwmIO


class Testtest_ArcGISSwmIO:
class TesttestArcGISSwmIO:
def setup_method(self):
self.test_file = test_file = pysal_examples.get_path("ohio.swm")
self.obj = ArcGISSwmIO(test_file, "r")
Expand All @@ -35,9 +35,9 @@ def test_write(self):
f = tempfile.NamedTemporaryFile(suffix=".swm")
fname = f.name
f.close()
o = psopen(fname, "w")
o = FileIO(fname, "w")
o.write(w)
o.close()
wnew = psopen(fname, "r").read()
wnew = FileIO(fname, "r").read()
assert wnew.pct_nonzero == w.pct_nonzero
os.remove(fname)
26 changes: 13 additions & 13 deletions libpysal/io/iohandlers/tests/test_arcgis_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import pytest

from .... import examples as pysal_examples
from ...fileio import FileIO as psopen
from ...fileio import FileIO
from ..arcgis_txt import ArcGISTextIO


class Testtest_ArcGISTextIO:
class TesttestArcGISTextIO:
def setup_method(self):
self.test_file = test_file = pysal_examples.get_path("arcgis_txt.txt")
self.obj = ArcGISTextIO(test_file, "r")
Expand All @@ -26,9 +26,9 @@ def test_read(self):
if len(warn) > 0:
assert issubclass(warn[0].category, RuntimeWarning)
assert (
"DBF relating to ArcGIS TEXT was not found, proceeding with unordered string IDs."
in str(warn[0].message)
)
"DBF relating to ArcGIS TEXT was not found, "
"proceeding with unordered string IDs."
) in str(warn[0].message)
assert w.n == 3
assert w.mean_neighbors == 2.0
assert [0.1, 0.05] == list(w[2].values())
Expand All @@ -46,23 +46,23 @@ def test_write(self):
if len(warn) > 0:
assert issubclass(warn[0].category, RuntimeWarning)
assert (
"DBF relating to ArcGIS TEXT was not found, proceeding with unordered string IDs."
in str(warn[0].message)
)
"DBF relating to ArcGIS TEXT was not found, "
"proceeding with unordered string IDs."
) in str(warn[0].message)
f = tempfile.NamedTemporaryFile(suffix=".txt")
fname = f.name
f.close()
o = psopen(fname, "w", "arcgis_text")
o = FileIO(fname, "w", "arcgis_text")
o.write(w)
o.close()
with warnings.catch_warnings(record=True) as warn:
warnings.simplefilter("always")
wnew = psopen(fname, "r", "arcgis_text").read()
wnew = FileIO(fname, "r", "arcgis_text").read()
if len(warn) > 0:
assert issubclass(warn[0].category, RuntimeWarning)
assert (
"DBF relating to ArcGIS TEXT was not found, proceeding with unordered string IDs."
in str(warn[0].message)
)
"DBF relating to ArcGIS TEXT was not found, "
"proceeding with unordered string IDs."
) in str(warn[0].message)
assert wnew.pct_nonzero == w.pct_nonzero
os.remove(fname)
20 changes: 7 additions & 13 deletions libpysal/io/iohandlers/tests/test_csvWrapper.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from sys import version as V
# ruff: noqa: N999

from .... import examples as pysal_examples
from ...util import WKTParser
from .. import csvWrapper

PY3 = int(V[0]) > 2


class TesttestCsvWrapper:
def setup_method(self):
Expand Down Expand Up @@ -38,10 +36,10 @@ def test_read(self):
objs = self.obj.read()
assert len(objs) == 78
self.obj.seek(0)
objsB = list(self.obj)
assert len(objsB) == 78
for rowA, rowB in zip(objs, objsB):
assert rowA == rowB
objs_b = list(self.obj)
assert len(objs_b) == 78
for row_a, row_b in zip(objs, objs_b, strict=True):
assert row_a == row_b

def test_casting(self):
self.obj.cast("WKT", WKTParser())
Expand All @@ -63,12 +61,8 @@ def test_casting(self):
(-89.4927978515625, 39.980186462402344),
(-89.585220336914062, 39.978794097900391),
]
if PY3:
for i, pt in enumerate(self.obj.__next__()[0].vertices):
assert pt[:] == verts[i]
else:
for i, pt in enumerate(self.obj.next()[0].vertices):
assert pt[:] == verts[i]
for i, pt in enumerate(self.obj.__next__()[0].vertices):
assert pt[:] == verts[i]

def test_by_col(self):
for field in self.obj.header:
Expand Down
8 changes: 4 additions & 4 deletions libpysal/io/iohandlers/tests/test_dat.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import pytest

from .... import examples as pysal_examples
from ...fileio import FileIO as psopen
from ...fileio import FileIO
from ..dat import DatIO


class Testtest_DatIO:
class TesttestDatIO:
def setup_method(self):
self.test_file = test_file = pysal_examples.get_path("wmat.dat")
self.obj = DatIO(test_file, "r")
Expand All @@ -35,9 +35,9 @@ def test_write(self):
f = tempfile.NamedTemporaryFile(suffix=".dat")
fname = f.name
f.close()
o = psopen(fname, "w")
o = FileIO(fname, "w")
o.write(w)
o.close()
wnew = psopen(fname, "r").read()
wnew = FileIO(fname, "r").read()
assert wnew.pct_nonzero == w.pct_nonzero
os.remove(fname)
7 changes: 4 additions & 3 deletions libpysal/io/iohandlers/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .... import examples as pysal_examples
from ... import geotable as pdio
from ...fileio import FileIO as psopen
from ...fileio import FileIO

try:
import sqlalchemy
Expand Down Expand Up @@ -39,7 +39,8 @@ def setup_method(self):
self.conn,
index=True,
dtype={
"date": sqlalchemy.types.UnicodeText, # Should convert the df date into a true date object, just a hack again
# Should convert the df date into a true date object, just a hack again
"date": sqlalchemy.types.UnicodeText,
"dataset": sqlalchemy.types.UnicodeText,
"street": sqlalchemy.types.UnicodeText,
"intersection": sqlalchemy.types.UnicodeText,
Expand All @@ -49,7 +50,7 @@ def setup_method(self):
) # This is converted to TEXT as lowest type common sqlite

def test_deserialize(self):
db = psopen(f"sqlite:///{self.dbf}")
db = FileIO(f"sqlite:///{self.dbf}")
assert db.tables == ["newhaven"]

gj = db._get_gjson("newhaven")
Expand Down
8 changes: 4 additions & 4 deletions libpysal/io/iohandlers/tests/test_gal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import pytest

from .... import examples as pysal_examples
from ...fileio import FileIO as psopen
from ...fileio import FileIO
from ..gal import GalIO


class Testtest_GalIO:
class TesttestGalIO:
def setup_method(self):
self.test_file = test_file = pysal_examples.get_path("sids2.gal")
self.obj = GalIO(test_file, "r")
Expand Down Expand Up @@ -40,8 +40,8 @@ def test_write(self):
f = tempfile.NamedTemporaryFile(suffix=".gal")
fname = f.name
f.close()
o = psopen(fname, "w")
o = FileIO(fname, "w")
o.write(w)
o.close()
wnew = psopen(fname, "r").read()
wnew = FileIO(fname, "r").read()
assert wnew.pct_nonzero == w.pct_nonzero
8 changes: 4 additions & 4 deletions libpysal/io/iohandlers/tests/test_geobugs_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import pytest

from .... import examples as pysal_examples
from ...fileio import FileIO as psopen
from ...fileio import FileIO
from ..geobugs_txt import GeoBUGSTextIO


class Testtest_GeoBUGSTextIO:
class TesttestGeoBUGSTextIO:
def setup_method(self):
self.test_file_scot = test_file_scot = pysal_examples.get_path("geobugs_scot")
self.test_file_col = test_file_col = pysal_examples.get_path(
Expand Down Expand Up @@ -48,9 +48,9 @@ def test_write(self):
f = tempfile.NamedTemporaryFile(suffix="")
fname = f.name
f.close()
o = psopen(fname, "w", "geobugs_text")
o = FileIO(fname, "w", "geobugs_text")
o.write(w)
o.close()
wnew = psopen(fname, "r", "geobugs_text").read()
wnew = FileIO(fname, "r", "geobugs_text").read()
assert wnew.pct_nonzero == w.pct_nonzero
os.remove(fname)
6 changes: 3 additions & 3 deletions libpysal/io/iohandlers/tests/test_geoda_txt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import pytest

from .... import examples as pysal_examples
from ..geoda_txt import GeoDaTxtReader as GTR
from ..geoda_txt import GeoDaTxtReader


class Testtest_GeoDaTxtReader:
class TesttestGeoDaTxtReader:
def setup_method(self):
test_file = pysal_examples.get_path("stl_hom.txt")
self.obj = GTR(test_file, "r")
self.obj = GeoDaTxtReader(test_file, "r")

def test___init__(self):
assert self.obj.header == ["FIPSNO", "HR8488", "HR8893", "HC8488"]
Expand Down
8 changes: 4 additions & 4 deletions libpysal/io/iohandlers/tests/test_gwt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import pytest

from .... import examples as pysal_examples
from ...fileio import FileIO as psopen
from ...fileio import FileIO
from ..gwt import GwtIO


class Testtest_GwtIO:
class TesttestGwtIO:
def setup_method(self):
self.test_file = test_file = pysal_examples.get_path("juvenile.gwt")
self.obj = GwtIO(test_file, "r")
Expand Down Expand Up @@ -41,13 +41,13 @@ def test_write(self):
f = tempfile.NamedTemporaryFile(suffix=".gwt")
fname = f.name
f.close()
o = psopen(fname, "w")
o = FileIO(fname, "w")
# copy the shapefile and ID variable names from the old gwt.
# this is only available after the read() method has been called.
# o.shpName = self.obj.shpName
# o.varName = self.obj.varName
o.write(w)
o.close()
wnew = psopen(fname, "r").read()
wnew = FileIO(fname, "r").read()
assert wnew.pct_nonzero == w.pct_nonzero
os.remove(fname)
8 changes: 4 additions & 4 deletions libpysal/io/iohandlers/tests/test_mat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import pytest

from .... import examples as pysal_examples
from ...fileio import FileIO as psopen
from ...fileio import FileIO
from ..mat import MatIO


class Testtest_MatIO:
class TesttestMatIO:
def setup_method(self):
self.test_file = test_file = pysal_examples.get_path("spat-sym-us.mat")
self.obj = MatIO(test_file, "r")
Expand All @@ -36,13 +36,13 @@ def test_write(self):
f = tempfile.NamedTemporaryFile(suffix=".mat")
fname = f.name
f.close()
o = psopen(fname, "w")
o = FileIO(fname, "w")
with warnings.catch_warnings(record=True) as warn:
warnings.simplefilter("always")
o.write(w)
if len(warn) > 0:
assert issubclass(warn[0].category, FutureWarning)
o.close()
wnew = psopen(fname, "r").read()
wnew = FileIO(fname, "r").read()
assert wnew.pct_nonzero == w.pct_nonzero
os.remove(fname)
11 changes: 6 additions & 5 deletions libpysal/io/iohandlers/tests/test_mtx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest

from .... import examples as pysal_examples
from ...fileio import FileIO as psopen
from ...fileio import FileIO
from ..mtx import MtxIO


Expand All @@ -22,8 +22,9 @@ def test_read(self):
w = self.obj.read()
assert w.n == 49
assert w.mean_neighbors == 4.7346938775510203
assert [0.33329999999999999, 0.33329999999999999, 0.33329999999999999] == \
list(w[1].values())
assert [0.33329999999999999, 0.33329999999999999, 0.33329999999999999] == list(
w[1].values()
)
s0 = w.s0
self.obj.seek(0)
wsp = self.obj.read(sparse=True)
Expand All @@ -43,10 +44,10 @@ def test_write(self):
f = tempfile.NamedTemporaryFile(suffix=".mtx")
fname = f.name
f.close()
o = psopen(fname, "w")
o = FileIO(fname, "w")
o.write(w)
o.close()
wnew = psopen(fname, "r").read(sparse=i)
wnew = FileIO(fname, "r").read(sparse=i)
if i:
assert wnew.s0 == w.s0
else:
Expand Down
Loading