generated from NOAA-OWP/owp-open-source-project-template
-
Notifications
You must be signed in to change notification settings - Fork 18
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
fix(test): test_output
's monkeypatching of pd.read_csv
#172
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1812870
refactor: update type hints, remove unused variables, etc.
aaraney 0407eb9
style: formatting
aaraney 407e217
chore(typing): fix return type hint
aaraney 1bb2a5f
chore: use canonical pandas import style
aaraney afb30b9
test: fix monkeypatch; fixes #166
aaraney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,52 @@ | ||
import pytest | ||
""" | ||
Test suite for calibratable_catchment | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
if TYPE_CHECKING: | ||
from ngen.cal.calibration_cathment import CalibrationCatchment | ||
|
||
""" | ||
Test suite for calibratable_catchment | ||
""" | ||
|
||
@pytest.mark.usefixtures("catchment") | ||
def test_df(catchment: 'CalibrationCatchment') -> None: | ||
def test_df(catchment: CalibrationCatchment) -> None: | ||
""" | ||
Test the catchments proper construction of the parameter dataframe | ||
Test the catchments proper construction of the parameter dataframe | ||
""" | ||
assert catchment.df.iloc[0]['param'] == 'some_param' | ||
assert catchment.df.iloc[0]['0'] == 0.5 | ||
assert catchment.df.iloc[0]['min'] == 0.0 | ||
assert catchment.df.iloc[0]['max'] == 1.0 | ||
assert catchment.df.iloc[0]["param"] == "some_param" | ||
assert catchment.df.iloc[0]["0"] == 0.5 | ||
assert catchment.df.iloc[0]["min"] == 0.0 | ||
assert catchment.df.iloc[0]["max"] == 1.0 | ||
|
||
@pytest.mark.usefixtures("catchment2") | ||
def test_output(catchment2: 'CalibrationCatchment', monkeypatch) -> None: | ||
|
||
def test_output( | ||
catchment2: CalibrationCatchment, | ||
monkeypatch: pytest.MonkeyPatch, | ||
) -> None: | ||
""" | ||
Test proper handling of non-existent output | ||
Test proper handling of non-existent output | ||
""" | ||
import pandas as pd | ||
monkeypatch.setattr(pd, "read_csv", lambda *args, **kwargs: FileNotFoundError()) | ||
|
||
def file_not_found(*args, **kwargs): | ||
raise FileNotFoundError | ||
|
||
monkeypatch.setattr(pd, "read_csv", file_not_found) | ||
output = catchment2.output | ||
assert output == None | ||
assert output is None | ||
|
||
|
||
@pytest.mark.usefixtures("catchment") | ||
def test_observed(catchment: 'CalibrationCatchment') -> None: | ||
def test_observed(catchment: CalibrationCatchment) -> None: | ||
""" | ||
Test proper handling of non-existent output | ||
Test proper handling of non-existent output | ||
""" | ||
catchment.observed = None | ||
with pytest.raises(RuntimeError): | ||
obs = catchment.observed | ||
catchment.observed | ||
|
||
|
||
#TODO test catchment_set | ||
#TODO test evaluation_range? | ||
# TODO test catchment_set | ||
# TODO test evaluation_range? |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Killing my lambda 🤣