test_vector.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Wed Jun 18 17:21:42 2014
  4. @author: pietro
  5. """
  6. from grass.gunittest import TestCase, test
  7. from grass.pygrass.vector import VectorTopo
  8. class VectorTopoTestCase(TestCase):
  9. vname = "points_of_interest"
  10. def test_getitem_slice(self):
  11. """Test that getitem handle correctly the slice starting from 1"""
  12. vcoords = ((646341.7386813264, 218873.73056803632),
  13. (637772.0990144431, 218842.80557760992))
  14. with VectorTopo(self.vname, mode="r") as vect:
  15. coords = tuple([pnt.coords() for pnt in vect[:3]])
  16. self.assertTupleEqual(vcoords, coords)
  17. coords = tuple([pnt.coords() for pnt in vect[1:3]])
  18. self.assertTupleEqual(vcoords, coords)
  19. def test_getitem_raise(self):
  20. """Test that getitem raise a value error if the key is not
  21. an integer or a slice"""
  22. with VectorTopo(self.vname, mode="r") as vect:
  23. with self.assertRaises(ValueError):
  24. vect['value']
  25. if __name__ == '__main__':
  26. test()