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

tests: fix tests that were actually not testing anything #4349

Merged
merged 3 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
34 changes: 22 additions & 12 deletions scripts/v.centroids/testsuite/test_v_centroids.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,47 @@
class TestVCentroids(TestCase):
"""Test v.centroids script"""

mapName = "busroute11"
outRouteMap = "busroute11_boundary"
fromType = "line"
toType = "boundary"
outAreaMap = "busroute11_area"
region_line = "region_line"
region_boundary = "region_boundary"
region_area = "region_area"
output = "output"

@classmethod
def setUpClass(cls):
"""Create an area from a closed line"""
cls.runModule("v.in.region", output=cls.region_line, type="line")
cls.runModule("v.in.region", output=cls.region_area, type="area")
cls.runModule(
"v.type",
input=cls.mapName,
output=cls.outRouteMap,
from_type=cls.fromType,
to_type=cls.toType,
input=cls.region_line,
output=cls.region_boundary,
from_type="line",
to_type="boundary",
)

@classmethod
def tearDownClass(cls):
"""Remove the generated maps"""
cls.runModule(
"g.remove", flags="f", type="vector", name=(cls.outRouteMap, cls.outAreaMap)
"g.remove",
flags="f",
type="vector",
name=(cls.region_line, cls.region_area, cls.region_boundary),
)

def tearDown(self):
"""Remove the generated maps"""
self.runModule("g.remove", flags="f", type="vector", name=self.output)

def test_area(self):
"""Adds missing centroids to closed boundaries test"""
module = SimpleModule(
"v.centroids", input=self.outRouteMap, output=self.outAreaMap
"v.centroids", input=self.region_boundary, output=self.output
)
self.assertModule(module)
self.assertVectorExists(self.outAreaMap)
self.assertVectorInfoEqualsVectorInfo(
self.output, self.region_area, precision=1e-6
)


if __name__ == "__main__":
Expand Down
17 changes: 8 additions & 9 deletions scripts/v.what.vect/testsuite/test_v_what_vect.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from grass.gunittest.gmodules import SimpleModule

from grass.script.core import run_command
from grass.script.utils import decode


class TestVWhatVect(TestCase):
Expand All @@ -29,20 +28,20 @@ def tearDownClass(cls):

def test_what_vect(self):
"""Uploads vector values"""
run_command("v.db.addcolumn", map=self.mapName, columns="urb_name varchar(25)")
run_command("v.db.addcolumn", map=self.mapName, columns="geology_cat integer")

module = SimpleModule(
"v.what.vect",
map=self.mapName,
query_map="urbanarea",
column="urb_name",
query_column="NAME",
query_map="geology",
column="geology_cat",
query_column="cat",
)
self.assertModule(module)

m = SimpleModule("v.db.select", map=self.mapName)
self.assertModule(m)
self.assertRegex(decode(m.outputs.stdout), "urb_name")
minmax = "min=11\nmax=1810"
self.assertVectorFitsUnivar(
map=self.mapName, column="geology_cat", reference=minmax
)


if __name__ == "__main__":
Expand Down
33 changes: 9 additions & 24 deletions vector/v.select/testsuite/test_v_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,9 @@


class TestRasterReport(TestCase):
binput = "bridges"
binput = "zipcodes"
ainput = "geology"
output = "testvselect"
overlap = "geonames_wake"
disjoint = "schools_wake"
equals = "streets_wake"
touches = "zipcodes_wake"
within = "geonames_wake"

@classmethod
def setUpClass(cls):
cls.use_temp_region()

@classmethod
def tearDownClass(cls):
cls.del_temp_region()

def tearDown(cls):
cls.runModule("g.remove", type="vector", flags="f", name=cls.output)
Expand All @@ -42,8 +29,8 @@ def test_opo(self):
output=self.output,
operator="overlap",
)
topology = {"points": 1088, "lines": 0, "areas": 0}
self.assertVectorFitsTopoInfo(self.overlap, topology)
topology = {"areas": 97}
self.assertVectorFitsTopoInfo(self.output, topology)

def test_opd(self):
"""Testign operator disjoint"""
Expand All @@ -54,8 +41,8 @@ def test_opd(self):
output=self.output,
operator="disjoint",
)
topology = {"points": 167, "lines": 0, "areas": 0}
self.assertVectorFitsTopoInfo(self.disjoint, topology)
topology = {"areas": 1770}
self.assertVectorFitsTopoInfo(self.output, topology)

def test_ope(self):
"""Testing operator equals"""
Expand All @@ -66,8 +53,7 @@ def test_ope(self):
output=self.output,
operator="equals",
)
topology = {"points": 0, "lines": 49746, "areas": 0}
self.assertVectorFitsTopoInfo(self.equals, topology)
self.assertVectorDoesNotExist(self.output)
wenzeslaus marked this conversation as resolved.
Show resolved Hide resolved

def test_opt(self):
"""Testing operator touches"""
Expand All @@ -78,8 +64,7 @@ def test_opt(self):
output=self.output,
operator="touches",
)
topology = {"points": 0, "lines": 0, "areas": 48}
self.assertVectorFitsTopoInfo(self.touches, topology)
self.assertVectorDoesNotExist(self.output)

def test_opw(self):
"""Testing operator within"""
Expand All @@ -90,8 +75,8 @@ def test_opw(self):
output=self.output,
operator="within",
)
topology = {"points": 1088, "lines": 0, "areas": 0}
self.assertVectorFitsTopoInfo(self.within, topology)
topology = {"areas": 17}
self.assertVectorFitsTopoInfo(self.output, topology)


if __name__ == "__main__":
Expand Down
Loading