source: grass/trunk/raster/r.mapcalc/testsuite/test_row_above_below_bug.py

Last change on this file was 70476, checked in by wenzeslaus, 8 years ago

Python 2.6 does not support ommitting of positional argument specifiers

Fixes ValueError: zero length field name in format

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-python
File size: 2.8 KB
Line 
1#!/usr/bin/env python
2
3############################################################################
4#
5# MODULE: test_row_above_below_bug.py
6# AUTHOR: Vaclav Petras
7# PURPOSE: Show bug reported in #3067
8# COPYRIGHT: (C) 2016 by Vaclav Petras and the GRASS Development Team
9#
10# This program is free software under the GNU General Public
11# License (>=v2). Read the file COPYING that comes with GRASS
12# for details.
13#
14#############################################################################
15
16# #3067
17# r.mapcalc gives wrong result when neighborhood modifier takes a cell
18# above first
19# https://trac.osgeo.org/grass/ticket/3067
20
21from grass.gunittest.case import TestCase
22from grass.gunittest.main import test
23
24
25INPUT = """\
26north: 10
27south: 8
28east: 20
29west: 18
30rows: 3
31cols: 3
321 0 1
331 1 0
341 1 0
35"""
36
37OUTPUT = """\
38north: 10
39south: 8
40east: 20
41west: 18
42rows: 3
43cols: 3
44null: *
45* * *
462 1 1
47* * *
48"""
49
50class TestRowAboveAndBelowBug(TestCase):
51 # TODO: replace by unified handing of maps
52 to_remove = []
53 input = 'r_mapcalc_test_input'
54 output = 'r_mapcalc_test_output'
55 output_ref = 'r_mapcalc_test_output_ref'
56
57 def setUp(self):
58 self.use_temp_region()
59 self.runModule('r.in.ascii', input='-', stdin_=INPUT,
60 output=self.input, overwrite=True)
61 self.to_remove.append(self.input)
62 self.runModule('g.region', raster=self.input)
63 self.runModule('r.in.ascii', input='-', stdin_=OUTPUT,
64 output=self.output_ref, overwrite=True)
65 self.to_remove.append(self.output_ref)
66
67 def tearDown(self):
68 self.del_temp_region()
69 if 0 and self.to_remove:
70 self.runModule('g.remove', flags='f', type='raster',
71 name=','.join(self.to_remove), verbose=True)
72
73 def r_mapcalc_with_test(self, expression):
74 """Expects just RHS and inputs as ``{m}`` for format function"""
75 expression = expression.format(m=self.input)
76 expression = "{0} = {1}".format(self.output, expression)
77 self.assertModule('r.mapcalc', expression=expression, overwrite=True)
78 self.assertRasterExists(self.output)
79 self.to_remove.append(self.output)
80 ref_univar = dict(null_cells=6, cells=9)
81 self.assertRasterFitsUnivar(raster=self.output,
82 reference=ref_univar, precision=0)
83 self.assertRastersNoDifference(actual=self.output,
84 reference=self.output_ref,
85 precision=0) # it's CELL type
86
87 def test_below_above(self):
88 self.r_mapcalc_with_test("{m}[1,0] + {m}[-1,0]")
89
90 def test_above_below(self):
91 self.r_mapcalc_with_test("{m}[-1,0] + {m}[1,0]")
92
93
94if __name__ == '__main__':
95 test()
Note: See TracBrowser for help on using the repository browser.