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

v.build: added tests for v.build module #5061

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
85 changes: 85 additions & 0 deletions vector/v.build/testsuite/test_v_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import grass.script as gs
from grass.gunittest.case import TestCase
from grass.gunittest.main import test


class TestVBuild(TestCase):
"""Test v.build output against expected output stored in vbuild_output"""

@classmethod
def setUpClass(cls):
"""Set up a temporary region and create vector map with test features."""
cls.use_temp_region()
input_data = "P 1\n1 1\nL 2\n0.5 0.5\n2.5 2.5"
gs.write_command(
"v.in.ascii",
input="-",
format="standard",
stdin=input_data,
output="test_3x3_map",
flags="n",
overwrite=True,
)

# Run v.build (with multiple dump options) and store its output in a class variable.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use read_command, the output is not meant to be parsed into a dictionary.

cls.build_module = gs.read_command(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be executed in the test_vbuild_output

"v.build",
map="test_3x3_map",
option="build,dump,sdump,cdump,fdump",
quiet=True,
).strip()

# Read the expected output.
cls.vbuild_output = """
N,S,E,W,T,B: 2.500000, 0.500000, 2.500000, 0.500000, 0.000000, 0.000000
-----------------------------------
Nodes (2 nodes, alive + dead):
node = 1, n_lines = 1, xyz = 0.500000, 0.500000, 0.000000
line = 2, type = 2, angle = 0.785398 (45.0000)
node = 2, n_lines = 1, xyz = 2.500000, 2.500000, 0.000000
line = -2, type = 2, angle = -2.356194 (225.0000)
-----------------------------------
Lines (2 lines, alive + dead):
line = 1, type = 1, offset = 18
line = 2, type = 2, offset = 35, n1 = 1, n2 = 2
-----------------------------------
Areas (0 areas, alive + dead):
-----------------------------------
Islands (0 islands, alive + dead):
---------- SPATIAL INDEX DUMP ----------
Nodes
Node level=0 count=2
Branch 0 id = 1 0.500000 0.500000 0.000000 0.500000 0.500000 0.000000
Branch 1 id = 2 2.500000 2.500000 0.000000 2.500000 2.500000 0.000000
Lines
Node level=0 count=2
Branch 0 id = 1 1.000000 1.000000 0.000000 1.000000 1.000000 0.000000
Branch 1 id = 2 0.500000 0.500000 0.000000 2.500000 2.500000 0.000000
Areas
Node level=0 count=0
Isles
Node level=0 count=0
---------- CATEGORY INDEX DUMP: Number of layers: 1 --------------------------------------
Layer 0 number of unique cats: 1 number of cats: 2 number of types: 2
------------------------------------------------------------------------------------------
type | count
1 | 1
2 | 1
category | type | line/area
0 | 1 | 1
0 | 2 | 2
------------------------------------------------------------------------------------------"""

@classmethod
def tearDownClass(cls):
"""Remove created vector map and temporary files, then delete the temp region."""
gs.run_command("g.remove", type="vector", flags="f", name="test_3x3_map")
cls.del_temp_region()

def test_vbuild_output(self):
"""Compare the v.build output (build_module) to the expected output."""
self.assertMultiLineEqual(self.build_module[135:], self.vbuild_output)


if __name__ == "__main__":
test()
Loading