diff --git a/cf_xarray/tests/test_accessor.py b/cf_xarray/tests/test_accessor.py index ca78df05..e467260d 100644 --- a/cf_xarray/tests/test_accessor.py +++ b/cf_xarray/tests/test_accessor.py @@ -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 @@ -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")? ), ) @@ -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( @@ -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(): @@ -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 diff --git a/doc/whats-new.rst b/doc/whats-new.rst index cef2e696..1fd1c2fa 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -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`_.