File: test_raster.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 (45 lines) | stat: -rw-r--r-- 1,279 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
# -*- coding: utf-8 -*-
"""
Created on Thu Feb 18 09:42:23 2016

@author: lucadelu
"""

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

import grass.script as gscript


class TestRaster(TestCase):
    """Test raster functions"""

    raster = 'testrasterscript'
    region = gscript.region()
    coords = (region['e'] - 1, region['n'] - 1)

    @classmethod
    def setUpClass(cls):
        cls.runModule("r.mapcalc", expression="testrasterscript = 100",
                      overwrite=True)

    @classmethod
    def tearDownClass(cls):
        cls.runModule("g.remove", type='raster', name='testrasterscript',
                      flags='f')

    def test_raster_what(self):
        res = gscript.raster_what(self.raster, [self.coords])[0]
        self.assertEquals(int(res[self.raster]['value']), 100)

        res = gscript.raster_what(self.raster, [self.coords],
                                  localized=True)[0]
        self.assertEquals(int(res[self.raster][_('value')]), 100)

    def test_raster_info(self):
        res = gscript.raster_info(self.raster)
        self.assertEquals(str(res['cols']), str(self.region['cols']))
        self.assertEquals(str(res['north']), str(self.region['n']))

if __name__ == '__main__':
    test()