Browse Source

property _LineSegment.vertex_indices now read-only

Fabian Peter Hammerle 5 years ago
parent
commit
68ce1f9151
2 changed files with 10 additions and 6 deletions
  1. 3 6
      freesurfer_surface/__init__.py
  2. 7 0
      tests/test_line_segment.py

+ 3 - 6
freesurfer_surface/__init__.py

@@ -141,12 +141,9 @@ class PolygonalCircuit:
 
 class _LineSegment(PolygonalCircuit):
 
-    # pylint: disable=no-member
-    @PolygonalCircuit.vertex_indices.setter
-    def vertex_indices(self, indices: PolygonalCircuit._VERTEX_INDICES_TYPE):
-        assert len(indices) == 2
-        # pylint: disable=attribute-defined-outside-init
-        self._vertex_indices = tuple(indices)
+    def __init__(self, indices: PolygonalCircuit._VERTEX_INDICES_TYPE):
+        super().__init__(indices)
+        assert len(self.vertex_indices) == 2
 
     def __repr__(self) -> str:
         return '_LineSegment(vertex_indices={})'.format(self.vertex_indices)

+ 7 - 0
tests/test_line_segment.py

@@ -1,6 +1,13 @@
+import pytest
+
 from freesurfer_surface import _LineSegment
 
 
+def test_init_fail():
+    with pytest.raises(Exception):
+        _LineSegment((1, 2, 3))
+
+
 def test_eq():
     assert _LineSegment((67018, 67019)) == _LineSegment((67018, 67019))
     assert _LineSegment((67018, 67019)) == _LineSegment((67019, 67018))