Skip to content

Commit

Permalink
Adds basic unit tests to v.out.ogr
Browse files Browse the repository at this point in the history
  • Loading branch information
ldesousa committed Jun 16, 2024
1 parent 6d42a02 commit 5cffa26
Showing 1 changed file with 111 additions and 0 deletions.
111 changes: 111 additions & 0 deletions vector/v.out.ogr/testsuite/test_v_out_ogr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
"""Test of v.in.ogr
@author Luís Moreira de Sousa
"""

from grass.gunittest.case import TestCase
from pathlib import Path


class TestOgrExport(TestCase):

# Vector map in NC test dataset
test_map = "boundary_county"

# Result of import tests
temp_import = "test_ogr_import_map"

# Column on which to test v.univar
univar_col = "PERIMETER"

# Output of v.univar
univar_string = """n=926
nmissing=0
nnull=0
min=9.64452
max=3.70609e+06
range=3.70608e+06
sum=1.1223e+08
mean=121199
mean_abs=121199
population_stddev=342855
population_variance=1.17549e+11
population_coeff_variation=2.82886
sample_stddev=343040
sample_variance=1.17676e+11
kurtosis=33.681
skewness=4.86561
"""

@classmethod
def setUpClass(cls):
"""Use temporary region settings"""
cls.use_temp_region()

@classmethod
def tearDownClass(cls):
"""!Remove the temporary region"""
cls.del_temp_region()

def tearDown(self):
self.runModule(
"g.remove", type="vector", flags="f", pattern="%s*" % self.temp_import
)
for p in Path(".").glob("%s*" % self.test_map):
p.unlink()

def test_1(self):
self.assertModule(
"v.out.ogr",
"Export to GeoPackage Format",
input=self.test_map,
output="%s.gpkg" % self.test_map,
format="GPKG",
)

self.assertModule(
"v.in.ogr",
"Import back to verify",
input="%s.gpkg" % self.test_map,
output=self.temp_import,
)

self.runModule("g.region", vector=self.temp_import)

self.assertVectorFitsUnivar(
map=self.temp_import,
reference=self.univar_string,
column=self.univar_col,
precision=1e-8,
)

def test_2(self):
self.assertModule(
"v.out.ogr",
"Export to Shapefile Format",
input=self.test_map,
output="%s.shp" % self.test_map,
format="ESRI_Shapefile",
)

self.assertModule(
"v.in.ogr",
"Import back to verify",
input="%s.shp" % self.test_map,
output=self.temp_import,
)

self.runModule("g.region", vector=self.temp_import)

self.assertVectorFitsUnivar(
map=self.temp_import,
reference=self.univar_string,
column=self.univar_col,
precision=1e-8,
)


if __name__ == "__main__":
from grass.gunittest.main import test

test()

0 comments on commit 5cffa26

Please sign in to comment.