|
3 | 3 | import numpy as np
|
4 | 4 | import pytest
|
5 | 5 |
|
6 |
| -from matplotlib import _preprocess_data |
| 6 | +from matplotlib import _add_data_doc, _preprocess_data |
7 | 7 | from matplotlib.axes import Axes
|
8 | 8 | from matplotlib.testing.decorators import check_figures_equal
|
9 | 9 |
|
@@ -194,35 +194,105 @@ def func(ax, x, y, z=1):
|
194 | 194 | func(None, "a", "b", "z", "z", data=data)
|
195 | 195 |
|
196 | 196 |
|
| 197 | +def test_add_data_doc_kwargs(): |
| 198 | + """Test that the data docs is inserted before **kwargs.""" |
| 199 | + assert ("Data param should follow.\ndata : indexable object, optional" in |
| 200 | + _add_data_doc("""\ |
| 201 | +Some function. |
| 202 | +
|
| 203 | +Parameters |
| 204 | +---------- |
| 205 | +x |
| 206 | + Data param should follow. |
| 207 | +**kwargs |
| 208 | + Additional parameters. |
| 209 | +""", replace_names=['x'])) |
| 210 | + |
| 211 | + |
| 212 | +def test_add_data_doc_after_params(): |
| 213 | + """ |
| 214 | + Test that the data docs is inserted at the end of Parameters section |
| 215 | + that is followed by another section. |
| 216 | + """ |
| 217 | + assert ("Data param should follow.\ndata : indexable object, optional" in |
| 218 | + _add_data_doc("""\ |
| 219 | +Some function. |
| 220 | +
|
| 221 | +Parameters |
| 222 | +---------- |
| 223 | +x |
| 224 | + Data param should follow. |
| 225 | +
|
| 226 | +Returns |
| 227 | +------- |
| 228 | +someting |
| 229 | +""", replace_names=['x'])) |
| 230 | + |
| 231 | + |
| 232 | +def test_add_data_doc_after_params_last(): |
| 233 | + """ |
| 234 | + Test that the data docs is inserted at the end of Parameters section |
| 235 | + that is not followed by further docs. |
| 236 | + """ |
| 237 | + assert ("Data param should follow.\ndata : indexable object, optional" in |
| 238 | + _add_data_doc("""\ |
| 239 | +Some function. |
| 240 | +
|
| 241 | +Parameters |
| 242 | +---------- |
| 243 | +x |
| 244 | + Data param should follow. |
| 245 | +""", replace_names=['x'])) |
| 246 | + |
| 247 | + |
197 | 248 | def test_docstring_addition():
|
198 | 249 | @_preprocess_data()
|
199 | 250 | def funcy(ax, *args, **kwargs):
|
200 |
| - """Funcy does nothing""" |
| 251 | + """ |
| 252 | + Funcy does nothing. |
| 253 | +
|
| 254 | + Parameters |
| 255 | + ---------- |
| 256 | + **kwargs |
| 257 | + Text. |
| 258 | + """ |
201 | 259 |
|
202 |
| - assert re.search(r"every other argument", funcy.__doc__) |
203 |
| - assert not re.search(r"the following arguments", funcy.__doc__) |
| 260 | + assert re.search(r"all parameters also accept a string", funcy.__doc__) |
| 261 | + assert not re.search(r"the following parameters", funcy.__doc__) |
204 | 262 |
|
205 | 263 | @_preprocess_data(replace_names=[])
|
206 | 264 | def funcy(ax, x, y, z, bar=None):
|
207 | 265 | """Funcy does nothing"""
|
208 | 266 |
|
209 |
| - assert not re.search(r"every other argument", funcy.__doc__) |
210 |
| - assert not re.search(r"the following arguments", funcy.__doc__) |
| 267 | + assert not re.search(r"all parameters also accept a string", funcy.__doc__) |
| 268 | + assert not re.search(r"the following parameters", funcy.__doc__) |
211 | 269 |
|
212 | 270 | @_preprocess_data(replace_names=["bar"])
|
213 | 271 | def funcy(ax, x, y, z, bar=None):
|
214 |
| - """Funcy does nothing""" |
215 |
| - |
F313
216 |
| - assert not re.search(r"every other argument", funcy.__doc__) |
217 |
| - assert not re.search(r"the following arguments .*: \*bar\*\.", |
| 272 | + """ |
| 273 | + Funcy does nothing. |
| 274 | +
|
| 275 | + Parameters |
| 276 | + ---------- |
| 277 | + **kwargs |
| 278 | + Text. |
| 279 | + """ |
| 280 | + assert not re.search(r"all parameters also accept a string", funcy.__doc__) |
| 281 | + assert not re.search(r"the following parameters .*: \*bar\*\.", |
218 | 282 | funcy.__doc__)
|
219 | 283 |
|
220 | 284 | @_preprocess_data(replace_names=["x", "t"])
|
221 | 285 | def funcy(ax, x, y, z, t=None):
|
222 |
| - """Funcy does nothing""" |
223 |
| - |
224 |
| - assert not re.search(r"every other argument", funcy.__doc__) |
225 |
| - assert not re.search(r"the following arguments .*: \*x\*, \*t\*\.", |
| 286 | + """ |
| 287 | + Funcy does nothing. |
| 288 | +
|
| 289 | + Parameters |
| 290 | + ---------- |
| 291 | + x, y, z |
| 292 | + Text. |
| 293 | + """ |
| 294 | + assert not re.search(r"all parameters also accept a string", funcy.__doc__) |
| 295 | + assert not re.search(r"the following parameters .*: \*x\*, \*t\*\.", |
226 | 296 | funcy.__doc__)
|
227 | 297 |
|
228 | 298 |
|
|
0 commit comments