Skip to content

Commit

Permalink
Merge pull request #297 from informatics-lab/fix-nearcast-variables
Browse files Browse the repository at this point in the history
Fix nearcast variables
  • Loading branch information
andrewgryan authored Mar 2, 2020
2 parents c934bc4 + 49e3707 commit 643b400
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion forest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
.. automodule:: forest.presets
"""
__version__ = '0.12.4'
__version__ = '0.12.5'

from .config import *
from . import (
Expand Down
2 changes: 1 addition & 1 deletion forest/nearcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def variables(self, pattern):
paths = self.locator.find(self.pattern)
if len(paths) == 0:
return []
return list(sorted(self._variables(paths[-1])))
return list(sorted(set(self._variables(paths[-1]))))

@staticmethod
def _variables(path):
Expand Down
28 changes: 28 additions & 0 deletions test/test_drivers_nearcast.py
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

0 comments on commit 643b400

Please sign in to comment.