test_r_import.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from grass.gunittest.case import TestCase
  2. from grass.gunittest.main import test
  3. class TestRImportRegion(TestCase):
  4. imported = 'test_r_import_imported'
  5. @classmethod
  6. def setUpClass(cls):
  7. cls.runModule('g.region', raster='elevation')
  8. def tearDown(cls):
  9. """Remove imported map after each test method"""
  10. cls.runModule('g.remove', flags='f', type='raster',
  11. name=cls.imported)
  12. def test_import_estimate(self):
  13. """Test e flag"""
  14. self.assertModule('r.import', input='data/data2.asc', output=self.imported,
  15. resample='nearest', flags='e')
  16. self.assertRasterDoesNotExist(name=self.imported)
  17. def test_import_same_proj_tif(self):
  18. """Import tif in same proj, default params"""
  19. self.assertModule('r.import', input='data/data1.tif', output=self.imported,
  20. resample='bilinear')
  21. reference = dict(north=223490, south=223390, east=636820, west=636710,
  22. nsres=10, ewres=10, datatype='FCELL')
  23. self.assertRasterFitsInfo(raster=self.imported, reference=reference)
  24. def test_import_asc_custom_res(self):
  25. """Import ASC in different projection, with specified resolution"""
  26. self.assertModule('r.import', input='data/data2.asc', output=self.imported,
  27. resample='nearest', resolution='value', resolution_value=30)
  28. reference = dict(rows=3, cols=4,
  29. nsres=30, ewres=30, datatype='CELL')
  30. self.assertRasterFitsInfo(raster=self.imported, reference=reference, precision=1.1)
  31. def test_import_asc_region_extent(self):
  32. """Import ASC in different projection in specified region"""
  33. self.runModule('g.region', raster='elevation', n=223655, s=223600)
  34. self.assertModule('r.import', input='data/data2.asc', output=self.imported,
  35. resample='nearest', extent='region', resolution='region')
  36. reference = dict(north=223655, south=223600)
  37. self.assertRasterFitsInfo(raster=self.imported, reference=reference, precision=1e-6)
  38. if __name__ == '__main__':
  39. test()