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
3 changes: 2 additions & 1 deletion python/grass/pygrass/vector/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,8 @@ def c_read_next_line(c_mapinfo, c_points, c_cats):
if ftype == -2:
raise StopIteration
if ftype == -1:
raise
msg = "Cannot read the next line"
raise GrassError(msg)
return ftype, v_id, c_points, c_cats


Expand Down
32 changes: 31 additions & 1 deletion python/grass/pygrass/vector/testsuite/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@
"""

import unittest
from unittest.mock import MagicMock, patch

import numpy as np

import grass.lib.vector as libvect
from grass.exceptions import GrassError
from grass.gunittest.case import TestCase
from grass.gunittest.main import test
from grass.pygrass.vector import VectorTopo
from grass.pygrass.vector.basic import Bbox
from grass.pygrass.vector.geometry import Area, Line, Node, Point
from grass.pygrass.vector.geometry import Area, Line, Node, Point, c_read_next_line


class PointTestCase(TestCase):
Expand Down Expand Up @@ -390,5 +392,33 @@ def test_isles_2(self):
self.assertEqual(str(isle.bbox()), "Bbox(3.0, 1.0, 3.0, 1.0)")


class ReadNextLineTestCase(TestCase):
def test_c_read_next_line_error(self):
"""Test c_read_next_line raises GrassError when Vect_read_next_line returns -1"""
mock_mapinfo = MagicMock()
mock_mapinfo.contents.next_line = 1
with (
patch(
"grass.pygrass.vector.geometry.libvect.Vect_read_next_line",
return_value=-1,
),
self.assertRaises(GrassError),
):
c_read_next_line(mock_mapinfo, None, None)

def test_c_read_next_line_stop_iteration(self):
"""Test c_read_next_line raises StopIteration when Vect_read_next_line returns -2"""
mock_mapinfo = MagicMock()
mock_mapinfo.contents.next_line = 1
with (
patch(
"grass.pygrass.vector.geometry.libvect.Vect_read_next_line",
return_value=-2,
),
self.assertRaises(StopIteration),
):
c_read_next_line(mock_mapinfo, None, None)


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