~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to raster/r.in.poly/testsuite/test_rinpoly.py

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import os
 
2
import tempfile
 
3
import grass.gunittest
 
4
from grass.script.core import read_command
 
5
 
 
6
 
 
7
input1 = \
 
8
"""
 
9
A
 
10
634308.630394 223320.356473
 
11
640640.712946 223092.401501
 
12
641248.592871 217748.123827
 
13
= 10.01 label1
 
14
A
 
15
639576.923077 222256.566604
 
16
639045.028143 216329.737336
 
17
637702.626642 224662.757974
 
18
= -8
 
19
L
 
20
633523.452158 222231.238274
 
21
642565.666041 221218.105066
 
22
641957.786116 222585.834897
 
23
= 3 label2
 
24
"""
 
25
 
 
26
 
 
27
class TestRInPoly(grass.gunittest.TestCase):
 
28
 
 
29
    rinpoly = 'test_rinpoly'
 
30
 
 
31
    @classmethod
 
32
    def setUpClass(cls):
 
33
        cls.use_temp_region()
 
34
        cls.runModule('g.region', raster='elevation')
 
35
 
 
36
    @classmethod
 
37
    def tearDownClass(cls):
 
38
        cls.del_temp_region()
 
39
 
 
40
    def setUp(self):
 
41
        self.tmpFile = tempfile.NamedTemporaryFile(delete=False)
 
42
 
 
43
    def tearDown(self):
 
44
        """Remove rinpoly map after each test method"""
 
45
        self.runModule('g.remove', flags='f', type='raster',
 
46
                       name=self.rinpoly)
 
47
        os.unlink(self.tmpFile.name)
 
48
 
 
49
    def testTypeCell(self):
 
50
        """Test type of resulting map"""
 
51
        self.tmpFile.write(input1)
 
52
        self.tmpFile.close()
 
53
        self.assertModule('r.in.poly', input=self.tmpFile.name, output=self.rinpoly, type='CELL')
 
54
        minmax = 'min=-8\nmax=10\ndatatype=CELL'
 
55
        self.assertRasterFitsInfo(raster=self.rinpoly, reference=minmax)
 
56
 
 
57
    def testTypeFCell(self):
 
58
        """Test type of resulting map"""
 
59
        self.tmpFile.write(input1)
 
60
        self.tmpFile.close()
 
61
        self.assertModule('r.in.poly', input=self.tmpFile.name, output=self.rinpoly, type='FCELL')
 
62
        minmax = 'min=-8\nmax=10.01\ndatatype=FCELL'
 
63
        self.assertRasterFitsInfo(raster=self.rinpoly, reference=minmax, precision=1e-8)
 
64
 
 
65
    def testTypeDCell(self):
 
66
        """Test type of resulting map"""
 
67
        self.tmpFile.write(input1)
 
68
        self.tmpFile.close()
 
69
        self.assertModule('r.in.poly', input=self.tmpFile.name, output=self.rinpoly, type='DCELL')
 
70
        minmax = 'min=-8\nmax=10.01\ndatatype=DCELL'
 
71
        self.assertRasterFitsInfo(raster=self.rinpoly, reference=minmax, precision=1e-8)
 
72
 
 
73
    def testTypeCellNull(self):
 
74
        """Test type of resulting map"""
 
75
        self.tmpFile.write(input1)
 
76
        self.tmpFile.close()
 
77
        self.assertModule('r.in.poly', input=self.tmpFile.name, output=self.rinpoly, type='CELL',
 
78
                          null=-8)
 
79
        minmax = 'min=3\nmax=10\ndatatype=CELL'
 
80
        self.assertRasterFitsInfo(raster=self.rinpoly, reference=minmax, precision=1e-8)
 
81
 
 
82
    def testTypeDCellNull(self):
 
83
        """Test type of resulting map"""
 
84
        self.tmpFile.write(input1)
 
85
        self.tmpFile.close()
 
86
        self.assertModule('r.in.poly', input=self.tmpFile.name, output=self.rinpoly, type='DCELL',
 
87
                          null=-8)
 
88
        minmax = 'min=3\nmax=10.01\ndatatype=DCELL'
 
89
        self.assertRasterFitsInfo(raster=self.rinpoly, reference=minmax, precision=1e-8)
 
90
 
 
91
    def testTypeDCellNull2(self):
 
92
        """Test type of resulting map"""
 
93
        self.tmpFile.write(input1)
 
94
        self.tmpFile.close()
 
95
        self.assertModule('r.in.poly', input=self.tmpFile.name, output=self.rinpoly, type='DCELL',
 
96
                          null=0)
 
97
        minmax = 'min=-8\nmax=10.01\ndatatype=DCELL'
 
98
        self.assertRasterFitsInfo(raster=self.rinpoly, reference=minmax, precision=1e-8)
 
99
 
 
100
    def testLabels(self):
 
101
        """Test type of resulting map"""
 
102
        self.tmpFile.write(input1)
 
103
        self.tmpFile.close()
 
104
        self.assertModule('r.in.poly', input=self.tmpFile.name, output=self.rinpoly, type='DCELL')
 
105
        category = read_command('r.category', map=self.rinpoly, values=[-8, 3, 10.01]).strip()
 
106
        self.assertEqual(first="-8\t\n3\tlabel2\n10.01\tlabel1", second=category,
 
107
                         msg="Labels do not match")
 
108
 
 
109
 
 
110
if __name__ == '__main__':
 
111
    grass.gunittest.test()