test_r_in_ascii.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. """
  2. Name: r.in.ascii test
  3. Purpose: Tests r.in.ascii and its flags/options.
  4. Author: Sunveer Singh, Google Code-in 2017
  5. Copyright: (C) 2017 by Sunveer Singh and the GRASS Development Team
  6. Licence: This program is free software under the GNU General Public
  7. License (>=v2). Read the file COPYING that comes with GRASS
  8. for details.
  9. """
  10. from grass.gunittest.case import TestCase
  11. from grass.gunittest.main import test
  12. from grass.script.core import read_command
  13. INPUT_NOQUOTES="""north: 4299000.00
  14. south: 4247000.00
  15. east: 528000.00
  16. west: 500000.00
  17. rows: 10
  18. cols: 15
  19. null: -9999
  20. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  21. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  22. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  23. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  24. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  25. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  26. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  27. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  28. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  29. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 """
  30. INPUT_TSV="""north: 4299000.00
  31. south: 4247000.00
  32. east: 528000.00
  33. west: 500000.00
  34. rows: 10
  35. cols: 15
  36. null: -9999
  37. 1\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 9\ 10\ 11\ 12\ 13\ 14\ 15
  38. 1\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 9\ 10\ 11\ 12\ 13\ 14\ 15
  39. 1\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 9\ 10\ 11\ 12\ 13\ 14\ 15
  40. 1\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3@ 4@ 5@ 6@ 7@ 8@ 9@ 10@ 11@ 12@ 13@ 14@ 15
  63. 1@ 2@ 3@ 4@ 5@ 6@ 7@ 8@ 9@ 10@ 11@ 12@ 13@ 14@ 15 """
  64. class SimpleCsvTestCase(TestCase):
  65. ascii_test = 'ascii'
  66. @classmethod
  67. def setUpClass(cls):
  68. """Use temporary region settings"""
  69. cls.use_temp_region()
  70. cls.runModule('g.region', n=4299000.00, s=4247000.00, e=528000.00, w=500000.00)
  71. @classmethod
  72. def tearDownClass(cls):
  73. cls.del_temp_region()
  74. def tearDown(self):
  75. """Remove the raster map after each test method"""
  76. self.runModule('g.remove', flags='f', type='raster', pattern=self.ascii_test)
  77. def test_no_text_delimeter(self):
  78. """Test loading no quotes"""
  79. self.assertModule('r.in.ascii', input='-', output=self.ascii_test,
  80. type='CELL', stdin_=INPUT_NOQUOTES)
  81. self.assertRasterMinMax(map=self.ascii_test, refmin=1, refmax=15,
  82. msg="ascii_test in degrees must be between 1 and 15")
  83. def test_text_delimeter(self):
  84. """Testing with external file"""
  85. self.assertModule('r.in.ascii', input='data/input_ascii.txt', output=self.ascii_test,
  86. type='CELL')
  87. self.assertRasterMinMax(map=self.ascii_test, refmin=1, refmax=5,
  88. msg="ascii_test in degrees must be between 1 and 5")
  89. def test_tsv(self):
  90. """Test loading TSV"""
  91. self.assertModule('r.in.ascii', input='-', output=self.ascii_test,
  92. type='CELL', stdin_=INPUT_TSV)
  93. self.assertRasterMinMax(map=self.ascii_test, refmin=1, refmax=15,
  94. msg="ascii_test in degrees must be between 1 and 15")
  95. def test_uncommon_delims(self):
  96. """Test loading with uncommon delimiters"""
  97. self.assertModule('r.in.ascii', input='-', output=self.ascii_test,
  98. type='CELL', stdin_=INPUT_UNCOMMON)
  99. self.assertRasterMinMax(map=self.ascii_test, refmin=1, refmax=15,
  100. msg="ascii_test in degrees must be between 1 and 15")
  101. if __name__ == '__main__':
  102. test()