|
1 | 1 | # -*- encoding:utf-8 -*-
|
2 | 2 | from copy import deepcopy
|
3 |
| -from numpydoc.numpydoc import mangle_docstrings |
| 3 | +from numpydoc.numpydoc import mangle_docstrings, _clean_text_signature |
4 | 4 | from numpydoc.xref import DEFAULT_LINKS
|
5 | 5 | from sphinx.ext.autodoc import ALL
|
6 | 6 |
|
@@ -36,7 +36,7 @@ class MockApp():
|
36 | 36 |
|
37 | 37 |
|
38 | 38 | def test_mangle_docstrings():
|
39 |
| - s =''' |
| 39 | + s = ''' |
40 | 40 | A top section before
|
41 | 41 |
|
42 | 42 | .. autoclass:: str
|
@@ -64,6 +64,34 @@ def test_mangle_docstrings():
|
64 | 64 | assert 'upper' not in [x.strip() for x in lines]
|
65 | 65 |
|
66 | 66 |
|
| 67 | +def test_clean_text_signature(): |
| 68 | + assert _clean_text_signature(None) is None |
| 69 | + assert _clean_text_signature('func($self)') == 'func()' |
| 70 | + assert (_clean_text_signature('func($self, *args, **kwargs)') |
| 71 | + == 'func(*args, **kwargs)') |
| 72 | + assert _clean_text_signature('($self)') == '()' |
| 73 | + assert _clean_text_signature('()') == '()' |
| 74 | + assert _clean_text_signature('func()') == 'func()' |
| 75 | + assert (_clean_text_signature('func($self, /, *args, **kwargs)') |
| 76 | + == 'func(*args, **kwargs)') |
| 77 | + assert (_clean_text_signature('func($self, other, /, *args, **kwargs)') |
| 78 | + == 'func(other, *args, **kwargs)') |
| 79 | + assert _clean_text_signature('($module)') == '()' |
| 80 | + assert _clean_text_signature('func($type)') == 'func()' |
| 81 | + assert (_clean_text_signature('func($self, foo="hello world")') |
| 82 | + == 'func(foo="hello world")') |
| 83 | + assert (_clean_text_signature("func($self, foo='hello world')") |
| 84 | + == "func(foo='hello world')") |
| 85 | + assert (_clean_text_signature('func(foo="hello world")') |
| 86 | + == 'func(foo="hello world")') |
| 87 | + assert (_clean_text_signature('func(foo="$self")') |
| 88 | + == 'func(foo="$self")') |
| 89 | + assert (_clean_text_signature('func($self, foo="$self")') |
| 90 | + == 'func(foo="$self")') |
| 91 | + assert _clean_text_signature('func(self, other)') == 'func(self, other)' |
| 92 | + assert _clean_text_signature('func($self, *args)') == 'func(*args)' |
| 93 | + |
| 94 | + |
67 | 95 | if __name__ == "__main__":
|
68 | 96 | import pytest
|
69 | 97 | pytest.main()
|
0 commit comments