Skip to content

Commit

Permalink
add a multifinalization flag and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Moodie committed May 25, 2020
1 parent 9e98300 commit 48c7486
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pyDeltaRCM/deltaRCM_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def finalize(self):
except Exception:
pass

self._is_finalized = True

# define properties

@property
Expand Down
3 changes: 3 additions & 0 deletions pyDeltaRCM/deltaRCM_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ def run_one_timestep(self):
print('-' * 20)
print('Timestep: ' + str(self._time))

if self._is_finalized:
raise RuntimeError('Cannot update model, model already finalized!')

for iteration in range(self.itermax):

self.init_water_iteration()
Expand Down
2 changes: 2 additions & 0 deletions pyDeltaRCM/init_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ def create_other_variables(self):
if self.case_prefix:
self.prefix += self.case_prefix + '_'

self._is_finalized = False

def create_domain(self):
"""
Creates the model domain
Expand Down
20 changes: 20 additions & 0 deletions tests/test_deltaRCM_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,28 @@ def test_init():
test the deltaRCM_driver init (happened when delta.initialize was run)
"""
assert delta._time == 0.
assert delta._is_finalized == False


def test_update():
delta.update()
assert delta._time == 1.0
assert delta._is_finalized == False


def test_finalize():
delta.finalize()
assert delta._is_finalized == True


@pytest.mark.xfail(raises=RuntimeError, strict=True)
def test_multifinalization_error():
err_delta = pyDeltaRCM(input_file=os.path.join(os.getcwd(), 'tests', 'test.yaml'))
err_delta.update()
# test will Fail if any assertion is wrong
assert err_delta._time == 1.0
assert err_delta._is_finalized == False
err_delta.finalize()
assert err_delta._is_finalized == True
# next line should throw RuntimeError and test will xFail
err_delta.update()

0 comments on commit 48c7486

Please sign in to comment.