Test that cftimeindex is sensitive to OPTIONS['display_width'].
(periods, display_width)
| 1171 | @pytest.mark.parametrize("display_width", [40, 80, 100]) |
| 1172 | @pytest.mark.parametrize("periods", [2, 3, 4, 100, 101]) |
| 1173 | def test_cftimeindex_repr_formatting_width(periods, display_width): |
| 1174 | """Test that cftimeindex is sensitive to OPTIONS['display_width'].""" |
| 1175 | index = xr.date_range(start="2000", periods=periods, use_cftime=True) |
| 1176 | len_intro_str = len("CFTimeIndex(") |
| 1177 | with xr.set_options(display_width=display_width): |
| 1178 | repr_str = index.__repr__() |
| 1179 | splitted = repr_str.split("\n") |
| 1180 | for i, s in enumerate(splitted): |
| 1181 | # check that lines not longer than OPTIONS['display_width'] |
| 1182 | assert len(s) <= display_width, f"{len(s)} {s} {display_width}" |
| 1183 | if i > 0: |
| 1184 | # check for initial spaces |
| 1185 | assert s[:len_intro_str] == " " * len_intro_str |
| 1186 | |
| 1187 | |
| 1188 | @requires_cftime |