test_i_band.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. from grass.gunittest.case import TestCase
  2. from grass.gunittest.main import test
  3. from grass.gunittest.gmodules import SimpleModule, call_module
  4. from grass.pygrass.raster import RasterRow
  5. class TestBandsSystemDefined(TestCase):
  6. # note that full NC dataset is needed
  7. raster_map = "lsat7_2002_10"
  8. band_ref = "L7_1"
  9. def read_band_ref(self):
  10. with RasterRow(self.raster_map) as rast:
  11. band_ref = rast.info.band_reference
  12. return band_ref
  13. def test_band_ref_assign_not_current_mapset(self):
  14. # it is assumed that we are not in PERMANENT mapset
  15. module = SimpleModule(
  16. "i.band", map=self.raster_map + "@PERMANENT", band=self.band_ref
  17. )
  18. self.assertModuleFail(module)
  19. def test_band_ref_assign(self):
  20. # Copy raster map to the current mapset
  21. call_module("g.copy", raster="{m}@PERMANENT,{m}".format(m=self.raster_map))
  22. module = SimpleModule("i.band", map=self.raster_map, band=self.band_ref)
  23. self.assertModule(module)
  24. # check also using pygrass
  25. self.assertEqual(self.read_band_ref(), self.band_ref)
  26. def test_band_ref_dissociate(self):
  27. module = SimpleModule("i.band", operation="remove", map=self.raster_map)
  28. self.assertModule(module)
  29. # check also using pygrass
  30. self.assertEqual(self.read_band_ref(), None)
  31. if __name__ == "__main__":
  32. test()