[GRASS-SVN] r58809 - grass/trunk/raster/r.category

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jan 30 09:36:23 PST 2014


Author: wenzeslaus
Date: 2014-01-30 09:36:23 -0800 (Thu, 30 Jan 2014)
New Revision: 58809

Added:
   grass/trunk/raster/r.category/test_rcatetgory_doctest.txt
Log:
r.category: test for input of cell, dcell, cell range, and outputs (test witten as python doctest)

Added: grass/trunk/raster/r.category/test_rcatetgory_doctest.txt
===================================================================
--- grass/trunk/raster/r.category/test_rcatetgory_doctest.txt	                        (rev 0)
+++ grass/trunk/raster/r.category/test_rcatetgory_doctest.txt	2014-01-30 17:36:23 UTC (rev 58809)
@@ -0,0 +1,140 @@
+Run this test file from command line using
+
+python -m doctest -v doctest.txt
+
+
+>>> from grass.script.core import run_command, read_command, write_command
+
+Data preparation
+================
+
+>>> run_command('r.mapcalc', expression='test = rand(1 , 3)')
+0
+>>> print(read_command('r.info', map='test',flags='r'))
+min=1
+max=2
+<BLANKLINE>
+>>> run_command('r.mapcalc', expression='test_14 = rand(1 , 5)')
+0
+>>> print(read_command('r.info', map='test_14',flags='r'))
+min=1
+max=4
+<BLANKLINE>
+>>> run_command('r.mapcalc', expression='test_d = double(rand(0 , 10))/2')
+0
+>>> print(read_command('r.info', map='test_d',flags='r'))
+min=0
+max=4.5
+<BLANKLINE>
+
+
+Basic tnput and output
+======================
+
+>>> write_command('r.category', map='test', rules='-', stdin="""
+... 1:trees
+... 2:water
+... """)
+0
+>>> read_command('r.category', map='test', separator=',')
+'1,trees\n2,water\n'
+
+
+Input and output with default separator
+=======================================
+
+>>> write_command('r.category', map='test', rules='-', stdin="""
+... 1:trees
+... 2:water
+... """)
+0
+>>> read_command('r.category', map='test', separator='tab')
+'1\ttrees\n2\twater\n'
+
+Tabs needs a special treatment.
+
+
+Category range
+==============
+
+>>> write_command('r.category', map='test_14', rules='-', stdin="""
+... 1:trees
+... 2:4:buildings
+... """)
+0
+>>> print(read_command('r.category', map='test_14', separator=' '))  # doctest: +NORMALIZE_WHITESPACE
+1 trees
+2 4:buildings
+3
+4
+<BLANKLINE>
+
+Output has spaces at the end of line.
+More importantly, the output of r.category is wrong but here we are expecting this wrong output.
+
+
+Floating point maps
+===================
+
+>>> write_command('r.category', map='test_d', rules='-', stdin="""
+... 0:1.5:trees
+... 1.5:3:buildings
+... """)
+0
+>>> print(read_command('r.category', map='test_d', separator=' ', vals=[1, 1.1, 2.1, 4]))  # doctest: +NORMALIZE_WHITESPACE
+1 trees
+1.1 trees
+2.1 buildings
+4
+<BLANKLINE>
+
+Output has spaces at the end of line.
+More importantly, the output of r.category is wrong but here we are expecting this wrong output.
+
+
+Separators in output
+====================
+
+Test output first because now we perhaps have data correct.
+
+>>> print(read_command('r.category', map='test', separator='space'))
+1 trees
+2 water
+<BLANKLINE>
+>>> print(read_command('r.category', map='test', separator=','))
+1,trees
+2,water
+<BLANKLINE>
+>>> print(read_command('r.category', map='test', separator='XYZ'))
+1XYZtrees
+2XYZwater
+<BLANKLINE>
+>>> print(read_command('r.category', map='test', separator='newline'))
+1
+trees
+2
+water
+<BLANKLINE>
+>>> print(read_command('r.category', map='test', separator='\n&\n'))
+1
+&
+trees
+2
+&
+water
+<BLANKLINE>
+
+
+Clean the results
+=================
+
+This is useful when test is runned in location which is not deleted
+when test finishes. It could test if everything which was expected
+to be created was created if it would check all outputs properly.
+
+>>> run_command('g.remove', rast='test')
+0
+>>> run_command('g.remove', rast='test_14')
+0
+>>> run_command('g.remove', rast='test_d')
+0


Property changes on: grass/trunk/raster/r.category/test_rcatetgory_doctest.txt
___________________________________________________________________
Added: svn:mime-type
   + text/plain
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native



More information about the grass-commit mailing list