|
102 | 102 | :class:`python:dict`\[:class:`python:tuple`\(:class:`python:str`, :class:`python:str`), :class:`python:int`]
|
103 | 103 | """ # noqa: E501
|
104 | 104 |
|
| 105 | +data_ignore_obj = r""" |
| 106 | +(...) array_like, float, optional |
| 107 | +(...) :term:`numpy:array_like`, :class:`python:float`, optional |
| 108 | +
|
| 109 | +(2,) ndarray |
| 110 | +(2,) :obj:`ndarray <numpy.ndarray>` |
| 111 | +
|
| 112 | +(...,M,N) array_like |
| 113 | +(...,M,N) :term:`numpy:array_like` |
| 114 | +
|
| 115 | +(..., M, N) array_like |
| 116 | +(..., M, N) :term:`numpy:array_like` |
| 117 | +
|
| 118 | +(float, float), optional |
| 119 | +(:class:`python:float`, :class:`python:float`), optional |
| 120 | +
|
| 121 | +1-D array or sequence |
| 122 | +1-D :obj:`array <numpy.ndarray>` or :term:`python:sequence` |
| 123 | +
|
| 124 | +array of str or unicode-like |
| 125 | +:obj:`array <numpy.ndarray>` of :class:`python:str` or unicode-like |
| 126 | +
|
| 127 | +array_like of float |
| 128 | +:term:`numpy:array_like` of :class:`python:float` |
| 129 | +
|
| 130 | +bool or callable |
| 131 | +:ref:`bool <python:bltin-boolean-values>` or :func:`python:callable` |
| 132 | +
|
| 133 | +int in [0, 255] |
| 134 | +:class:`python:int` in [0, 255] |
| 135 | +
|
| 136 | +int or None, optional |
| 137 | +:class:`python:int` or :data:`python:None`, optional |
| 138 | +
|
| 139 | +list of str or array_like |
| 140 | +:class:`python:list` of :class:`python:str` or :term:`numpy:array_like` |
| 141 | +
|
| 142 | +sequence of array_like |
| 143 | +:term:`python:sequence` of :term:`numpy:array_like` |
| 144 | +
|
| 145 | +str or pathlib.Path |
| 146 | +:class:`python:str` or pathlib.Path |
| 147 | +
|
| 148 | +{'', string}, optional |
| 149 | +{'', :class:`python:str`}, optional |
| 150 | +
|
| 151 | +{'C', 'F', 'A', or 'K'}, optional |
| 152 | +{'C', 'F', 'A', or 'K'}, optional |
| 153 | +
|
| 154 | +{'linear', 'lower', 'higher', 'midpoint', 'nearest'} |
| 155 | +{'linear', 'lower', 'higher', 'midpoint', 'nearest'} |
| 156 | +
|
| 157 | +{False, True, 'greedy', 'optimal'} |
| 158 | +{:data:`python:False`, :data:`python:True`, 'greedy', 'optimal'} |
| 159 | +
|
| 160 | +{{'begin', 1}, {'end', 0}}, {string, int} |
| 161 | +{{'begin', 1}, {'end', 0}}, {:class:`python:str`, :class:`python:int`} |
| 162 | +
|
| 163 | +callable f'(x,*args) |
| 164 | +:func:`python:callable` f'(x,*args) |
| 165 | +
|
| 166 | +callable ``fhess(x, *args)``, optional |
| 167 | +:func:`python:callable` ``fhess(x, *args)``, optional |
| 168 | +
|
| 169 | +spmatrix (format: ``csr``, ``bsr``, ``dia`` or coo``) |
| 170 | +spmatrix (format: ``csr``, ``bsr``, ``dia`` or coo``) |
| 171 | +
|
| 172 | +:ref:`strftime <strftime-strptime-behavior>` |
| 173 | +:ref:`strftime <strftime-strptime-behavior>` |
| 174 | +
|
| 175 | +callable or :ref:`strftime <strftime-strptime-behavior>` |
| 176 | +:func:`python:callable` or :ref:`strftime <strftime-strptime-behavior>` |
| 177 | +
|
| 178 | +callable or :ref:`strftime behavior <strftime-strptime-behavior>` |
| 179 | +:func:`python:callable` or :ref:`strftime behavior <strftime-strptime-behavior>` |
| 180 | +
|
| 181 | +list(int) |
| 182 | +:class:`python:list`\(:class:`python:int`) |
| 183 | +
|
| 184 | +list[int] |
| 185 | +:class:`python:list`\[:class:`python:int`] |
| 186 | +
|
| 187 | +dict(str, int) |
| 188 | +:class:`python:dict`\(:class:`python:str`, :class:`python:int`) |
| 189 | +
|
| 190 | +dict[str, int] |
| 191 | +:class:`python:dict`\[:class:`python:str`, :class:`python:int`] |
| 192 | +
|
| 193 | +tuple(float, float) |
| 194 | +:class:`python:tuple`\(:class:`python:float`, :class:`python:float`) |
| 195 | +
|
| 196 | +dict[tuple(str, str), int] |
| 197 | +:class:`python:dict`\[:class:`python:tuple`\(:class:`python:str`, :class:`python:str`), :class:`python:int`] |
| 198 | +""" # noqa: E501 |
| 199 | + |
105 | 200 | xref_ignore = {'or', 'in', 'of', 'default', 'optional'}
|
106 | 201 |
|
107 | 202 |
|
|
111 | 206 | )
|
112 | 207 | def test_make_xref(param_type, expected_result):
|
113 | 208 | assert make_xref(param_type, xref_aliases, xref_ignore) == expected_result
|
| 209 | + |
| 210 | +@pytest.mark.parametrize( |
| 211 | + ('param_type', 'expected_result'), |
| 212 | + [tuple(s.split('\n')) for s in data_ignore_obj.strip().split('\n\n')] |
| 213 | +) |
| 214 | +def test_make_xref_ignore_unknown(param_type, expected_result): |
| 215 | + assert make_xref(param_type, xref_aliases, xref_ignore="all") == expected_result |
| 216 | + |
| 217 | +def test_xref_ignore_is_all(): |
| 218 | + with pytest.raises(TypeError, match="must be a set or 'all'"): |
| 219 | + make_xref("array_like", xref_aliases, xref_ignore="foo") |
0 commit comments