diff --git a/src/lisflood/global_modules/settings.py b/src/lisflood/global_modules/settings.py index 6ee4f6e7..7a307c94 100644 --- a/src/lisflood/global_modules/settings.py +++ b/src/lisflood/global_modules/settings.py @@ -37,7 +37,7 @@ from pandas._libs.tslibs.parsing import parse_time_string import numpy as np -from .errors import LisfloodError, LisfloodWarning +from .errors import LisfloodError, LisfloodWarning, LisfloodFileError from .decorators import cached from .default_options import default_options @@ -190,7 +190,8 @@ def __str__(self): def __init__(self, settings_file): dom = xml.dom.minidom.parse(settings_file) - self.settings_path = os.path.normpath(os.path.dirname((os.path.abspath(settings_file)))) + self.settings_dir = os.path.normpath(os.path.dirname((os.path.abspath(settings_file)))) + self.settings_path = os.path.normpath(os.path.abspath(settings_file)) user_settings, bindings = self._bindings(dom) self.timestep_init = None if not bindings.get('timestepInit') else bindings['timestepInit'] self.output_dir = self._out_dirs(user_settings) @@ -315,7 +316,7 @@ def _bindings(self, dom): # built-in user variables user = { 'ProjectDir': project_dir, 'ProjectPath': project_dir, - 'SettingsDir': self.settings_path, 'SettingsPath': self.settings_path, + 'SettingsDir': self.settings_dir, 'SettingsPath': self.settings_dir, } # get all the bindings in the first part of the settingsfile = lfuser # list of elements "lfuser" in settings file @@ -342,9 +343,11 @@ def _bindings(self, dom): binding[i] = expr # Read the calendar type from the precipitation forcing NetCDF file - with Dataset(binding["PrecipitationMaps"] + ".nc") as nc: + precipitation_map_path = binding["PrecipitationMaps"] + '.nc' + if not os.path.exists(precipitation_map_path): + raise LisfloodFileError(precipitation_map_path) + with Dataset(precipitation_map_path) as nc: binding["calendar_type"] = get_calendar_type(nc) - return user, binding @staticmethod @@ -358,8 +361,7 @@ def _report_steps(user_settings, bindings): for i in repsteps: if '..' in i: j = list(map(int, i.split('..'))) - for jj in range(j[0], j[1] + 1): - jjj.append(jj) + jjj = list(range(j[0], j[1] + 1)) else: jjj.append(i) res['rep'] = list(map(int, jjj)) diff --git a/tests/__init__.py b/tests/__init__.py index f98c4e73..509cbff4 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -35,14 +35,14 @@ class TestLis(object): reference_files = { - 'dis_drina': {'outpath': os.path.join(current_dir, 'data/Drina/reference/dis'), - 'report_map': 'DischargeMaps', - 'report_tss': 'DisTS' - }, - 'dis_madeira': {'outpath': os.path.join(current_dir, 'data/Madeira/reference/dis'), - 'report_map': 'DischargeMaps', - 'report_tss': 'DisTS' - } + 'dis_1': {'outpath': os.path.join(current_dir, 'data/TestCatchment1/reference/dis'), + 'report_map': 'DischargeMaps', + 'report_tss': 'DisTS' + }, + 'dis_2': {'outpath': os.path.join(current_dir, 'data/TestCatchment2/reference/dis'), + 'report_map': 'DischargeMaps', + 'report_tss': 'DisTS' + } } domain = None @@ -92,7 +92,9 @@ def check_var_step(cls, var, step): perc_wrong = float(wrong_values_size * 100) / float(diff_values.size) if perc_wrong >= cls.max_perc_wrong or perc_wrong >= cls.max_perc_wrong_large_diff and large_diff: print('[ERROR]') - print('Var: {} - STEP {}: {:3.9f}% of values are different. max diff: {:3.4f}'.format(var, step, perc_wrong, max_diff)) + print('Var: {} - STEP {}: {:3.9f}% of values are different. max diff: {:3.4f}'.format(var, step, + perc_wrong, + max_diff)) return False else: print('[OK] {} {}'.format(var, step)) diff --git a/tests/smoke_tests.py b/tests/smoke_tests.py index b4cdcc66..299945a5 100644 --- a/tests/smoke_tests.py +++ b/tests/smoke_tests.py @@ -23,15 +23,15 @@ current_dir = os.path.dirname(os.path.abspath(__file__)) -class TestDrina(TestLis): - settings_path = os.path.join(current_dir, 'data/Drina/settings/lisfloodSettings_cold_day_base.xml') +class TestCatch1(TestLis): + settings_path = os.path.join(current_dir, 'data/TestCatchment1/settings/cold_day_base.xml') def test_dis(self): - return self.listest('dis_drina') + return self.listest('dis_1') -class TestMadeira(TestLis): - settings_path = os.path.join(current_dir, 'data/Madeira/settings/settings_Madeira_prerun.xml') +class TestCatch2(TestLis): + settings_path = os.path.join(current_dir, 'data/TestCatchment2/settings/prerun.xml') def test_dis(self): - return self.listest('dis_madeira') + return self.listest('dis_2')