MCPcopy
hub / github.com/pydata/xarray / test_label_from_attrs

Method test_label_from_attrs

xarray/tests/test_plot.py:192–220  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

190 assert isinstance(self.darray.plot, DataArrayPlotAccessor)
191
192 def test_label_from_attrs(self) -> None:
193 da = self.darray.copy()
194 assert "" == label_from_attrs(da)
195
196 da.name = 0
197 assert "0" == label_from_attrs(da)
198
199 da.name = "a"
200 da.attrs["units"] = "a_units"
201 da.attrs["long_name"] = "a_long_name"
202 da.attrs["standard_name"] = "a_standard_name"
203 assert "a_long_name [a_units]" == label_from_attrs(da)
204
205 da.attrs.pop("long_name")
206 assert "a_standard_name [a_units]" == label_from_attrs(da)
207 da.attrs.pop("units")
208 assert "a_standard_name" == label_from_attrs(da)
209
210 da.attrs["units"] = "a_units"
211 da.attrs.pop("standard_name")
212 assert "a [a_units]" == label_from_attrs(da)
213
214 da.attrs.pop("units")
215 assert "a" == label_from_attrs(da)
216
217 # Latex strings can be longer without needing a new line:
218 long_latex_name = r"$Ra_s = \mathrm{mean}(\epsilon_k) / \mu M^2_\infty$"
219 da.attrs = dict(long_name=long_latex_name)
220 assert label_from_attrs(da) == long_latex_name
221
222 def test1d(self) -> None:
223 self.darray[:, 0, 0].plot() # type: ignore[call-arg]

Callers

nothing calls this directly

Calls 2

label_from_attrsFunction · 0.90
copyMethod · 0.45

Tested by

no test coverage detected