Skip to content

Commit d8c21ad

Browse files
committed
Minor cleaning in unit test, reactivating TestCachingSlow
1 parent 75c5901 commit d8c21ad

File tree

5 files changed

+81
-97
lines changed

5 files changed

+81
-97
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.3.1 MCT
1+
4.3.1.9998

docs/media/lisfloodSettings_reference_prerun_optional_init_v4.0.0.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4959,7 +4959,7 @@ Map with location of reservoirs (number)
49594959
</comment>
49604960
</textvar>
49614961

4962-
<textvar name="ReservoirInitialFill" value="$(ReservoirInitialFill)">
4962+
<textvar name="ReservoirInitialFillValue" value="$(ReservoirInitialFillValue)">
49634963
<comment>
49644964
Initial reservoir storage (fraction)
49654965
</comment>

tests/data/LF_MCT_UseCase/maps/table2map/soildepth3_o.nc.aux.xml

-10
This file was deleted.

tests/test_caching.py

+78-80
Original file line numberDiff line numberDiff line change
@@ -83,83 +83,81 @@ def teardown_method(self):
8383
shutil.rmtree(self.out_dir_b, ignore_errors=True)
8484
Cache.clear()
8585

86-
# do_not_run
87-
# The slow test does not run but Carlo has fixed it
88-
# @pytest.mark.slow
89-
# class TestCachingSlow(ETRS89TestCase):
90-
# case_dir = os.path.join(os.path.dirname(__file__), 'data', 'LF_ETRS89_UseCase')
91-
#
92-
# modules_to_set = (
93-
# 'SplitRouting',
94-
# 'simulateReservoirs',
95-
# 'simulateLakes',
96-
# 'drainedIrrigation',
97-
# 'openwaterevapo',
98-
# 'riceIrrigation',
99-
# 'wateruse',
100-
# 'useWaterDemandAveYear',
101-
# 'wateruseRegion',
102-
# 'TransientWaterDemandChange',
103-
# )
104-
# settings_files = {
105-
# 'base': os.path.join(case_dir, 'settings/base.xml'),
106-
# 'prerun': os.path.join(case_dir, 'settings/prerun.xml')
107-
# }
108-
#
109-
# def run(self, dt_sec, step_start, step_end):
110-
# output_dir = mk_path_out('data/LF_ETRS89_UseCase/out/test_results{}'.format(dt_sec))
111-
# opts_to_unset = (
112-
# "repStateSites", "repRateSites", "repStateUpsGauges", "repRateUpsGauges", "repMeteoUpsGauges",
113-
# "repsimulateLakes", "repStateMaps",
114-
# "repsimulateReservoirs", "repSnowMaps", "repPFMaps", "repLZMaps", "repUZMaps",
115-
# "repGwPercUZLZMaps", "repRWS", "repTotalWUse", "repWIndex",
116-
# "repSurfaceRunoffMaps", "repRainMaps", "repSnowMaps", "repSnowCoverMaps", "repSnowMeltMaps", "repThetaMaps",
117-
# "repThetaForestMaps", "repLZMaps", "repUZMaps",
118-
# "repGwPercUZLZMaps", "repRWS", "repPFMaps", "repPFForestMaps"
119-
# )
120-
# settings = setoptions(self.settings_files['base'],
121-
# opts_to_set=('repDischargeTs', 'repDischargeMaps',) + self.modules_to_set,
122-
# opts_to_unset=opts_to_unset,
123-
# vars_to_set={'StepStart': step_start,
124-
# 'StepEnd': step_end,
125-
# 'DtSec': dt_sec,
126-
# 'PathOut': output_dir,
127-
# 'MapsCaching': 'True'})
128-
# lisfloodexe(settings)
129-
#
130-
# cache_size_a = Cache.size()
131-
# cache_found_a = Cache.values_found()
132-
# print('Cache size is {}'.format(cache_size_a))
133-
# print('Items found: {}'.format(cache_found_a))
134-
#
135-
# assert cache_found_a == 1 # apparently one map is called twice
136-
#
137-
# lisfloodexe(settings)
138-
#
139-
# cache_size_b = Cache.size()
140-
# cache_found_b = Cache.values_found()
141-
# print('Cache size is {}'.format(cache_size_b))
142-
# print('Items found: {}'.format(cache_found_b))
143-
#
144-
# Cache.info()
145-
#
146-
# assert cache_found_b == cache_size_b + 2
147-
# assert cache_size_a == cache_size_b
148-
#
149-
# self.compare_reference('dis', check='map', step_length=dt_sec)
150-
# self.compare_reference('dis', check='tss', step_length=dt_sec)
151-
# self.compare_reference('chanq', check='tss', step_length=dt_sec)
152-
#
153-
#
154-
# def test_dis_daily(self):
155-
# self.run('86400', '02/01/2016 06:00', '02/07/2016 06:00')
156-
#
157-
# def test_dis_6h(self):
158-
# self.run('21600', '02/01/2016 06:00', '02/07/2016 06:00')
159-
#
160-
# def teardown_method(self):
161-
# print('Cleaning directories and cache')
162-
# settings = LisSettings.instance()
163-
# output_dir = settings.output_dir
164-
# shutil.rmtree(output_dir)
165-
# Cache.clear()
86+
@pytest.mark.slow
87+
class TestCachingSlow(ETRS89TestCase):
88+
case_dir = os.path.join(os.path.dirname(__file__), 'data', 'LF_ETRS89_UseCase')
89+
90+
modules_to_set = (
91+
'SplitRouting',
92+
'simulateReservoirs',
93+
'simulateLakes',
94+
'drainedIrrigation',
95+
'openwaterevapo',
96+
'riceIrrigation',
97+
'wateruse',
98+
'useWaterDemandAveYear',
99+
'wateruseRegion',
100+
'TransientWaterDemandChange',
101+
)
102+
settings_files = {
103+
'base': os.path.join(case_dir, 'settings/base.xml'),
104+
'prerun': os.path.join(case_dir, 'settings/prerun.xml')
105+
}
106+
107+
def run(self, dt_sec, step_start, step_end):
108+
output_dir = mk_path_out('data/LF_ETRS89_UseCase/out/test_results{}'.format(dt_sec))
109+
opts_to_unset = (
110+
"repStateSites", "repRateSites", "repStateUpsGauges", "repRateUpsGauges", "repMeteoUpsGauges",
111+
"repsimulateLakes", "repStateMaps",
112+
"repsimulateReservoirs", "repSnowMaps", "repPFMaps", "repLZMaps", "repUZMaps",
113+
"repGwPercUZLZMaps", "repRWS", "repTotalWUse", "repWIndex",
114+
"repSurfaceRunoffMaps", "repRainMaps", "repSnowMaps", "repSnowCoverMaps", "repSnowMeltMaps", "repThetaMaps",
115+
"repThetaForestMaps", "repLZMaps", "repUZMaps",
116+
"repGwPercUZLZMaps", "repRWS", "repPFMaps", "repPFForestMaps"
117+
)
118+
settings = setoptions(self.settings_files['base'],
119+
opts_to_set=('repDischargeTs', 'repDischargeMaps',) + self.modules_to_set,
120+
opts_to_unset=opts_to_unset,
121+
vars_to_set={'StepStart': step_start,
122+
'StepEnd': step_end,
123+
'DtSec': dt_sec,
124+
'PathOut': output_dir,
125+
'MapsCaching': 'True'})
126+
lisfloodexe(settings)
127+
128+
cache_size_a = Cache.size()
129+
cache_found_a = Cache.values_found()
130+
print('Cache size is {}'.format(cache_size_a))
131+
print('Items found: {}'.format(cache_found_a))
132+
133+
assert cache_found_a == 1 # apparently one map is called twice
134+
135+
lisfloodexe(settings)
136+
137+
cache_size_b = Cache.size()
138+
cache_found_b = Cache.values_found()
139+
print('Cache size is {}'.format(cache_size_b))
140+
print('Items found: {}'.format(cache_found_b))
141+
142+
Cache.info()
143+
144+
assert cache_found_b == cache_size_b + 2
145+
assert cache_size_a == cache_size_b
146+
147+
self.compare_reference('dis', check='map', step_length=dt_sec)
148+
self.compare_reference('dis', check='tss', step_length=dt_sec)
149+
self.compare_reference('chanq', check='tss', step_length=dt_sec)
150+
151+
152+
def test_dis_daily(self):
153+
self.run('86400', '02/01/2016 06:00', '02/07/2016 06:00')
154+
155+
def test_dis_6h(self):
156+
self.run('21600', '02/01/2016 06:00', '02/07/2016 06:00')
157+
158+
def teardown_method(self):
159+
print('Cleaning directories and cache')
160+
settings = LisSettings.instance()
161+
output_dir = settings.output_dir
162+
shutil.rmtree(output_dir)
163+
Cache.clear()

tests/test_water_abstraction.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
from __future__ import absolute_import
22
import os
3-
import datetime
4-
import shutil
5-
import pytest
63

74
from lisfloodutilities.compare.nc import NetCDFComparator
85

96
from lisflood.main import lisfloodexe
10-
from lisflood.global_modules.settings import LisSettings
117

128
from .test_utils import setoptions, mk_path_out, ETRS89TestCase
139

1410

15-
class TestCaching(ETRS89TestCase):
11+
class TestWaterAbstraction(ETRS89TestCase):
1612
def test_waterabstraction_24h(self):
1713
dt_sec = 86400
1814
self.run_lisflood_waterabstraction(dt_sec)

0 commit comments

Comments
 (0)