generated from jCloud/repository-template
Add feature to get the signature representation of a Python function argument
This commit is contained in:
@@ -13,8 +13,7 @@
|
||||
# limitations under the License.
|
||||
|
||||
from src.jcloud_docsgen.core.python.arguments import PythonFunctionArgument, PythonArgumentKind
|
||||
from src.jcloud_docsgen.exceptions import InvalidPythonIdentifierError, InvalidPythonAnnotationError
|
||||
import ast
|
||||
from src.jcloud_docsgen.exceptions import InvalidPythonIdentifierError, InvalidPythonAnnotationError, PythonArgumentStructureError
|
||||
import pytest
|
||||
|
||||
@pytest.mark.parametrize('name,kind,default,annotation,expected_exception,expected_exception_msg', [
|
||||
@@ -59,6 +58,8 @@ import pytest
|
||||
('lambda', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: lambda'),
|
||||
('None', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: None'),
|
||||
('True', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: True'),
|
||||
('a', PythonArgumentKind.VARARG, '1', None, PythonArgumentStructureError, '* or ** arguments cannot have default values: *a = 1'),
|
||||
('a', PythonArgumentKind.KWARGS, '1', None, PythonArgumentStructureError, '* or ** arguments cannot have default values: **a = 1'),
|
||||
])
|
||||
def test_PythonFunctionArgument_exceptions(name, kind, default, annotation, expected_exception, expected_exception_msg):
|
||||
with pytest.raises(expected_exception) as exc_info:
|
||||
@@ -79,13 +80,14 @@ def test_PythonFunctionArgument_exceptions(name, kind, default, annotation, expe
|
||||
'case',
|
||||
'type',
|
||||
'ä',
|
||||
'none',
|
||||
'true',
|
||||
'false',
|
||||
])
|
||||
@pytest.mark.parametrize('kind', [
|
||||
PythonArgumentKind.NORMAL,
|
||||
PythonArgumentKind.POSITIONAL_ONLY,
|
||||
PythonArgumentKind.KEYWORD_ONLY,
|
||||
PythonArgumentKind.VARARG,
|
||||
PythonArgumentKind.KWARGS,
|
||||
])
|
||||
@pytest.mark.parametrize('default', [
|
||||
None,
|
||||
@@ -100,4 +102,35 @@ def test_PythonFunctionArgument_exceptions(name, kind, default, annotation, expe
|
||||
'_',
|
||||
])
|
||||
def test_PythonFunctionArgument(name, kind, default, annotation):
|
||||
PythonFunctionArgument(name, kind, default, annotation)
|
||||
PythonFunctionArgument(name, kind, default, annotation)
|
||||
|
||||
@pytest.mark.parametrize('name', [
|
||||
'a',
|
||||
'_a',
|
||||
'a1',
|
||||
'a0',
|
||||
'a_',
|
||||
'_',
|
||||
'_abc',
|
||||
'abc',
|
||||
'abc_',
|
||||
'match',
|
||||
'case',
|
||||
'type',
|
||||
'ä',
|
||||
'none',
|
||||
'true',
|
||||
'false',
|
||||
])
|
||||
@pytest.mark.parametrize('kind', [
|
||||
PythonArgumentKind.VARARG,
|
||||
PythonArgumentKind.KWARGS,
|
||||
])
|
||||
@pytest.mark.parametrize('annotation', [
|
||||
None,
|
||||
'a',
|
||||
'list[int]',
|
||||
'_',
|
||||
])
|
||||
def test_PythonFunctionArgument_asterik(name, kind, annotation):
|
||||
PythonFunctionArgument(name, kind, None, annotation)
|
||||
Reference in New Issue
Block a user