File: test_vector.py

package info (click to toggle)
grass 7.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 135,976 kB
  • ctags: 44,148
  • sloc: ansic: 410,300; python: 166,939; cpp: 34,819; sh: 9,358; makefile: 6,618; xml: 3,551; sql: 769; lex: 519; yacc: 450; asm: 387; perl: 282; sed: 17; objc: 7
file content (70 lines) | stat: -rw-r--r-- 2,125 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
"""
Created on Wed Jun 18 17:21:42 2014

@author: pietro
"""
from grass.gunittest.case import TestCase
from grass.gunittest.main import test

from grass.script.core import run_command
from grass.pygrass.vector import VectorTopo


class VectorTopoTestCase(TestCase):

    tmpname = "VectorTopoTestCase_map"

    @classmethod
    def setUpClass(cls):
        
        from grass.pygrass import utils
        utils.create_test_vector_map(cls.tmpname)
        
        cls.vect = None
        cls.vect = VectorTopo(cls.tmpname)
        cls.vect.open('r')
        cls.vect.close()

    @classmethod
    def tearDownClass(cls):
        if cls.vect.is_open():
            cls.vect.close()

        """Remove the generated vector map, if exist"""
        cls.runModule("g.remove", flags='f', type='vector', 
                      name=cls.tmpname)

    def test_getitem_slice(self):
        """Test that getitem handle correctly the slice starting from 1"""
        vcoords =  ((10.0, 6.0), (12.0, 6.0))
        with VectorTopo(self.tmpname, 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)
            self.vect.close()

    def test_viter(self):
        """Test that getitem handle correctly the slice starting from 1"""

        with VectorTopo(self.tmpname, mode="r") as vect:
            for name in ["points", "lines", "areas", "islands", "nodes"]:
                count = 0
                for feature in vect.viter(name):
                    count += 1
                self.assertEqual(count, vect.number_of(name))
                
            self.vect.close()

    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.tmpname, mode="r") as vect:
            with self.assertRaises(ValueError):
                vect['value']

            self.vect.close()

if __name__ == '__main__':
    test()