Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Rework tests for the HELP30 library #70

Merged
merged 6 commits into from
Mar 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 14 additions & 24 deletions pyhelp/tests/test_help3o.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-

# Copyright © 2018 PyHelp Project Contributors
# https://github.com/jnsebgosselin/gwhat
# =============================================================================
# Copyright © PyHelp Project Contributors
# https://github.com/cgq-qgc/pyhelp
#
# This file is part of PyHelp.
# Licensed under the terms of the GNU General Public License.
# Licensed under the terms of the MIT License.
# =============================================================================


# ---- Standard Library Imports
Expand All @@ -25,17 +26,12 @@

# ---- Fixtures
@pytest.fixture(scope="module")
def test_folder():
return osp.join(osp.dirname(__rootdir__), 'pyhelp', 'tests')

def rca_folder():
return osp.join(__rootdir__, 'tests', 'rca_original_testcase_1997')

@pytest.fixture(scope="module")
def rca_folder(test_folder):
return osp.join(test_folder, 'rca_original_testcase_1997')


@pytest.fixture(scope="module")
def rca_params(rca_folder):
@pytest.fixture
def rca_params(rca_folder, tmp_path):
daily_out = 0
monthly_out = 1
yearly_out = 0
Expand All @@ -48,7 +44,7 @@ def rca_params(rca_folder):
osp.join(rca_folder, 'RCRA.D13'),
osp.join(rca_folder, 'RCRA.D11'),
osp.join(rca_folder, 'RCRA.D10'),
osp.join(rca_folder, 'NEW_RCA.OUT'),
osp.join(tmp_path, 'NEW_RCA.OUT'),
daily_out,
monthly_out,
yearly_out,
Expand All @@ -58,15 +54,11 @@ def rca_params(rca_folder):
tfsoil)


# ---- Test HelpManager
# ---- Tests
def test_run_help3o(rca_params):
"""
Test that the HELP3O extension run and create an output file as expected.
"""
if osp.exists(rca_params[5]):
os.remove(rca_params[5])
assert not osp.exists(rca_params[5])

HELP3O.run_simulation(*rca_params)
assert osp.exists(rca_params[5])

Expand All @@ -76,17 +68,13 @@ def test_run_help_singlecell(rca_params):
Run HELP for a single cell using the RCA test case and assert that the
results are as expected.
"""
if osp.exists(rca_params[5]):
os.remove(rca_params[5])
assert not osp.exists(rca_params[5])

cellname, results = run_help_singlecell(('rca', rca_params))
assert not osp.exists(rca_params[5])
assert cellname == 'rca'

# Precipitations.
precip = np.sum(results['precip'] * 0.0393701, axis=1)
for i, expected_result in enumerate([48.5, 58.32, 56.71]):
for i, expected_result in enumerate([48.53, 58.32, 56.71]):
assert abs(precip[i] - expected_result) < 0.1, 'precip year %i' % i

# Runoff.
Expand All @@ -105,11 +93,13 @@ def test_run_help_singlecell(rca_params):
assert abs(evapo[i] - expected_result) < 0.1, 'evapo year %i' % i

# Superficial subsurface runoff.
# (DRAINAGE COLLECTED FROM LAYER 2)
subrun1 = np.sum(results['subrun1'] * 0.0393701, axis=1)
for i, expected_result in enumerate([15.4971, 22.8698, 19.1360]):
assert abs(subrun1[i] - expected_result) < 0.1, 'subrun1 year %i' % i

# Deep subsurface runoff.
# (DRAINAGE COLLECTED FROM LAYER 7 + DRAINAGE COLLECTED FROM LAYER 9)
subrun2 = np.sum(results['subrun2'] * 0.0393701, axis=1)
expected_results = (0.0543 + 0.0833, 0.1481 + 0.1658, 0.1835 + 0.1935)
for i, expected_result in enumerate(expected_results):
Expand Down