File: test_geometry_attrs.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 (75 lines) | stat: -rw-r--r-- 2,038 bytes parent folder | download | duplicates (2)
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
71
72
73
74
75
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 19 14:13:53 2014

@author: pietro
"""
import sys
import unittest
import numpy as np

from grass.gunittest.case import TestCase
from grass.gunittest.main import test

import grass.lib.vector as libvect
from grass.script.core import run_command

from grass.pygrass.vector import VectorTopo


class GeometryAttrsTestCase(TestCase):

    tmpname = "GeometryAttrsCase_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.c_mapinfo = cls.vect.c_mapinfo

        cls.attrs = cls.vect[1].attrs

    @classmethod
    def tearDownClass(cls):
        cls.attrs = None
        if cls.vect is not None:
            cls.vect.close()
            cls.c_mapinfo = None

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

    def test_getitem(self):
        """Test __getitem__ magic method"""
        self.assertEqual(self.attrs['name'], u'point')
        self.assertEqual(self.attrs['value'], 1.0)
        self.assertTupleEqual(self.attrs['name', 'value'], (u'point', 1.0))

        with self.assertRaises(ValueError) as cm:
            self.attrs['not_existing_column_name']

        self.assertTrue(u"not_existing_column_name" in cm.exception.message)


    def test_setitem(self):
        """Test __setitem__ magic method"""
        newname = 'setitem_point_1'
        newvalue = 100.0
        newpairs = ('setitem_point_2', 1000.)

        self.attrs.__setitem__('name', newname)
        self.assertEqual(self.attrs['name'], newname)
        self.attrs.__setitem__('value', newvalue)
        self.assertEqual(self.attrs['value'], newvalue)
        self.attrs.__setitem__(('name', 'value'), newpairs)
        self.assertEqual(self.attrs['name', 'value'], newpairs)


if __name__ == '__main__':
    test()