From f8d72569f4e4843c3c894bf38a0e37dcab655d9a Mon Sep 17 00:00:00 2001 From: Shreshth-Malik Date: Sat, 5 Oct 2024 18:38:40 -0400 Subject: [PATCH 01/12] Added test script for r.buffer --- raster/r.buffer/testsuite/test_buffer.py | 88 ++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 raster/r.buffer/testsuite/test_buffer.py diff --git a/raster/r.buffer/testsuite/test_buffer.py b/raster/r.buffer/testsuite/test_buffer.py new file mode 100644 index 00000000000..43d95f78557 --- /dev/null +++ b/raster/r.buffer/testsuite/test_buffer.py @@ -0,0 +1,88 @@ +from grass.gunittest.case import TestCase +from grass.gunittest.main import test +from grass.gunittest.gmodules import SimpleModule +import grass.script as gs + + +class TestRBuffer(TestCase): + + @classmethod + def setUpClass(cls): + cls.use_temp_region() + cls.runModule("g.region", raster="elevation") + + @classmethod + def tearDownClass(cls): + cls.del_temp_region() + + def test_buffer_creation(self): + output = "buf_test" + distances = [100, 200, 300, 400, 500] + + module = SimpleModule("r.buffer", input="elevation", output=output, + distances=distances, overwrite=True) + self.assertModule(module) + + self.assertRasterExists(output) + + expected_categories = [1] + [i + 1 for i in range(len(distances))] + + self.assertRasterMinMax( + map=output, + refmin=min(expected_categories), + refmax=max(expected_categories), + msg=("Buffer zones should have category values from 1 to " + #Checking if there are no abnormal values in the output raster map + str(max(expected_categories))) + ) + + category_values = gs.read_command("r.stats", flags="n", input=output).splitlines() + category_values = [int(line.split()[0]) for line in category_values] + + print("Category values:", category_values) + + unique_actual_categories = set(category_values) + self.assertTrue( + unique_actual_categories.issubset(set(expected_categories)), + msg=("Output categories should be a subset of expected categories: " + + str(expected_categories)) + ) + + def test_no_non_null_values(self): + null_map = "null_map" + self.runModule("r.mapcalc", expression=f"{null_map} = null()") + + output = "buf_no_non_null" + distances = [100, 200, 300] + + module = SimpleModule("r.buffer", input=null_map, output=output, + distances=distances, overwrite=True) + self.assertModule(module) + + self.assertRasterExists(output) + stats = gs.read_command("r.univar", map=output, flags="g") + self.assertIn("n=0", stats, msg="Output should have no non-NULL cells") # Checking an edge case where the input raster map is null + + def test_ignore_zero_values(self): + zero_map = "zero_map" + self.runModule("r.mapcalc", expression=f"{zero_map} = if(row() % 2 == 0, 0, 1)") + + output = "buf_ignore_zero" + distances = [100, 200] + + module = SimpleModule("r.buffer", input=zero_map, output=output, + distances=distances, flags="z", overwrite=True) + self.assertModule(module) + + self.assertRasterExists(output) + + category_values = gs.read_command("r.stats", flags="n", input=output).splitlines() + category_values = [int(line.split()[0]) for line in category_values] + + print("Category values:", category_values) + + self.assertNotIn(0, category_values, + msg="Output should not contain buffer zones around zero values") # Check if the output raster map ignored 0 values + + +if __name__ == "__main__": + test() From 7c35d81a6af1711b2db7b8af57bb1cfb7dce4b39 Mon Sep 17 00:00:00 2001 From: Shreshth-Malik Date: Tue, 8 Oct 2024 17:53:05 -0400 Subject: [PATCH 02/12] Corrected input map and added tearDown method to delete temp maps --- raster/r.buffer/testsuite/test_buffer.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/raster/r.buffer/testsuite/test_buffer.py b/raster/r.buffer/testsuite/test_buffer.py index 43d95f78557..9455e7bc298 100644 --- a/raster/r.buffer/testsuite/test_buffer.py +++ b/raster/r.buffer/testsuite/test_buffer.py @@ -9,23 +9,28 @@ class TestRBuffer(TestCase): @classmethod def setUpClass(cls): cls.use_temp_region() - cls.runModule("g.region", raster="elevation") + cls.runModule("g.region", raster="roadsmajor") @classmethod def tearDownClass(cls): cls.del_temp_region() + def tearDown(self): + # Remove temporary maps created during tests + gs.run_command('g.remove', type='raster', + name='null_map,zero_map,buf_test,buf_no_non_null,buf_ignore_zero', flags='f') + def test_buffer_creation(self): output = "buf_test" distances = [100, 200, 300, 400, 500] - module = SimpleModule("r.buffer", input="elevation", output=output, + module = SimpleModule("r.buffer", input="roadsmajor", output=output, distances=distances, overwrite=True) self.assertModule(module) self.assertRasterExists(output) - expected_categories = [1] + [i + 1 for i in range(len(distances))] + expected_categories = [1] + [i + 1 for i in range(len(distances)+1)] self.assertRasterMinMax( map=output, From cb4368f01352d367cddc5cf392e65345233bde28 Mon Sep 17 00:00:00 2001 From: Shreshth-Malik Date: Wed, 9 Oct 2024 16:15:59 -0400 Subject: [PATCH 03/12] Added pre commit fixes --- raster/r.buffer/testsuite/test_buffer.py | 69 +++++++++++++++++------- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/raster/r.buffer/testsuite/test_buffer.py b/raster/r.buffer/testsuite/test_buffer.py index 9455e7bc298..068411c64a9 100644 --- a/raster/r.buffer/testsuite/test_buffer.py +++ b/raster/r.buffer/testsuite/test_buffer.py @@ -17,30 +17,43 @@ def tearDownClass(cls): def tearDown(self): # Remove temporary maps created during tests - gs.run_command('g.remove', type='raster', - name='null_map,zero_map,buf_test,buf_no_non_null,buf_ignore_zero', flags='f') + gs.run_command( + "g.remove", + type="raster", + name="null_map,zero_map,buf_test,buf_no_non_null,buf_ignore_zero", + flags="f", + ) def test_buffer_creation(self): output = "buf_test" distances = [100, 200, 300, 400, 500] - module = SimpleModule("r.buffer", input="roadsmajor", output=output, - distances=distances, overwrite=True) + module = SimpleModule( + "r.buffer", + input="roadsmajor", + output=output, + distances=distances, + overwrite=True, + ) self.assertModule(module) self.assertRasterExists(output) - expected_categories = [1] + [i + 1 for i in range(len(distances)+1)] + expected_categories = [1] + [i + 1 for i in range(len(distances) + 1)] self.assertRasterMinMax( map=output, refmin=min(expected_categories), refmax=max(expected_categories), - msg=("Buffer zones should have category values from 1 to " + #Checking if there are no abnormal values in the output raster map - str(max(expected_categories))) + msg=( + "Buffer zones should have category values from 1 to " # Checking if there are no abnormal values in the output raster map + + str(max(expected_categories)) + ), ) - category_values = gs.read_command("r.stats", flags="n", input=output).splitlines() + category_values = gs.read_command( + "r.stats", flags="n", input=output + ).splitlines() category_values = [int(line.split()[0]) for line in category_values] print("Category values:", category_values) @@ -48,8 +61,10 @@ def test_buffer_creation(self): unique_actual_categories = set(category_values) self.assertTrue( unique_actual_categories.issubset(set(expected_categories)), - msg=("Output categories should be a subset of expected categories: " + - str(expected_categories)) + msg=( + "Output categories should be a subset of expected categories: " + + str(expected_categories) + ), ) def test_no_non_null_values(self): @@ -59,13 +74,20 @@ def test_no_non_null_values(self): output = "buf_no_non_null" distances = [100, 200, 300] - module = SimpleModule("r.buffer", input=null_map, output=output, - distances=distances, overwrite=True) + module = SimpleModule( + "r.buffer", + input=null_map, + output=output, + distances=distances, + overwrite=True, + ) self.assertModule(module) self.assertRasterExists(output) stats = gs.read_command("r.univar", map=output, flags="g") - self.assertIn("n=0", stats, msg="Output should have no non-NULL cells") # Checking an edge case where the input raster map is null + self.assertIn( + "n=0", stats, msg="Output should have no non-NULL cells" + ) # Checking an edge case where the input raster map is null def test_ignore_zero_values(self): zero_map = "zero_map" @@ -74,19 +96,30 @@ def test_ignore_zero_values(self): output = "buf_ignore_zero" distances = [100, 200] - module = SimpleModule("r.buffer", input=zero_map, output=output, - distances=distances, flags="z", overwrite=True) + module = SimpleModule( + "r.buffer", + input=zero_map, + output=output, + distances=distances, + flags="z", + overwrite=True, + ) self.assertModule(module) self.assertRasterExists(output) - category_values = gs.read_command("r.stats", flags="n", input=output).splitlines() + category_values = gs.read_command( + "r.stats", flags="n", input=output + ).splitlines() category_values = [int(line.split()[0]) for line in category_values] print("Category values:", category_values) - self.assertNotIn(0, category_values, - msg="Output should not contain buffer zones around zero values") # Check if the output raster map ignored 0 values + self.assertNotIn( + 0, + category_values, + msg="Output should not contain buffer zones around zero values", + ) # Check if the output raster map ignored 0 values if __name__ == "__main__": From b231515a10b12c94add15ab0431d5ad9efa84a24 Mon Sep 17 00:00:00 2001 From: Shreshth-Malik Date: Tue, 22 Oct 2024 21:59:47 -0400 Subject: [PATCH 04/12] Added resolution for feedback --- raster/r.buffer/testsuite/test_buffer.py | 32 +++++++----------------- 1 file changed, 9 insertions(+), 23 deletions(-) diff --git a/raster/r.buffer/testsuite/test_buffer.py b/raster/r.buffer/testsuite/test_buffer.py index 068411c64a9..c92993a49bf 100644 --- a/raster/r.buffer/testsuite/test_buffer.py +++ b/raster/r.buffer/testsuite/test_buffer.py @@ -20,7 +20,7 @@ def tearDown(self): gs.run_command( "g.remove", type="raster", - name="null_map,zero_map,buf_test,buf_no_non_null,buf_ignore_zero", + name="null_map,buf_test,consist_test,zero_map,buf_no_non_null,buf_ignore_zero", flags="f", ) @@ -39,7 +39,7 @@ def test_buffer_creation(self): self.assertRasterExists(output) - expected_categories = [1] + [i + 1 for i in range(len(distances) + 1)] + expected_categories = [i + 1 for i in range(len(distances) + 1)] self.assertRasterMinMax( map=output, @@ -51,22 +51,6 @@ def test_buffer_creation(self): ), ) - category_values = gs.read_command( - "r.stats", flags="n", input=output - ).splitlines() - category_values = [int(line.split()[0]) for line in category_values] - - print("Category values:", category_values) - - unique_actual_categories = set(category_values) - self.assertTrue( - unique_actual_categories.issubset(set(expected_categories)), - msg=( - "Output categories should be a subset of expected categories: " - + str(expected_categories) - ), - ) - def test_no_non_null_values(self): null_map = "null_map" self.runModule("r.mapcalc", expression=f"{null_map} = null()") @@ -84,10 +68,10 @@ def test_no_non_null_values(self): self.assertModule(module) self.assertRasterExists(output) - stats = gs.read_command("r.univar", map=output, flags="g") - self.assertIn( - "n=0", stats, msg="Output should have no non-NULL cells" - ) # Checking an edge case where the input raster map is null + + expected_stats = {"n": 0} + + self.assertRasterFitsUnivar(output, reference=expected_stats) def test_ignore_zero_values(self): zero_map = "zero_map" @@ -115,8 +99,10 @@ def test_ignore_zero_values(self): print("Category values:", category_values) + expected_categories = [1, 2] + self.assertNotIn( - 0, + expected_categories, category_values, msg="Output should not contain buffer zones around zero values", ) # Check if the output raster map ignored 0 values From 2d7c4ca37445e02afdc63d1e15e1e74f6999a17e Mon Sep 17 00:00:00 2001 From: Shreshth-Malik Date: Fri, 25 Oct 2024 21:30:40 -0400 Subject: [PATCH 05/12] Added tests for r.circle tool --- raster/r.circle/testsuite/test_circle.py | 68 ++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 raster/r.circle/testsuite/test_circle.py diff --git a/raster/r.circle/testsuite/test_circle.py b/raster/r.circle/testsuite/test_circle.py new file mode 100644 index 00000000000..4c7a3bdd367 --- /dev/null +++ b/raster/r.circle/testsuite/test_circle.py @@ -0,0 +1,68 @@ +from grass.gunittest.case import TestCase +from grass.gunittest.main import test +import grass.script as gs +from grass.gunittest.gmodules import SimpleModule + + +class TestRCircle(TestCase): + + @classmethod + def setUpClass(cls): + """Set up a temporary region for testing.""" + cls.use_temp_region() + cls.runModule("g.region", n=1000, s=0, e=1000, w=0, res=10) + + @classmethod + def tearDownClass(cls): + """Clean up after tests.""" + cls.del_temp_region() + + def tearDown(self): + gs.run_command( + "g.remove", + type="raster", + name="test_circle_binary,test_circle_distance", + flags="f", + ) + + def test_create_circle_with_b_flag(self): + """Test creating a binary circle with r.circle using -b flag.""" + output = "test_circle_binary" + + module = SimpleModule( + "r.circle", output=output, coordinates=(500, 500), max=100, flags="b" + ) + + self.assertModule(module) + + self.assertRasterExists(output) + + self.assertRasterMinMax( + map=output, + refmin=1, + refmax=1, + msg="Binary circle should have category value of 1", + ) + + def test_create_circle_without_b_flag(self): + """Test creating a circle with r.circle without -b flag.""" + output = "test_circle_distance" + + module = SimpleModule( + "r.circle", output=output, coordinates=(500, 500), max=100 + ) + + self.assertModule(module) + + self.assertRasterExists(output) + + self.assertRasterMinMax( + map=output, + refmin=0, + refmax=100, + msg="Circle should have distance values from 0 to 100", + ) + + +if __name__ == "__main__": + test() From 6086f56ddb48ee50320dadd8c5288ac52435c654 Mon Sep 17 00:00:00 2001 From: Shreshth Malik Date: Fri, 25 Oct 2024 22:24:54 -0400 Subject: [PATCH 06/12] Delete raster/r.buffer/testsuite directory --- raster/r.buffer/testsuite/test_buffer.py | 126 ----------------------- 1 file changed, 126 deletions(-) delete mode 100644 raster/r.buffer/testsuite/test_buffer.py diff --git a/raster/r.buffer/testsuite/test_buffer.py b/raster/r.buffer/testsuite/test_buffer.py deleted file mode 100644 index 068411c64a9..00000000000 --- a/raster/r.buffer/testsuite/test_buffer.py +++ /dev/null @@ -1,126 +0,0 @@ -from grass.gunittest.case import TestCase -from grass.gunittest.main import test -from grass.gunittest.gmodules import SimpleModule -import grass.script as gs - - -class TestRBuffer(TestCase): - - @classmethod - def setUpClass(cls): - cls.use_temp_region() - cls.runModule("g.region", raster="roadsmajor") - - @classmethod - def tearDownClass(cls): - cls.del_temp_region() - - def tearDown(self): - # Remove temporary maps created during tests - gs.run_command( - "g.remove", - type="raster", - name="null_map,zero_map,buf_test,buf_no_non_null,buf_ignore_zero", - flags="f", - ) - - def test_buffer_creation(self): - output = "buf_test" - distances = [100, 200, 300, 400, 500] - - module = SimpleModule( - "r.buffer", - input="roadsmajor", - output=output, - distances=distances, - overwrite=True, - ) - self.assertModule(module) - - self.assertRasterExists(output) - - expected_categories = [1] + [i + 1 for i in range(len(distances) + 1)] - - self.assertRasterMinMax( - map=output, - refmin=min(expected_categories), - refmax=max(expected_categories), - msg=( - "Buffer zones should have category values from 1 to " # Checking if there are no abnormal values in the output raster map - + str(max(expected_categories)) - ), - ) - - category_values = gs.read_command( - "r.stats", flags="n", input=output - ).splitlines() - category_values = [int(line.split()[0]) for line in category_values] - - print("Category values:", category_values) - - unique_actual_categories = set(category_values) - self.assertTrue( - unique_actual_categories.issubset(set(expected_categories)), - msg=( - "Output categories should be a subset of expected categories: " - + str(expected_categories) - ), - ) - - def test_no_non_null_values(self): - null_map = "null_map" - self.runModule("r.mapcalc", expression=f"{null_map} = null()") - - output = "buf_no_non_null" - distances = [100, 200, 300] - - module = SimpleModule( - "r.buffer", - input=null_map, - output=output, - distances=distances, - overwrite=True, - ) - self.assertModule(module) - - self.assertRasterExists(output) - stats = gs.read_command("r.univar", map=output, flags="g") - self.assertIn( - "n=0", stats, msg="Output should have no non-NULL cells" - ) # Checking an edge case where the input raster map is null - - def test_ignore_zero_values(self): - zero_map = "zero_map" - self.runModule("r.mapcalc", expression=f"{zero_map} = if(row() % 2 == 0, 0, 1)") - - output = "buf_ignore_zero" - distances = [100, 200] - - module = SimpleModule( - "r.buffer", - input=zero_map, - output=output, - distances=distances, - flags="z", - overwrite=True, - ) - self.assertModule(module) - - self.assertRasterExists(output) - - category_values = gs.read_command( - "r.stats", flags="n", input=output - ).splitlines() - category_values = [int(line.split()[0]) for line in category_values] - - print("Category values:", category_values) - - self.assertNotIn( - 0, - category_values, - msg="Output should not contain buffer zones around zero values", - ) # Check if the output raster map ignored 0 values - - -if __name__ == "__main__": - test() From 25bd2d9f7d3986a5777cbd02d124b5c896937a98 Mon Sep 17 00:00:00 2001 From: Shreshth-Malik Date: Fri, 25 Oct 2024 22:26:54 -0400 Subject: [PATCH 07/12] Added test file for r.circle tool --- raster/r.circle/testsuite/test_circle.py | 68 ++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 raster/r.circle/testsuite/test_circle.py diff --git a/raster/r.circle/testsuite/test_circle.py b/raster/r.circle/testsuite/test_circle.py new file mode 100644 index 00000000000..4c7a3bdd367 --- /dev/null +++ b/raster/r.circle/testsuite/test_circle.py @@ -0,0 +1,68 @@ +from grass.gunittest.case import TestCase +from grass.gunittest.main import test +import grass.script as gs +from grass.gunittest.gmodules import SimpleModule + + +class TestRCircle(TestCase): + + @classmethod + def setUpClass(cls): + """Set up a temporary region for testing.""" + cls.use_temp_region() + cls.runModule("g.region", n=1000, s=0, e=1000, w=0, res=10) + + @classmethod + def tearDownClass(cls): + """Clean up after tests.""" + cls.del_temp_region() + + def tearDown(self): + gs.run_command( + "g.remove", + type="raster", + name="test_circle_binary,test_circle_distance", + flags="f", + ) + + def test_create_circle_with_b_flag(self): + """Test creating a binary circle with r.circle using -b flag.""" + output = "test_circle_binary" + + module = SimpleModule( + "r.circle", output=output, coordinates=(500, 500), max=100, flags="b" + ) + + self.assertModule(module) + + self.assertRasterExists(output) + + self.assertRasterMinMax( + map=output, + refmin=1, + refmax=1, + msg="Binary circle should have category value of 1", + ) + + def test_create_circle_without_b_flag(self): + """Test creating a circle with r.circle without -b flag.""" + output = "test_circle_distance" + + module = SimpleModule( + "r.circle", output=output, coordinates=(500, 500), max=100 + ) + + self.assertModule(module) + + self.assertRasterExists(output) + + self.assertRasterMinMax( + map=output, + refmin=0, + refmax=100, + msg="Circle should have distance values from 0 to 100", + ) + + +if __name__ == "__main__": + test() From 2784a5c9d9371052dd04616f9167108265503271 Mon Sep 17 00:00:00 2001 From: Shreshth-Malik Date: Fri, 1 Nov 2024 18:20:53 -0400 Subject: [PATCH 08/12] Reduced the region size --- raster/r.circle/testsuite/test_circle.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/raster/r.circle/testsuite/test_circle.py b/raster/r.circle/testsuite/test_circle.py index 4c7a3bdd367..2904afe9256 100644 --- a/raster/r.circle/testsuite/test_circle.py +++ b/raster/r.circle/testsuite/test_circle.py @@ -10,7 +10,7 @@ class TestRCircle(TestCase): def setUpClass(cls): """Set up a temporary region for testing.""" cls.use_temp_region() - cls.runModule("g.region", n=1000, s=0, e=1000, w=0, res=10) + cls.runModule("g.region", n=30, s=0, e=30, w=0, res=10) @classmethod def tearDownClass(cls): @@ -30,7 +30,7 @@ def test_create_circle_with_b_flag(self): output = "test_circle_binary" module = SimpleModule( - "r.circle", output=output, coordinates=(500, 500), max=100, flags="b" + "r.circle", output=output, coordinates=(15, 15), max=10, flags="b" ) self.assertModule(module) @@ -49,7 +49,7 @@ def test_create_circle_without_b_flag(self): output = "test_circle_distance" module = SimpleModule( - "r.circle", output=output, coordinates=(500, 500), max=100 + "r.circle", output=output, coordinates=(15, 15), max=10 ) self.assertModule(module) @@ -59,10 +59,10 @@ def test_create_circle_without_b_flag(self): self.assertRasterMinMax( map=output, refmin=0, - refmax=100, - msg="Circle should have distance values from 0 to 100", + refmax=10, + msg="Circle should have distance values from 0 to 10", ) if __name__ == "__main__": - test() + test() \ No newline at end of file From cca140713aacceda5fb348cfc59952ca1b7e448f Mon Sep 17 00:00:00 2001 From: Shreshth Malik Date: Fri, 1 Nov 2024 18:29:43 -0400 Subject: [PATCH 09/12] Delete raster/r.buffer/testsuite directory --- raster/r.buffer/testsuite/test_buffer.py | 112 ----------------------- 1 file changed, 112 deletions(-) delete mode 100644 raster/r.buffer/testsuite/test_buffer.py diff --git a/raster/r.buffer/testsuite/test_buffer.py b/raster/r.buffer/testsuite/test_buffer.py deleted file mode 100644 index c92993a49bf..00000000000 --- a/raster/r.buffer/testsuite/test_buffer.py +++ /dev/null @@ -1,112 +0,0 @@ -from grass.gunittest.case import TestCase -from grass.gunittest.main import test -from grass.gunittest.gmodules import SimpleModule -import grass.script as gs - - -class TestRBuffer(TestCase): - - @classmethod - def setUpClass(cls): - cls.use_temp_region() - cls.runModule("g.region", raster="roadsmajor") - - @classmethod - def tearDownClass(cls): - cls.del_temp_region() - - def tearDown(self): - # Remove temporary maps created during tests - gs.run_command( - "g.remove", - type="raster", - name="null_map,buf_test,consist_test,zero_map,buf_no_non_null,buf_ignore_zero", - flags="f", - ) - - def test_buffer_creation(self): - output = "buf_test" - distances = [100, 200, 300, 400, 500] - - module = SimpleModule( - "r.buffer", - input="roadsmajor", - output=output, - distances=distances, - overwrite=True, - ) - self.assertModule(module) - - self.assertRasterExists(output) - - expected_categories = [i + 1 for i in range(len(distances) + 1)] - - self.assertRasterMinMax( - map=output, - refmin=min(expected_categories), - refmax=max(expected_categories), - msg=( - "Buffer zones should have category values from 1 to " # Checking if there are no abnormal values in the output raster map - + str(max(expected_categories)) - ), - ) - - def test_no_non_null_values(self): - null_map = "null_map" - self.runModule("r.mapcalc", expression=f"{null_map} = null()") - - output = "buf_no_non_null" - distances = [100, 200, 300] - - module = SimpleModule( - "r.buffer", - input=null_map, - output=output, - distances=distances, - overwrite=True, - ) - self.assertModule(module) - - self.assertRasterExists(output) - - expected_stats = {"n": 0} - - self.assertRasterFitsUnivar(output, reference=expected_stats) - - def test_ignore_zero_values(self): - zero_map = "zero_map" - self.runModule("r.mapcalc", expression=f"{zero_map} = if(row() % 2 == 0, 0, 1)") - - output = "buf_ignore_zero" - distances = [100, 200] - - module = SimpleModule( - "r.buffer", - input=zero_map, - output=output, - distances=distances, - flags="z", - overwrite=True, - ) - self.assertModule(module) - - self.assertRasterExists(output) - - category_values = gs.read_command( - "r.stats", flags="n", input=output - ).splitlines() - category_values = [int(line.split()[0]) for line in category_values] - - print("Category values:", category_values) - - expected_categories = [1, 2] - - self.assertNotIn( - expected_categories, - category_values, - msg="Output should not contain buffer zones around zero values", - ) # Check if the output raster map ignored 0 values - - -if __name__ == "__main__": - test() From 73576c7b2b14301b8b63163d8150fb903796e7ec Mon Sep 17 00:00:00 2001 From: Shreshth Malik Date: Sat, 2 Nov 2024 11:52:56 -0400 Subject: [PATCH 10/12] Update raster/r.circle/testsuite/test_circle.py Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- raster/r.circle/testsuite/test_circle.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/raster/r.circle/testsuite/test_circle.py b/raster/r.circle/testsuite/test_circle.py index ec301d96803..e7010ed7000 100644 --- a/raster/r.circle/testsuite/test_circle.py +++ b/raster/r.circle/testsuite/test_circle.py @@ -48,9 +48,7 @@ def test_create_circle_without_b_flag(self): """Test creating a circle with r.circle without -b flag.""" output = "test_circle_distance" - module = SimpleModule( - "r.circle", output=output, coordinates=(15, 15), max=10 - ) + module = SimpleModule("r.circle", output=output, coordinates=(15, 15), max=10) self.assertModule(module) From 4d5f93b500dc44ed773dbd375567995325299e99 Mon Sep 17 00:00:00 2001 From: Shreshth-Malik Date: Tue, 5 Nov 2024 21:41:47 -0500 Subject: [PATCH 11/12] Added test for multiplier --- raster/r.circle/testsuite/test_circle.py | 25 ++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/raster/r.circle/testsuite/test_circle.py b/raster/r.circle/testsuite/test_circle.py index ec301d96803..e82b8f5a02a 100644 --- a/raster/r.circle/testsuite/test_circle.py +++ b/raster/r.circle/testsuite/test_circle.py @@ -21,7 +21,7 @@ def tearDown(self): gs.run_command( "g.remove", type="raster", - name="test_circle_binary,test_circle_distance", + name="test_circle_binary,test_circle_distance,test_circle_mult", flags="f", ) @@ -48,9 +48,7 @@ def test_create_circle_without_b_flag(self): """Test creating a circle with r.circle without -b flag.""" output = "test_circle_distance" - module = SimpleModule( - "r.circle", output=output, coordinates=(15, 15), max=10 - ) + module = SimpleModule("r.circle", output=output, coordinates=(15, 15), max=10) self.assertModule(module) @@ -63,6 +61,25 @@ def test_create_circle_without_b_flag(self): msg="Circle should have distance values from 0 to 10", ) + def test_create_circle_with_multiplier(self): + """Test creating a circle with r.circle with a multiplier.""" + output = "test_circle_multi" + + module = SimpleModule( + "r.circle", output=output, coordinates=(15, 15), max=10, multiplier=2 + ) + + self.assertModule(module) + + self.assertRasterExists(output) + + self.assertRasterMinMax( + map=output, + refmin=0, + refmax=20, + msg="Circle should have distance values from 0 to 20", + ) + if __name__ == "__main__": test() From 57fb1eff009caeaff6b50d6657db1d11f9b54de7 Mon Sep 17 00:00:00 2001 From: Shreshth-Malik Date: Thu, 7 Nov 2024 17:45:19 -0500 Subject: [PATCH 12/12] Streamlined output map initialization --- raster/r.circle/testsuite/test_circle.py | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/raster/r.circle/testsuite/test_circle.py b/raster/r.circle/testsuite/test_circle.py index e82b8f5a02a..1c0a4b62f54 100644 --- a/raster/r.circle/testsuite/test_circle.py +++ b/raster/r.circle/testsuite/test_circle.py @@ -9,6 +9,7 @@ class TestRCircle(TestCase): @classmethod def setUpClass(cls): """Set up a temporary region for testing.""" + cls.output = "test_circle" cls.use_temp_region() cls.runModule("g.region", n=30, s=0, e=30, w=0, res=10) @@ -21,24 +22,23 @@ def tearDown(self): gs.run_command( "g.remove", type="raster", - name="test_circle_binary,test_circle_distance,test_circle_mult", + name=self.output, flags="f", ) def test_create_circle_with_b_flag(self): """Test creating a binary circle with r.circle using -b flag.""" - output = "test_circle_binary" module = SimpleModule( - "r.circle", output=output, coordinates=(15, 15), max=10, flags="b" + "r.circle", output=self.output, coordinates=(15, 15), max=10, flags="b" ) self.assertModule(module) - self.assertRasterExists(output) + self.assertRasterExists(self.output) self.assertRasterMinMax( - map=output, + map=self.output, refmin=1, refmax=1, msg="Binary circle should have category value of 1", @@ -46,16 +46,17 @@ def test_create_circle_with_b_flag(self): def test_create_circle_without_b_flag(self): """Test creating a circle with r.circle without -b flag.""" - output = "test_circle_distance" - module = SimpleModule("r.circle", output=output, coordinates=(15, 15), max=10) + module = SimpleModule( + "r.circle", output=self.output, coordinates=(15, 15), max=10 + ) self.assertModule(module) - self.assertRasterExists(output) + self.assertRasterExists(self.output) self.assertRasterMinMax( - map=output, + map=self.output, refmin=0, refmax=10, msg="Circle should have distance values from 0 to 10", @@ -63,18 +64,17 @@ def test_create_circle_without_b_flag(self): def test_create_circle_with_multiplier(self): """Test creating a circle with r.circle with a multiplier.""" - output = "test_circle_multi" module = SimpleModule( - "r.circle", output=output, coordinates=(15, 15), max=10, multiplier=2 + "r.circle", output=self.output, coordinates=(15, 15), max=10, multiplier=2 ) self.assertModule(module) - self.assertRasterExists(output) + self.assertRasterExists(self.output) self.assertRasterMinMax( - map=output, + map=self.output, refmin=0, refmax=20, msg="Circle should have distance values from 0 to 20",