-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #297 from informatics-lab/fix-nearcast-variables
Fix nearcast variables
- Loading branch information
Showing
3 changed files
with
30 additions
and
2 deletions.
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pytest | ||
import unittest.mock | ||
import pygrib | ||
from forest import nearcast | ||
|
||
|
||
def make_open(names): | ||
# Simulate pygrib.open(path).select() -> messages | ||
def _open(path): | ||
messages = unittest.mock.Mock() | ||
messages.select.return_value = [ | ||
{"name": name} for name in names | ||
] | ||
return messages | ||
return _open | ||
|
||
|
||
@pytest.mark.parametrize("names,expect", [ | ||
(["A", "A", "A"], ["A"]), | ||
(["D", "C", "B", "A"], ["A", "B", "C", "D"]), | ||
]) | ||
def test_navigator_variables(monkeypatch, names, expect): | ||
pattern = "" | ||
navigator = nearcast.Navigator(pattern) | ||
navigator.locator = unittest.mock.Mock() | ||
navigator.locator.find.return_value = ["some.grib"] | ||
monkeypatch.setattr(pygrib, "open", make_open(names)) | ||
assert navigator.variables(pattern) == expect |