Skip to content

Commit

Permalink
Fix pytest and other depreciation warnings / errors (#56)
Browse files Browse the repository at this point in the history
* fix pytest and other depreciation warnings / errors

* update pinned packages for doc environment (fix nbsphinx)

* fix overwritten input dataset
  • Loading branch information
benbovy committed Sep 20, 2019
1 parent 23567e0 commit 86729d4
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 20 deletions.
20 changes: 10 additions & 10 deletions doc/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ channels:
- conda-forge
- defaults
dependencies:
- attrs=18.2.0
- python=3.6
- numpy=1.14.5
- attrs=19.1.0
- python=3.7
- numpy=1.16.0
- pandas=0.23.3
- xarray=0.10.9
- ipython=6.4.0
- matplotlib=2.2.2
- xarray=0.13.0
- ipython=7.8.0
- matplotlib=3.0.2
- graphviz
- python-graphviz
- nbconvert=5.2.1
- sphinx=1.7.6
- nbsphinx=0.3.3
- pandoc=1.19.2
- nbconvert=5.6.0
- sphinx=1.8.5
- nbsphinx=0.4.2
- pandoc=2.7.3
3 changes: 2 additions & 1 deletion xsimlab/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ def _get_output_dataset(self):
var_name = '__'.join(key)
xr_vars[var_name] = self._to_xr_variable(key, clock)

out_ds = self.dataset.update(xr_vars)
out_ds = self.dataset.copy()
out_ds.update(xr_vars)

# remove output_vars attributes in output dataset
for clock in self.output_vars:
Expand Down
2 changes: 1 addition & 1 deletion xsimlab/tests/fixture_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(self):
self.u_change = np.zeros_like(self.u)

def run_step(self, *args):
self.u_change[:] = np.sum((d for d in self.u_diffs))
self.u_change[:] = sum((d for d in self.u_diffs))

def finalize_step(self):
self.u += self.u_change
Expand Down
14 changes: 10 additions & 4 deletions xsimlab/tests/test_dot.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ def test_to_graphviz_attributes(model):
reason="IPython is not installed")
@pytest.mark.parametrize('format,typ', [
('png', Image),
pytest.mark.xfail(('jpeg', Image),
reason='jpeg not always supported in dot'),
pytest.param(
'jpeg', Image,
marks=pytest.mark.xfail(
reason='jpeg not always supported in dot')
),
('dot', type(None)),
('pdf', type(None)),
('svg', SVG),
Expand Down Expand Up @@ -134,8 +137,11 @@ def test_dot_graph_no_ipython(model):
reason="IPython is not installed")
@pytest.mark.parametrize('format,typ', [
('png', Image),
pytest.mark.xfail(('jpeg', Image),
reason='jpeg not always supported in dot'),
pytest.param(
'jpeg', Image,
marks=pytest.mark.xfail(
reason='jpeg not always supported in dot')
),
('dot', type(None)),
('pdf', type(None)),
('svg', SVG),
Expand Down
5 changes: 5 additions & 0 deletions xsimlab/tests/test_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ def test_set_input_vars(self, in_dataset, xarray_driver,
actual[0] = -9999
assert not np.array_equal(actual, expected)

def test_get_output_dataset(self, in_dataset, xarray_driver):
# regression test: make sure a copy of input dataset is used
out_ds = xarray_driver.run_model()
assert not in_dataset.identical(out_ds)

def test_run_model(self, in_dataset, out_dataset, xarray_driver):
out_ds_actual = xarray_driver.run_model()

Expand Down
4 changes: 2 additions & 2 deletions xsimlab/tests/test_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def test_as_dim_tuple_invalid():

with pytest.raises(ValueError) as excinfo:
_as_dim_tuple(invalid_dims)
assert "following combinations" in str(excinfo)
assert "('x',), ('y',) and ('x', 'y'), ('y', 'x')" in str(excinfo)
assert "following combinations" in str(excinfo.value)
assert "('x',), ('y',) and ('x', 'y'), ('y', 'x')" in str(excinfo.value)


def test_foreign():
Expand Down
4 changes: 2 additions & 2 deletions xsimlab/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"""
import threading
from collections import (Mapping, KeysView, ItemsView, ValuesView,
OrderedDict)
from collections import OrderedDict
from collections.abc import Mapping, KeysView, ItemsView, ValuesView
from contextlib import suppress
from importlib import import_module

Expand Down

0 comments on commit 86729d4

Please sign in to comment.