Skip to content

fix tests #81

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

Merged
merged 8 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 39 additions & 40 deletions cf_xarray/tests/test_accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,6 @@
objects = datasets + dataarrays


def test_dicts():
from .datasets import airds

actual = airds.cf.sizes
expected = {"X": 50, "Y": 25, "T": 4, "longitude": 50, "latitude": 25, "time": 4}
assert actual == expected

assert popds.cf.sizes == popds.sizes

with pytest.raises(AttributeError):
multiple.cf.sizes

assert airds.cf.chunks == {}

expected = {
"X": (50,),
"Y": (5, 5, 5, 5, 5),
"T": (4,),
"longitude": (50,),
"latitude": (5, 5, 5, 5, 5),
"time": (4,),
}
assert airds.chunk({"lat": 5}).cf.chunks == expected

with pytest.raises(AttributeError):
airds.da.cf.chunks

airds = airds.copy(deep=True)
airds.lon.attrs = {}
actual = airds.cf.sizes
expected = {"lon": 50, "Y": 25, "T": 4, "latitude": 25, "time": 4}
assert actual == expected


def test_describe(capsys):
airds.cf.describe()
actual = capsys.readouterr().out
Expand Down Expand Up @@ -136,7 +102,6 @@ def test_rename_like():
reason="xarray GH4120. any test after this will fail since attrs are lost"
),
),
# order of above tests is important: See xarray GH4120
# groupby("time.day")?
),
)
Expand Down Expand Up @@ -222,9 +187,10 @@ def test_kwargs_expand_key_to_multiple_keys():
expected = multiple.mean(["x1", "x2"])
assert_identical(actual, expected)

actual = multiple.cf.coarsen(X=10, Y=5)
expected = multiple.coarsen(x1=10, y1=5, x2=10, y2=5)
assert_identical(actual.mean(), expected.mean())
# Commenting out lines that use Coarsen
# actual = multiple.cf.coarsen(X=10, Y=5)
# expected = multiple.coarsen(x1=10, y1=5, x2=10, y2=5)
# assert_identical(actual.mean(), expected.mean())


@pytest.mark.parametrize(
Expand Down Expand Up @@ -324,9 +290,10 @@ def test_getitem(obj, key, expected_key):
def test_getitem_errors(obj,):
with pytest.raises(KeyError):
obj.cf["XX"]
obj.lon.attrs = {}
obj2 = obj.copy(deep=True)
obj2.lon.attrs = {}
with pytest.raises(KeyError):
obj.cf["X"]
obj2.cf["X"]


def test_getitem_uses_coordinates():
Expand Down Expand Up @@ -444,3 +411,35 @@ def test_guess_axis_coord():
}
assert dsnew.x1.attrs == {"axis": "X"}
assert dsnew.y1.attrs == {"axis": "Y"}


def test_dicts():
actual = airds.cf.sizes
expected = {"X": 50, "Y": 25, "T": 4, "longitude": 50, "latitude": 25, "time": 4}
assert actual == expected

assert popds.cf.sizes == popds.sizes

with pytest.raises(AttributeError):
multiple.cf.sizes

assert airds.cf.chunks == {}

expected = {
"X": (50,),
"Y": (5, 5, 5, 5, 5),
"T": (4,),
"longitude": (50,),
"latitude": (5, 5, 5, 5, 5),
"time": (4,),
}
assert airds.chunk({"lat": 5}).cf.chunks == expected

with pytest.raises(AttributeError):
airds.da.cf.chunks

airds2 = airds.copy(deep=True)
airds2.lon.attrs = {}
actual = airds2.cf.sizes
expected = {"lon": 50, "Y": 25, "T": 4, "latitude": 25, "time": 4}
assert actual == expected
4 changes: 4 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
What's New
----------
v0.2.2 (unreleased)
===========================
- Fixed tests that would only pass if ran in a specific order. `Julia Kent`_.

v0.2.1 (Aug 06, 2020)
=====================
- Support for the ``bounds`` attribute. (:pr:`68`, :issue:`32`). `Deepak Cherian`_.
Expand Down