Skip to content

Commit

Permalink
bugfix for slow tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Cinzia Mazzetti committed Nov 29, 2024
1 parent e094ccd commit 732b31b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/test_caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def run(self, dt_sec, step_start, step_end):
self.compare_reference('dis', check='tss', step_length=dt_sec)
self.compare_reference('chanq', check='tss', step_length=dt_sec)


def test_dis_daily(self):
self.run('86400', '02/01/2016 06:00', '02/07/2016 06:00')

Expand Down
4 changes: 4 additions & 0 deletions tests/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
@pytest.mark.slow
class TestCatch(ETRS89TestCase):
case_dir = os.path.join(os.path.dirname(__file__), 'data', 'LF_ETRS89_UseCase')
mk_path_out(os.path.join(case_dir, 'out'))

modules_to_set = (
'SplitRouting',
'simulateReservoirs',
Expand Down Expand Up @@ -68,6 +70,7 @@ def run(self, dt_sec, step_start, step_end):
'StepEnd': step_end,
'DtSec': dt_sec,
'PathOut': output_dir})
mk_path_out(output_dir)
lisfloodexe(settings)

def test_output_daily(self):
Expand Down Expand Up @@ -115,6 +118,7 @@ def test_initvars(self):
vars_to_set={'StepStart': '02/02/2016 06:00',
'StepEnd': '05/02/2016 06:00',
'PathOut': output_dir})
mk_path_out(output_dir)
lisfloodexe(settings)
initcond_files = ('ch2cr.end.nc', 'chanq.end.nc', 'chcro.end.nc',
'chside.end.nc', 'cseal.end.nc', 'cum.end.nc',
Expand Down
27 changes: 27 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,33 @@ class ETRS89TestCase(object):
},
},
}
def teardown_method(self):
settings = LisSettings.instance()
output_dir = settings.output_dir
shutil.rmtree(output_dir)

@classmethod
def compare_reference(cls, variable='dis', check='map', step_length='86400'):
"""
:param variable: variable to check. Default 'dis' (Discharge)
:param check: either 'map' or 'tss'. Default 'map'
:param step_length: DtSec (86400 for daily and 21600 for 6h run)
"""

settings = LisSettings.instance()
binding = settings.binding
reference = cls.reference_files[variable][step_length][check]

if check == 'map':
output_map = os.path.normpath(binding[cls.reference_files[variable]['report_map']]) + '.nc'
comparator = NetCDFComparator(settings.maskpath)
comparator.compare_files(reference, output_map)
elif check == 'tss':
output_tss = binding[cls.reference_files[variable]['report_tss']]
comparator = TSSComparator()
comparator.compare_files(reference, output_tss)
# If there are differences, test fails before reaching this line (AssertionError(s) in comparator methods)
assert True

class MCTTestCase(object):
case_dir = os.path.join(os.path.dirname(__file__), 'data', 'LF_MCT_UseCase')
Expand Down

0 comments on commit 732b31b

Please sign in to comment.