test_i_band_library.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import os
  2. from grass.gunittest.case import TestCase
  3. from grass.gunittest.main import test
  4. from grass.gunittest.gmodules import call_module
  5. class TestBandsSystemDefined(TestCase):
  6. @staticmethod
  7. def _number_of_bands(**kwargs):
  8. gbands = call_module("i.band.library", **kwargs)
  9. return len(gbands.rstrip(os.linesep).split(os.linesep))
  10. def test_number_system_defined(self):
  11. """Test number of valid band identifiers"""
  12. # get number of valid band identifiers by i.band.library
  13. nbands = self._number_of_bands()
  14. # get number of valid band identifiers by Bands lib
  15. from grass.semantic_label import SemanticLabelReader
  16. nbands_ref = len(SemanticLabelReader().get_bands())
  17. self.assertEqual(nbands, nbands_ref)
  18. def test_number_s2(self):
  19. """Test number of S2 band identifiers (hardcoded, no changes expected)"""
  20. nbands = self._number_of_bands(pattern="S2")
  21. self.assertEqual(nbands, 13)
  22. def test_number_s2_1(self):
  23. """Test if S2_1 is defined (lower + upper case)"""
  24. band = "S2_1"
  25. for iband in [band, band.upper()]:
  26. nbands = self._number_of_bands(pattern=iband)
  27. self.assertEqual(nbands, 1)
  28. if __name__ == "__main__":
  29. test()