From 5cffa26034cfea841ae6d116abc6f04c5ac81b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Sun, 16 Jun 2024 13:04:15 +0200 Subject: [PATCH 01/18] Adds basic unit tests to v.out.ogr --- vector/v.out.ogr/testsuite/test_v_out_ogr.py | 111 +++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 vector/v.out.ogr/testsuite/test_v_out_ogr.py diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py new file mode 100644 index 00000000000..ecb4776c7e2 --- /dev/null +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -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() From 47d256ba9d5e488d32bea1c244ae7a853558a5c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Mon, 17 Jun 2024 11:32:07 +0200 Subject: [PATCH 02/18] Closes #2187 --- vector/v.out.ogr/main.c | 1 - vector/v.out.ogr/testsuite/ESRI54052.wkt | 63 ++++++++++++++++++ vector/v.out.ogr/testsuite/test_v_out_ogr.py | 69 +++++++++++++++++++- 3 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 vector/v.out.ogr/testsuite/ESRI54052.wkt diff --git a/vector/v.out.ogr/main.c b/vector/v.out.ogr/main.c index 788d27a3665..6a961c37a10 100644 --- a/vector/v.out.ogr/main.c +++ b/vector/v.out.ogr/main.c @@ -324,7 +324,6 @@ int main(int argc, char *argv[]) inwkt = NULL; } proj_destroy(source_crs); - Ogr_projection = NULL; if (inwkt) { char *inwkttmp = inwkt; diff --git a/vector/v.out.ogr/testsuite/ESRI54052.wkt b/vector/v.out.ogr/testsuite/ESRI54052.wkt new file mode 100644 index 00000000000..9bfdc68b945 --- /dev/null +++ b/vector/v.out.ogr/testsuite/ESRI54052.wkt @@ -0,0 +1,63 @@ +BOUNDCRS[ + SOURCECRS[ + PROJCRS["unknown", + BASEGEOGCRS["wgs84", + DATUM["World Geodetic System 1984", + ELLIPSOID["WGS_1984",6378137,298.257223563, + LENGTHUNIT["metre",1, + ID["EPSG",9001]]]], + PRIMEM["Greenwich",0, + ANGLEUNIT["degree",0.0174532925199433], + ID["EPSG",8901]]], + CONVERSION["unnamed", + METHOD["Interrupted Goode Homolosine"], + PARAMETER["Longitude of natural origin",0, + ANGLEUNIT["degree",0.0174532925199433], + ID["EPSG",8802]], + PARAMETER["False easting",0, + LENGTHUNIT["metre",1], + ID["EPSG",8806]], + PARAMETER["False northing",0, + LENGTHUNIT["metre",1], + ID["EPSG",8807]]], + CS[Cartesian,2], + AXIS["easting",east, + ORDER[1], + LENGTHUNIT["metre",1, + ID["EPSG",9001]]], + AXIS["northing",north, + ORDER[2], + LENGTHUNIT["metre",1, + ID["EPSG",9001]]]]], + TARGETCRS[ + GEOGCRS["WGS 84", + DATUM["World Geodetic System 1984", + ELLIPSOID["WGS 84",6378137,298.257223563, + LENGTHUNIT["metre",1]]], + PRIMEM["Greenwich",0, + ANGLEUNIT["degree",0.0174532925199433]], + CS[ellipsoidal,2], + AXIS["latitude",north, + ORDER[1], + ANGLEUNIT["degree",0.0174532925199433]], + AXIS["longitude",east, + ORDER[2], + ANGLEUNIT["degree",0.0174532925199433]], + ID["EPSG",4326]]], + ABRIDGEDTRANSFORMATION["Transformation from wgs84 to WGS84", + METHOD["Position Vector transformation (geog2D domain)", + ID["EPSG",9606]], + PARAMETER["X-axis translation",0, + ID["EPSG",8605]], + PARAMETER["Y-axis translation",0, + ID["EPSG",8606]], + PARAMETER["Z-axis translation",0, + ID["EPSG",8607]], + PARAMETER["X-axis rotation",0, + ID["EPSG",8608]], + PARAMETER["Y-axis rotation",0, + ID["EPSG",8609]], + PARAMETER["Z-axis rotation",0, + ID["EPSG",8610]], + PARAMETER["Scale difference",1, + ID["EPSG",8611]]]] diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py index ecb4776c7e2..6a7155f8b45 100644 --- a/vector/v.out.ogr/testsuite/test_v_out_ogr.py +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -3,8 +3,10 @@ @author Luís Moreira de Sousa """ +import grass.script as gs from grass.gunittest.case import TestCase from pathlib import Path +from shutil import rmtree class TestOgrExport(TestCase): @@ -15,6 +17,15 @@ class TestOgrExport(TestCase): # Result of import tests temp_import = "test_ogr_import_map" + # Temporary location + temp_location = "temp_location" + + # Temporary Homolosine map + temp_54052 = "temp_rand.gpkg" + + # Temporary environment file + session_file = "" + # Column on which to test v.univar univar_col = "PERIMETER" @@ -42,17 +53,35 @@ 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): + + # Remove maps in temp mapset self.runModule( - "g.remove", type="vector", flags="f", pattern="%s*" % self.temp_import + "g.remove", type="vector", flags="f", + pattern="%s*" % self.temp_import ) + + # Remove temporary files for p in Path(".").glob("%s*" % self.test_map): p.unlink() + for p in Path(".").glob("%s*" % self.temp_54052): + p.unlink() + if len(self.session_file) > 0: + Path(self.session_file).unlink() + + # Remove temporary location + env = gs.parse_command("g.gisenv") + rmtree("%s/%s" % (env["GISDBASE"].replace('\'', '').replace(';', ''), + self.temp_location), + ignore_errors=True) + def test_1(self): self.assertModule( @@ -104,6 +133,44 @@ def test_2(self): precision=1e-8, ) + def test_3(self): + + # Record original location to return later + env_orig = gs.parse_command("g.gisenv") + + # Create new location with CRS without EPSG code + gs.run_command( + "g.proj", + wkt="ESRI54052.wkt", + location=self.temp_location, + flags="c" + ) + + self.session_file, env_new = gs.core.create_environment( + env_orig["GISDBASE"].replace('\'', '').replace(';', ''), + self.temp_location, + "PERMANENT" + ) + + # Creates a random layer to test output + gs.run_command( + "v.random", + output="temp_rand", + npoints=3, + env=env_new + ) + + # Test output of a vector with non-EPSG CRS + gs.run_command( + "v.out.ogr", + input="temp_rand", + output=self.temp_54052, + format="GPKG", + dsco="a_srs=ESRI:54052", + env=env_new + + ) + if __name__ == "__main__": from grass.gunittest.main import test From 8da3982c99e8d5bee0bd0ace02439e4a7b43aab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Mon, 17 Jun 2024 11:52:48 +0200 Subject: [PATCH 03/18] Restricts use of assertModule method --- vector/v.out.ogr/testsuite/test_v_out_ogr.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py index ecb4776c7e2..53114d3bb2d 100644 --- a/vector/v.out.ogr/testsuite/test_v_out_ogr.py +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -63,9 +63,9 @@ def test_1(self): format="GPKG", ) - self.assertModule( + # Import back to verify + self.runModule( "v.in.ogr", - "Import back to verify", input="%s.gpkg" % self.test_map, output=self.temp_import, ) @@ -88,9 +88,9 @@ def test_2(self): format="ESRI_Shapefile", ) - self.assertModule( + # Import back to verify + self.runModule( "v.in.ogr", - "Import back to verify", input="%s.shp" % self.test_map, output=self.temp_import, ) From 36caea6673df0b97e1f35b32a4a188ece7ebedfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Mon, 17 Jun 2024 12:24:20 +0200 Subject: [PATCH 04/18] Code farmatting --- vector/v.out.ogr/testsuite/test_v_out_ogr.py | 40 ++++++++------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py index 30ff244c1f7..f052283bf15 100644 --- a/vector/v.out.ogr/testsuite/test_v_out_ogr.py +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -53,19 +53,16 @@ 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): # Remove maps in temp mapset self.runModule( - "g.remove", type="vector", flags="f", - pattern="%s*" % self.temp_import + "g.remove", type="vector", flags="f", pattern="%s*" % self.temp_import ) # Remove temporary files @@ -76,14 +73,16 @@ def tearDown(self): if len(self.session_file) > 0: Path(self.session_file).unlink() - # Remove temporary location + # Remove temporary location env = gs.parse_command("g.gisenv") - rmtree("%s/%s" % (env["GISDBASE"].replace('\'', '').replace(';', ''), - self.temp_location), - ignore_errors=True) - + rmtree( + "%s/%s" + % (env["GISDBASE"].replace("'", "").replace(";", ""), self.temp_location), + ignore_errors=True, + ) def test_1(self): + self.assertModule( "v.out.ogr", "Export to GeoPackage Format", @@ -109,6 +108,7 @@ def test_1(self): ) def test_2(self): + self.assertModule( "v.out.ogr", "Export to Shapefile Format", @@ -135,30 +135,23 @@ def test_2(self): def test_3(self): - # Record original location to return later + # Record original location to use corect GISDBASE env_orig = gs.parse_command("g.gisenv") # Create new location with CRS without EPSG code gs.run_command( - "g.proj", - wkt="ESRI54052.wkt", - location=self.temp_location, - flags="c" + "g.proj", wkt="ESRI54052.wkt", location=self.temp_location, flags="c" ) + # Create new session to avoid temporary region self.session_file, env_new = gs.core.create_environment( - env_orig["GISDBASE"].replace('\'', '').replace(';', ''), + env_orig["GISDBASE"].replace("'", "").replace(";", ""), self.temp_location, - "PERMANENT" + "PERMANENT", ) # Creates a random layer to test output - gs.run_command( - "v.random", - output="temp_rand", - npoints=3, - env=env_new - ) + gs.run_command("v.random", output="temp_rand", npoints=3, env=env_new) # Test output of a vector with non-EPSG CRS gs.run_command( @@ -167,8 +160,7 @@ def test_3(self): output=self.temp_54052, format="GPKG", dsco="a_srs=ESRI:54052", - env=env_new - + env=env_new, ) From 1cb66323038063d34d5f246ce3ea6267b05da4f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Mon, 17 Jun 2024 14:29:17 +0200 Subject: [PATCH 05/18] Moves WKT file to data folder in unit test --- vector/v.out.ogr/testsuite/{ => data}/ESRI54052.wkt | 0 vector/v.out.ogr/testsuite/test_v_out_ogr.py | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename vector/v.out.ogr/testsuite/{ => data}/ESRI54052.wkt (100%) diff --git a/vector/v.out.ogr/testsuite/ESRI54052.wkt b/vector/v.out.ogr/testsuite/data/ESRI54052.wkt similarity index 100% rename from vector/v.out.ogr/testsuite/ESRI54052.wkt rename to vector/v.out.ogr/testsuite/data/ESRI54052.wkt diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py index f052283bf15..4ca6b74d1d6 100644 --- a/vector/v.out.ogr/testsuite/test_v_out_ogr.py +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -140,7 +140,7 @@ def test_3(self): # Create new location with CRS without EPSG code gs.run_command( - "g.proj", wkt="ESRI54052.wkt", location=self.temp_location, flags="c" + "g.proj", wkt="data/ESRI54052.wkt", location=self.temp_location, flags="c" ) # Create new session to avoid temporary region From 0b95ec4b6d2adec5c333993a515fc117a8b9ccf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Tue, 18 Jun 2024 14:46:33 +0200 Subject: [PATCH 06/18] Improves code standards with pylint suggestions --- vector/v.out.ogr/testsuite/test_v_out_ogr.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py index 53114d3bb2d..357a5248cc0 100644 --- a/vector/v.out.ogr/testsuite/test_v_out_ogr.py +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -3,8 +3,8 @@ @author Luís Moreira de Sousa """ -from grass.gunittest.case import TestCase from pathlib import Path +from grass.gunittest.case import TestCase class TestOgrExport(TestCase): @@ -49,9 +49,9 @@ def tearDownClass(cls): def tearDown(self): self.runModule( - "g.remove", type="vector", flags="f", pattern="%s*" % self.temp_import + "g.remove", type="vector", flags="f", pattern=f"{self.temp_import}*" ) - for p in Path(".").glob("%s*" % self.test_map): + for p in Path(".").glob(f"{self.test_map}*"): p.unlink() def test_1(self): @@ -59,14 +59,14 @@ def test_1(self): "v.out.ogr", "Export to GeoPackage Format", input=self.test_map, - output="%s.gpkg" % self.test_map, + output=f"{self.test_map}.gpkg", format="GPKG", ) # Import back to verify self.runModule( "v.in.ogr", - input="%s.gpkg" % self.test_map, + input=f"{self.test_map}.gpkg", output=self.temp_import, ) @@ -84,14 +84,14 @@ def test_2(self): "v.out.ogr", "Export to Shapefile Format", input=self.test_map, - output="%s.shp" % self.test_map, + output=f"{self.test_map}.shp", format="ESRI_Shapefile", ) # Import back to verify self.runModule( "v.in.ogr", - input="%s.shp" % self.test_map, + input=f"{self.test_map}.shp", output=self.temp_import, ) From 5a73b5f5fb9e3b1a15eaa0f786ee13788573e309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Tue, 18 Jun 2024 15:08:19 +0200 Subject: [PATCH 07/18] Improves code standards with pylint suggestions --- vector/v.out.ogr/testsuite/test_v_out_ogr.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py index 5045891be09..d8194e15fb3 100644 --- a/vector/v.out.ogr/testsuite/test_v_out_ogr.py +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -67,18 +67,15 @@ def tearDown(self): # Remove temporary files for p in Path(".").glob(f"{self.test_map}*"): p.unlink() - for p in Path(".").glob("%s*" % self.temp_54052): + for p in Path(".").glob(f"{self.temp_54052}*"): p.unlink() if len(self.session_file) > 0: Path(self.session_file).unlink() # Remove temporary location env = gs.parse_command("g.gisenv") - rmtree( - "%s/%s" - % (env["GISDBASE"].replace("'", "").replace(";", ""), self.temp_location), - ignore_errors=True, - ) + dbase = env["GISDBASE"].replace("'", "").replace(";", "") + rmtree(f"{dbase}/{self.temp_location}", ignore_errors=True) def test_1(self): From 35ba7697201921687786d10f2c86467b3e69ae95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Tue, 18 Jun 2024 19:06:02 +0200 Subject: [PATCH 08/18] Renames methods and adds doc strings --- vector/v.out.ogr/testsuite/test_v_out_ogr.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py index 357a5248cc0..1b44a6e2f7a 100644 --- a/vector/v.out.ogr/testsuite/test_v_out_ogr.py +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -54,7 +54,9 @@ def tearDown(self): for p in Path(".").glob(f"{self.test_map}*"): p.unlink() - def test_1(self): + def test_gpkg_format(self): + """Tests output to GeoPackage format""" + self.assertModule( "v.out.ogr", "Export to GeoPackage Format", @@ -79,7 +81,9 @@ def test_1(self): precision=1e-8, ) - def test_2(self): + def test_shp_format(self): + """Tests output to Shapefile format""" + self.assertModule( "v.out.ogr", "Export to Shapefile Format", From ebf444c4a1e13f18f52cb202c9d6db8e752efd39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Tue, 18 Jun 2024 19:12:52 +0200 Subject: [PATCH 09/18] Renames methods and adds doc strings --- vector/v.out.ogr/testsuite/test_v_out_ogr.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py index 79fd44cccfc..d7b1f64b51f 100644 --- a/vector/v.out.ogr/testsuite/test_v_out_ogr.py +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -131,7 +131,8 @@ def test_shp_format(self): precision=1e-8, ) - def test_3(self): + def test_no_epsg_crs(self): + """Tests output from a location/project lacking an EPSG code""" # Record original location to use corect GISDBASE env_orig = gs.parse_command("g.gisenv") From 9b293b32bbdeda88818885dbfa3dd647683db9d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Sun, 16 Jun 2024 13:04:15 +0200 Subject: [PATCH 10/18] Adds basic unit tests to v.out.ogr --- vector/v.out.ogr/testsuite/test_v_out_ogr.py | 111 +++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 vector/v.out.ogr/testsuite/test_v_out_ogr.py diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py new file mode 100644 index 00000000000..ecb4776c7e2 --- /dev/null +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -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() From 93f54294fcbf60cf9669756a22ca97a9a6991050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Mon, 17 Jun 2024 11:52:48 +0200 Subject: [PATCH 11/18] Restricts use of assertModule method --- vector/v.out.ogr/testsuite/test_v_out_ogr.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py index ecb4776c7e2..53114d3bb2d 100644 --- a/vector/v.out.ogr/testsuite/test_v_out_ogr.py +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -63,9 +63,9 @@ def test_1(self): format="GPKG", ) - self.assertModule( + # Import back to verify + self.runModule( "v.in.ogr", - "Import back to verify", input="%s.gpkg" % self.test_map, output=self.temp_import, ) @@ -88,9 +88,9 @@ def test_2(self): format="ESRI_Shapefile", ) - self.assertModule( + # Import back to verify + self.runModule( "v.in.ogr", - "Import back to verify", input="%s.shp" % self.test_map, output=self.temp_import, ) From 280997f06f4c58a1d200f6fc1c36a803ef5657ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Tue, 18 Jun 2024 14:46:33 +0200 Subject: [PATCH 12/18] Improves code standards with pylint suggestions --- vector/v.out.ogr/testsuite/test_v_out_ogr.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py index 53114d3bb2d..357a5248cc0 100644 --- a/vector/v.out.ogr/testsuite/test_v_out_ogr.py +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -3,8 +3,8 @@ @author Luís Moreira de Sousa """ -from grass.gunittest.case import TestCase from pathlib import Path +from grass.gunittest.case import TestCase class TestOgrExport(TestCase): @@ -49,9 +49,9 @@ def tearDownClass(cls): def tearDown(self): self.runModule( - "g.remove", type="vector", flags="f", pattern="%s*" % self.temp_import + "g.remove", type="vector", flags="f", pattern=f"{self.temp_import}*" ) - for p in Path(".").glob("%s*" % self.test_map): + for p in Path(".").glob(f"{self.test_map}*"): p.unlink() def test_1(self): @@ -59,14 +59,14 @@ def test_1(self): "v.out.ogr", "Export to GeoPackage Format", input=self.test_map, - output="%s.gpkg" % self.test_map, + output=f"{self.test_map}.gpkg", format="GPKG", ) # Import back to verify self.runModule( "v.in.ogr", - input="%s.gpkg" % self.test_map, + input=f"{self.test_map}.gpkg", output=self.temp_import, ) @@ -84,14 +84,14 @@ def test_2(self): "v.out.ogr", "Export to Shapefile Format", input=self.test_map, - output="%s.shp" % self.test_map, + output=f"{self.test_map}.shp", format="ESRI_Shapefile", ) # Import back to verify self.runModule( "v.in.ogr", - input="%s.shp" % self.test_map, + input=f"{self.test_map}.shp", output=self.temp_import, ) From a2ae2009ba564000bdb2c44b7ed1a9a1be179bdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Tue, 18 Jun 2024 19:06:02 +0200 Subject: [PATCH 13/18] Renames methods and adds doc strings --- vector/v.out.ogr/testsuite/test_v_out_ogr.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py index 357a5248cc0..1b44a6e2f7a 100644 --- a/vector/v.out.ogr/testsuite/test_v_out_ogr.py +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -54,7 +54,9 @@ def tearDown(self): for p in Path(".").glob(f"{self.test_map}*"): p.unlink() - def test_1(self): + def test_gpkg_format(self): + """Tests output to GeoPackage format""" + self.assertModule( "v.out.ogr", "Export to GeoPackage Format", @@ -79,7 +81,9 @@ def test_1(self): precision=1e-8, ) - def test_2(self): + def test_shp_format(self): + """Tests output to Shapefile format""" + self.assertModule( "v.out.ogr", "Export to Shapefile Format", From 1c83ffad366ef8c37e4ecc91a8df65c0c7460379 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Wed, 19 Jun 2024 12:59:09 +0200 Subject: [PATCH 14/18] Corrects typo --- vector/v.out.ogr/testsuite/test_v_out_ogr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py index 1b44a6e2f7a..1c208e913d7 100644 --- a/vector/v.out.ogr/testsuite/test_v_out_ogr.py +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -1,4 +1,4 @@ -"""Test of v.in.ogr +"""Test of v.out.ogr @author Luís Moreira de Sousa """ From 77fc48b91fddc7cb2797b7b1b8a17a1c0f2634a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Wed, 31 Jul 2024 17:43:08 +0100 Subject: [PATCH 15/18] Updates vector/v.out.ogr/testsuite/test_v_out_ogr.py with Ruff suggestion Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- vector/v.out.ogr/testsuite/test_v_out_ogr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py index 6b2a964fb1e..18d511234f3 100644 --- a/vector/v.out.ogr/testsuite/test_v_out_ogr.py +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -65,7 +65,7 @@ def tearDown(self): "g.remove", type="vector", flags="f", pattern=f"{self.temp_import}*" ) # Remove temporary files - for p in Path(".").glob(f"{self.test_map}*"): + for p in Path().glob(f"{self.test_map}*"): p.unlink() for p in Path(".").glob(f"{self.temp_54052}*"): p.unlink() From a076bbcc5a576d99fe5ab0ac7e00ede162570647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Wed, 31 Jul 2024 17:43:26 +0100 Subject: [PATCH 16/18] Updates vector/v.out.ogr/testsuite/test_v_out_ogr.py with Ruff suggestion Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- vector/v.out.ogr/testsuite/test_v_out_ogr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py index 18d511234f3..2b253b89342 100644 --- a/vector/v.out.ogr/testsuite/test_v_out_ogr.py +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -67,7 +67,7 @@ def tearDown(self): # Remove temporary files for p in Path().glob(f"{self.test_map}*"): p.unlink() - for p in Path(".").glob(f"{self.temp_54052}*"): + for p in Path().glob(f"{self.temp_54052}*"): p.unlink() if len(self.session_file) > 0: Path(self.session_file).unlink() From b46fb05bdc26984637002c2efd543165542256d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Thu, 29 Aug 2024 16:00:30 +0100 Subject: [PATCH 17/18] Update vector/v.out.ogr/testsuite/test_v_out_ogr.py Co-authored-by: Vaclav Petras --- vector/v.out.ogr/testsuite/test_v_out_ogr.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py index 1bdfd0222ca..1fbd4153b3e 100644 --- a/vector/v.out.ogr/testsuite/test_v_out_ogr.py +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -55,7 +55,7 @@ def setUpClass(cls): @classmethod def tearDownClass(cls): - """!Remove the temporary region""" + """Remove the temporary region""" cls.del_temp_region() def tearDown(self): From f59f324e202aa73d7d1cc058a04943a3e43fd610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20de=20Sousa?= Date: Fri, 6 Sep 2024 17:59:43 +0100 Subject: [PATCH 18/18] Extra comments required in PR review --- vector/v.out.ogr/testsuite/test_v_out_ogr.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vector/v.out.ogr/testsuite/test_v_out_ogr.py b/vector/v.out.ogr/testsuite/test_v_out_ogr.py index 1fbd4153b3e..53ac0270a74 100644 --- a/vector/v.out.ogr/testsuite/test_v_out_ogr.py +++ b/vector/v.out.ogr/testsuite/test_v_out_ogr.py @@ -74,6 +74,7 @@ def tearDown(self): # Remove temporary location env = gs.parse_command("g.gisenv") + # Quotes and separator in environment variable string must be removed dbase = env["GISDBASE"].replace("'", "").replace(";", "") rmtree(f"{dbase}/{self.temp_location}", ignore_errors=True) @@ -143,6 +144,7 @@ def test_no_epsg_crs(self): ) # Create new session to avoid temporary region + # Quotes and separator in environment variable string must be removed self.session_file, env_new = gs.core.create_environment( env_orig["GISDBASE"].replace("'", "").replace(";", ""), self.temp_location,