Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions src/vector/v.flexure/testsuite/test_v_flexure.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ class TestVFlexureInputErrors(TestCase):
"""Input-validation errors raised inside main() — gFlex must be importable."""

loads = "test_vflex_ierr_loads"
empty_loads = "test_vflex_ierr_empty"

@classmethod
def setUpClass(cls):
Expand All @@ -605,11 +606,15 @@ def setUpClass(cls):
value="1e15",
where="cat=1",
)
cls.runModule("v.edit", map=cls.empty_loads, tool="create")

@classmethod
def tearDownClass(cls):
cls.del_temp_region()
cls.runModule("g.remove", flags="f", type="vector", name=cls.loads, quiet=True)
cls.runModule(
"g.remove", flags="f", type="vector", name=cls.empty_loads, quiet=True
)

def test_missing_column(self):
"""Module exits with error when the named column is absent from the input map."""
Expand All @@ -622,6 +627,17 @@ def test_missing_column(self):
output="dummy_out",
)

def test_empty_input(self):
"""Module exits with error when the input vector map contains no points."""
self.assertModuleFail(
"v.flexure",
input=self.empty_loads,
column="q",
te="10000",
te_units="m",
output="dummy_out",
)


if __name__ == "__main__":
test()
4 changes: 4 additions & 0 deletions src/vector/v.flexure/v.flexure.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ def get_points_xy(vect_name):
"v.out.ascii", input=vect_name, format="point", separator="space", quiet=True
)
rows = [line.split() for line in out.strip().splitlines() if line.strip()]
if not rows:
return np.array([]), np.array([])
coords = np.array([[float(r[0]), float(r[1])] for r in rows], dtype=float)
return coords[:, 0], coords[:, 1] # x, y

Expand Down Expand Up @@ -219,6 +221,8 @@ def main():

# x, y, q — load point coordinates and magnitudes
flex.x, flex.y = get_points_xy(options["input"])
if len(flex.x) == 0:
gs.fatal(_("Input vector map <%s> contains no points.") % options["input"])
vect_db = gs.vector_db_select(options["input"])
col_names = np.array(vect_db["columns"])
q_col = col_names == options["column"]
Expand Down
Loading