#!/usr/bin/env python ############################################################################ # # NAME: i_saocom_import_test # # AUTHOR: Santiago Seppi (sseppi@conae.gov.ar) # # PURPOSE: This is a test file for i.saocom.import # # COPYRIGHT: (C) 2023 by Santiago Seppi and the GRASS Development Team # # This program is free software under the GNU General Public # License (>=v2). Read the file COPYING that comes with GRASS # for details. # ############################################################################# # Dependencies from grass.gunittest.case import TestCase from grass.gunittest.main import test import grass.script as grass import os import shutil # Tests class TestImport(TestCase): # Setup variables to be used for outputs basename='SAO1B_20211222' pols = ['hh'] output_real = f'{basename}_{pols[0]}_real' output_imag = f'{basename}_{pols[0]}_imag' zip_file = 'data/S1B_OPER_SAR_EOSSP__CORE_L1A_OLF_20211225T165228.zip' is_zip = 'yes' multilook=4,4 ref_raster='ref_hh_real' expected_raster = f'{basename}_hh_real' @classmethod def setUpClass(cls): """Ensures expected computational region""" # to not override mapset's region (which might be used by other tests) cls.use_temp_region() # cls.runModule or self.runModule is used for general module calls cls.runModule("g.region", raster=cls.ref_raster) @classmethod def tearDownClass(cls): """Remove temporary region""" cls.del_temp_region() def tearDown(self): """ Remove the outputs created from the i.saocom.import module This is executed after each test run. """ self.runModule("g.remove", flags="f", type="raster", name=self.output_real) self.runModule("g.remove", flags="f", type="raster", name=self.output_imag) #Remove the GCPS.csv file and its contaning folder shutil.rmtree(os.path.join('saocom','PERMANENT','cell_misc',self.basename)) def test_output(self): """Test that imported raster is the same as reference""" # assertModule is used to call module which we test # we expect module to finish successfully self.assertModule( "i.saocom.import", data=self.zip_file, pols = self.pols, is_zip=self.is_zip, basename=self.basename, multilook=self.multilook ) self.assertRastersEqual( actual=self.output_real, reference=self.ref_raster, precision=6 ) self.assertRasterExists( name=self.expected_raster ) if __name__ == "__main__": test()