test_vector.py 1.1 KB

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