def test_preserve_existing_raster(self): """Test that existing raster is preserved""" # TODO: write the same for other types # TODO: create a general functions to avoid duplication runivar = SimpleModule('r.univar', flags='g', map='exists') self.runModule(runivar, expecting_stdout=True) original_runivar = text_to_keyvalue(runivar.outputs.stdout, sep='=', skip_empty=True) module = SimpleModule('g.rename', raster=['rename_3', 'exists'], overwrite=False) self.assertModule(module) self.assertRasterExists( 'exists', msg="Destination (existing) map (to) should exist") self.assertRasterExists('rename_3', msg="Source map (from) should exist") runivar = SimpleModule('r.univar', flags='g', map='exists') self.runModule(runivar, expecting_stdout=True) new_runivar = text_to_keyvalue(runivar.outputs.stdout, sep='=', skip_empty=True) if not keyvalue_equals( dict_a=original_runivar, dict_b=new_runivar, precision=1e-7): unused, missing, mismatch = diff_keyvalue(dict_a=original_runivar, dict_b=new_runivar, precision=1e-7) if mismatch: msg = "Raster map changed. It was probably overwritten.\n" msg += "Difference between r.univar of maps:\n" msg += "mismatch values" msg += " (key, reference, actual): %s\n" % mismatch self.fail(msg)
def test_preserve_existing_raster(self): """Test that existing raster is preserved""" # TODO: write the same for other types # TODO: create a general functions to avoid duplication runivar = SimpleModule('r.univar', flags='g', map='exists') self.runModule(runivar, expecting_stdout=True) original_runivar = text_to_keyvalue(runivar.outputs.stdout, sep='=', skip_empty=True) module = SimpleModule('g.rename', raster=['rename_3', 'exists'], overwrite=False) self.assertModule(module) self.assertRasterExists('exists', msg="Destination (existing) map (to) should exist") self.assertRasterExists('rename_3', msg="Source map (from) should exist") runivar = SimpleModule('r.univar', flags='g', map='exists') self.runModule(runivar, expecting_stdout=True) new_runivar = text_to_keyvalue(runivar.outputs.stdout, sep='=', skip_empty=True) if not keyvalue_equals(dict_a=original_runivar, dict_b=new_runivar, precision=1e-7): unused, missing, mismatch = diff_keyvalue(dict_a=original_runivar, dict_b=new_runivar, precision=1e-7) if mismatch: msg = "Raster map changed. It was probably overwritten.\n" msg += "Difference between r.univar of maps:\n" msg += "mismatch values" msg += " (key, reference, actual): %s\n" % mismatch self.fail(msg)
def test_overwrite_existing_raster(self): """Test that existing raster is overriden if desired""" runivar_source = SimpleModule('r.univar', flags='g', map='rename_3') self.runModule(runivar_source, expecting_stdout=True) original_runivar_source = text_to_keyvalue( runivar_source.outputs.stdout, sep='=', skip_empty=True) runivar_target = SimpleModule('r.univar', flags='g', map='exists') self.runModule(runivar_target, expecting_stdout=True) original_runivar_target = text_to_keyvalue( runivar_target.outputs.stdout, sep='=', skip_empty=True) module = SimpleModule('g.rename', raster=['rename_3', 'exists'], overwrite=True) self.assertModule(module) self.assertRasterExists( 'exists', msg= "Destination (here: existing) map (to) should exist after rename") self.assertFalse(is_map_in_mapset('rename_3', type='raster'), msg="Source map (from) should not exist after rename") runivar = SimpleModule('r.univar', flags='g', map='exists') self.runModule(runivar, expecting_stdout=True) new_runivar = text_to_keyvalue(runivar.outputs.stdout, sep='=', skip_empty=True) # both these tests are probably redundant but let's test thoroughly if keyvalue_equals(dict_a=original_runivar_target, dict_b=new_runivar, precision=1e-7): msg = "Raster map did not change. It probably wasn't overwritten." self.fail(msg) if not keyvalue_equals(dict_a=original_runivar_source, dict_b=new_runivar, precision=1e-7): unused, missing, mismatch = diff_keyvalue( dict_a=original_runivar_source, dict_b=new_runivar, precision=1e-7) if mismatch: msg = "Destination raster map is not the same as source." msg += " It probably wasn't overwritten.\n" msg += "Difference between r.univar of maps:\n" msg += "mismatch values" msg += " (key, reference, actual): %s\n" % mismatch self.fail(msg)
def test_overwrite_existing_raster(self): """Test that existing raster is overriden if desired""" runivar_source = SimpleModule('r.univar', flags='g', map='rename_3') self.runModule(runivar_source, expecting_stdout=True) original_runivar_source = text_to_keyvalue(runivar_source.outputs.stdout, sep='=', skip_empty=True) runivar_target = SimpleModule('r.univar', flags='g', map='exists') self.runModule(runivar_target, expecting_stdout=True) original_runivar_target = text_to_keyvalue(runivar_target.outputs.stdout, sep='=', skip_empty=True) module = SimpleModule('g.rename', raster=['rename_3', 'exists'], overwrite=True) self.assertModule(module) self.assertRasterExists('exists', msg="Destination (here: existing) map (to) should exist after rename") self.assertFalse(is_map_in_mapset('rename_3', type='raster'), msg="Source map (from) should not exist after rename") runivar = SimpleModule('r.univar', flags='g', map='exists') self.runModule(runivar, expecting_stdout=True) new_runivar = text_to_keyvalue(runivar.outputs.stdout, sep='=', skip_empty=True) # both these tests are probably redundant but let's test thoroughly if keyvalue_equals(dict_a=original_runivar_target, dict_b=new_runivar, precision=1e-7): msg = "Raster map did not change. It probably wasn't overwritten." self.fail(msg) if not keyvalue_equals(dict_a=original_runivar_source, dict_b=new_runivar, precision=1e-7): unused, missing, mismatch = diff_keyvalue(dict_a=original_runivar_source, dict_b=new_runivar, precision=1e-7) if mismatch: msg = "Destination raster map is not the same as source." msg += " It probably wasn't overwritten.\n" msg += "Difference between r.univar of maps:\n" msg += "mismatch values" msg += " (key, reference, actual): %s\n" % mismatch self.fail(msg)