Преглед на файлове

pygrass: Add test on __getitem__ method in VectorTopo class

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@62135 15284696-431f-4ddb-bdfa-cd5b030d7da7
Pietro Zambelli преди 10 години
родител
ревизия
241d5e96f5
променени са 1 файла, в които са добавени 35 реда и са изтрити 0 реда
  1. 35 0
      lib/python/pygrass/vector/testsuite/test_vector.py

+ 35 - 0
lib/python/pygrass/vector/testsuite/test_vector.py

@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Wed Jun 18 17:21:42 2014
+
+@author: pietro
+"""
+from grass.gunittest import TestCase, test
+
+from grass.pygrass.vector import VectorTopo
+
+
+class VectorTopoTestCase(TestCase):
+
+    vname = "points_of_interest"
+
+    def test_getitem_slice(self):
+        """Test that getitem handle correctly the slice starting from 1"""
+        vcoords = ((646341.7386813264, 218873.73056803632),
+                   (637772.0990144431, 218842.80557760992))
+        with VectorTopo(self.vname, mode="r") as vect:
+            coords = tuple([pnt.coords() for pnt in vect[:3]])
+            self.assertTupleEqual(vcoords, coords)
+            coords = tuple([pnt.coords() for pnt in vect[1:3]])
+            self.assertTupleEqual(vcoords, coords)
+
+    def test_getitem_raise(self):
+        """Test that getitem raise a value error if the key is not
+        an integer or a slice"""
+        with VectorTopo(self.vname, mode="r") as vect:
+            with self.assertRaises(ValueError):
+                vect['value']
+
+
+if __name__ == '__main__':
+    test()