style: limit line length to 79 characters

Limited the lengths of all lines to 79 characters (if possible).
Additionally, some other lines were breaked for consistence.
This commit is contained in:
jakob.scheid committed 2026-09-18 16:57:45 +02:00
1 parent 8930efc7e6
commit caa8e04047
25 files changed
+6726 -1071

No files matched your search

@@ -12,86 +12,482 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from src.jcloud_docsgen.core.python.definitions import PythonFunctionDefinition, PythonClassDefinition
from src.jcloud_docsgen.core.python.arguments import PythonFunctionArgument, PythonArgumentKind
from src.jcloud_docsgen.core.python.definitions import (
PythonFunctionDefinition,
PythonClassDefinition
)
from src.jcloud_docsgen.core.python.arguments import (
PythonFunctionArgument,
PythonArgumentKind
)
from src.jcloud_docsgen.core.python.docstrings import PythonDocstring
from src.jcloud_docsgen.exceptions import InvalidPythonIdentifierError
from tests.utils.ast_node import ast_node
import pytest
@pytest.mark.parametrize('definition,expected', [
(PythonClassDefinition('A', [], None, None, []), 'PythonClassDefinition(\'A\', [], None, None, [])'),
(PythonClassDefinition('A', [], None, PythonDocstring('Hello, World!'), []), 'PythonClassDefinition(\'A\', [], None, PythonDocstring(\'Hello, World!\'), [])'),
(
PythonClassDefinition(
'A',
[],
None,
None,
[]
),
'PythonClassDefinition(\'A\', [], None, None, [])'
),
(
PythonClassDefinition(
'A',
[],
None,
PythonDocstring('Hello, World!'),
[]
),
(
'PythonClassDefinition(\'A\', [], None, '
'PythonDocstring(\'Hello, World!\'), [])'
)
),
])
def test_PythonDefinition_string_representation(definition, expected):
assert repr(definition) == expected
@pytest.mark.parametrize('name,args,returns,doc,decorators,expected_exception,expected_exception_message', [
('', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier'),
('.', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: .'),
('#', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: #'),
('1a', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: 1a'),
('1_', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: 1_'),
('1,', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: 1,'),
(',', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: ,'),
(':', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: :'),
('-', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: -'),
(';', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: ;'),
('|', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: |'),
('<', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: <'),
('>', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: >'),
('a,', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: a,'),
(',a', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: ,a'),
('a:', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: a:'),
(':a', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: :a'),
('a-', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: a-'),
('-a', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: -a'),
('a;', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: a;'),
(';a', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: ;a'),
('a|', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: a|'),
('|a', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: |a'),
('a<', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: a<'),
('<a', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: <a'),
('a>', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: a>'),
('>a', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: >a'),
('class', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: class'),
('def', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: def'),
('lambda', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: lambda'),
('None', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: None'),
('True', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: True'),
])
def test_PythonFunctionDefinition_exceptions(name, args, returns, doc, decorators, expected_exception, expected_exception_message):
@pytest.mark.parametrize(
(
'name,args,returns,doc,decorators,expect'
'ed_exception,expected_exception_message'
),
[
(
'',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier'
),
(
'.',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: .'
),
(
'#',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: #'
),
(
'1a',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1a'
),
(
'1_',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1_'
),
(
'1,',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1,'
),
(
',',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ,'
),
(
':',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: :'
),
(
'-',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: -'
),
(
';',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ;'
),
(
'|',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: |'
),
(
'<',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: <'
),
(
'>',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: >'
),
(
'a,',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a,'
),
(
',a',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ,a'
),
(
'a:',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a:'
),
(
':a',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: :a'
),
(
'a-',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a-'
),
(
'-a',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: -a'
),
(
'a;',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a;'
),
(
';a',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ;a'
),
(
'a|',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a|'
),
(
'|a',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: |a'
),
(
'a<',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a<'
),
(
'<a',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: <a'
),
(
'a>',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a>'
),
(
'>a',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: >a'
),
(
'class',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: class'
),
(
'def',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: def'
),
(
'lambda',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: lambda'
),
(
'None',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: None'
),
(
'True',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: True'
),
]
)
def test_PythonFunctionDefinition_exceptions(
name,
args,
returns,
doc,
decorators,
expected_exception,
expected_exception_message
):
with pytest.raises(expected_exception) as exc_info:
PythonClassDefinition(name, args, returns, doc, decorators)
assert str(exc_info.value) == expected_exception_message
@pytest.mark.parametrize('node,expected', [
(ast_node('@decorator\nclass Class(BaseClass1, BaseClass2):\n\tdef __init__(self, value: object) -> None:\n\t\tself._value = value\n\n\t@property\n\tdef value(self) -> object:\n\t\treturn self._value'), PythonClassDefinition('Class', [
'BaseClass1',
'BaseClass2'
], None, ['decorator'], [
PythonFunctionDefinition('__init__', [
PythonFunctionArgument('self', PythonArgumentKind.NORMAL, None, None),
PythonFunctionArgument('value', PythonArgumentKind.NORMAL, None, 'object')
], 'None', None, []),
PythonFunctionDefinition('value', [
PythonFunctionArgument('self', PythonArgumentKind.NORMAL, None, None)
], 'object', None, ['property'])
])),
(ast_node('class Class: ...'), PythonClassDefinition('Class', [], None, [], [])),
(ast_node('class Class: \'\'\'docstring\'\'\''), PythonClassDefinition('Class', [], PythonDocstring('docstring'), [], [])),
(ast_node('class Class:\n\tdef __init__(self): ...'), PythonClassDefinition('Class', [], None, [], [
PythonFunctionDefinition('__init__', [
PythonFunctionArgument('self', PythonArgumentKind.NORMAL, None, None)
], None, None, [])
])),
(ast_node('class Class:\n\t\'\'\'doc\'\'\'\n\tdef __init__(self): ...'), PythonClassDefinition('Class', [], PythonDocstring('doc'), [], [
PythonFunctionDefinition('__init__', [
PythonFunctionArgument('self', PythonArgumentKind.NORMAL, None, None)
], None, None, [])
])),
(
ast_node(
(
'@decorator\nclass Class(BaseClass1, BaseClass2)'
':\n\tdef __init__(self, value: object) -> None:'
'\n\t\tself._value = value\n\n\t@property\n\tdef'
' value(self) -> object:\n\t\treturn self._value'
)
),
PythonClassDefinition(
'Class',
['BaseClass1', 'BaseClass2'],
None,
['decorator'],
[
PythonFunctionDefinition(
'__init__',
[
PythonFunctionArgument(
'self',
PythonArgumentKind.NORMAL,
None,
None
),
PythonFunctionArgument(
'value',
PythonArgumentKind.NORMAL,
None,
'object'
)
],
'None',
None,
[]
),
PythonFunctionDefinition(
'value',
[
PythonFunctionArgument(
'self',
PythonArgumentKind.NORMAL,
None,
None
)
],
'object',
None,
['property']
)
]
)
),
(
ast_node('class Class: ...'),
PythonClassDefinition(
'Class',
[],
None,
[],
[]
)
),
(
ast_node('class Class: \'\'\'docstring\'\'\''),
PythonClassDefinition(
'Class',
[],
PythonDocstring('docstring'),
[],
[]
)
),
(
ast_node('class Class:\n\tdef __init__(self): ...'),
PythonClassDefinition(
'Class',
[],
None,
[],
[
PythonFunctionDefinition(
'__init__',
[
PythonFunctionArgument(
'self',
PythonArgumentKind.NORMAL,
None,
None
)
],
None,
None,
[]
)
]
)
),
(
ast_node('class Class:\n\t\'\'\'doc\'\'\'\n\tdef __init__(self): ...'),
PythonClassDefinition(
'Class',
[],
PythonDocstring('doc'),
[],
[
PythonFunctionDefinition(
'__init__',
[
PythonFunctionArgument(
'self',
PythonArgumentKind.NORMAL,
None,
None
)
],
None,
None,
[]
)
]
)
),
])
def test_PythonDefinition_from_node(node, expected):
assert PythonClassDefinition.from_node(node) == expected
@@ -18,66 +18,425 @@ from src.jcloud_docsgen.exceptions import InvalidPythonIdentifierError
import pytest
@pytest.mark.parametrize('definition,expected', [
(PythonDefinition('a', None, []), 'PythonDefinition(\'a\', None, [])'),
(PythonDefinition('a', PythonDocstring('Hello, World!'), []), 'PythonDefinition(\'a\', PythonDocstring(\'Hello, World!\'), [])'),
(
PythonDefinition(
'a',
None,
[]
),
'PythonDefinition(\'a\', None, [])'
),
(
PythonDefinition(
'a',
PythonDocstring('Hello, World!'),
[]
),
'PythonDefinition(\'a\', PythonDocstring(\'Hello, World!\'), [])'
),
])
def test_PythonDefinition_string_representation(definition, expected):
assert repr(definition) == expected
@pytest.mark.parametrize('name,doc,decorators,expected_exception,expected_exception_message', [
('', None, [], InvalidPythonIdentifierError, 'invalid identifier'),
('.', None, [], InvalidPythonIdentifierError, 'invalid identifier: .'),
('#', None, [], InvalidPythonIdentifierError, 'invalid identifier: #'),
('1a', None, [], InvalidPythonIdentifierError, 'invalid identifier: 1a'),
('1_', None, [], InvalidPythonIdentifierError, 'invalid identifier: 1_'),
('1,', None, [], InvalidPythonIdentifierError, 'invalid identifier: 1,'),
(',', None, [], InvalidPythonIdentifierError, 'invalid identifier: ,'),
(':', None, [], InvalidPythonIdentifierError, 'invalid identifier: :'),
('-', None, [], InvalidPythonIdentifierError, 'invalid identifier: -'),
(';', None, [], InvalidPythonIdentifierError, 'invalid identifier: ;'),
('|', None, [], InvalidPythonIdentifierError, 'invalid identifier: |'),
('<', None, [], InvalidPythonIdentifierError, 'invalid identifier: <'),
('>', None, [], InvalidPythonIdentifierError, 'invalid identifier: >'),
('a,', None, [], InvalidPythonIdentifierError, 'invalid identifier: a,'),
(',a', None, [], InvalidPythonIdentifierError, 'invalid identifier: ,a'),
('a:', None, [], InvalidPythonIdentifierError, 'invalid identifier: a:'),
(':a', None, [], InvalidPythonIdentifierError, 'invalid identifier: :a'),
('a-', None, [], InvalidPythonIdentifierError, 'invalid identifier: a-'),
('-a', None, [], InvalidPythonIdentifierError, 'invalid identifier: -a'),
('a;', None, [], InvalidPythonIdentifierError, 'invalid identifier: a;'),
(';a', None, [], InvalidPythonIdentifierError, 'invalid identifier: ;a'),
('a|', None, [], InvalidPythonIdentifierError, 'invalid identifier: a|'),
('|a', None, [], InvalidPythonIdentifierError, 'invalid identifier: |a'),
('a<', None, [], InvalidPythonIdentifierError, 'invalid identifier: a<'),
('<a', None, [], InvalidPythonIdentifierError, 'invalid identifier: <a'),
('a>', None, [], InvalidPythonIdentifierError, 'invalid identifier: a>'),
('>a', None, [], InvalidPythonIdentifierError, 'invalid identifier: >a'),
('class', None, [], InvalidPythonIdentifierError, 'invalid identifier: class'),
('def', None, [], InvalidPythonIdentifierError, 'invalid identifier: def'),
('lambda', None, [], InvalidPythonIdentifierError, 'invalid identifier: lambda'),
('None', None, [], InvalidPythonIdentifierError, 'invalid identifier: None'),
('True', None, [], InvalidPythonIdentifierError, 'invalid identifier: True'),
])
def test_PythonDefinition_exceptions(name, doc, decorators, expected_exception, expected_exception_message):
@pytest.mark.parametrize(
'name,doc,decorators,expected_exception,expected_exception_message',
[
(
'',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier'
),
(
'.',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: .'
),
(
'#',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: #'
),
(
'1a',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1a'
),
(
'1_',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1_'
),
(
'1,',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1,'
),
(
',',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ,'
),
(
':',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: :'
),
(
'-',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: -'
),
(
';',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ;'
),
(
'|',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: |'
),
(
'<',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: <'
),
(
'>',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: >'
),
(
'a,',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a,'
),
(
',a',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ,a'
),
(
'a:',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a:'
),
(
':a',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: :a'
),
(
'a-',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a-'
),
(
'-a',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: -a'
),
(
'a;',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a;'
),
(
';a',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ;a'
),
(
'a|',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a|'
),
(
'|a',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: |a'
),
(
'a<',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a<'
),
(
'<a',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: <a'
),
(
'a>',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a>'
),
(
'>a',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: >a'
),
(
'class',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: class'
),
(
'def',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: def'
),
(
'lambda',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: lambda'
),
(
'None',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: None'
),
(
'True',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: True'
),
]
)
def test_PythonDefinition_exceptions(
name,
doc,
decorators,
expected_exception,
expected_exception_message
):
with pytest.raises(expected_exception) as exc_info:
PythonDefinition(name, doc, decorators)
assert str(exc_info.value) == expected_exception_message
@pytest.mark.parametrize('definition1,definition2,expected', [
(PythonDefinition('a', None, []), PythonDefinition('a', None, []), True),
(PythonDefinition('a', PythonDocstring('doc'), []), PythonDefinition('a', PythonDocstring('doc'), []), True),
(PythonDefinition('a', PythonDocstring('doc'), ['a']), PythonDefinition('a', PythonDocstring('doc'), ['a']), True),
(PythonDefinition('a', PythonDocstring('doc'), ['a', 'b']), PythonDefinition('a', PythonDocstring('doc'), ['a', 'b']), True),
(PythonDefinition('a', None, []), PythonDefinition('b', None, []), False),
(PythonDefinition('a', PythonDocstring('doc'), []), PythonDefinition('a', None, []), False),
(PythonDefinition('a', PythonDocstring('doc'), []), PythonDefinition('a', PythonDocstring('docs'), []), False),
(PythonDefinition('a', None, ['a']), PythonDefinition('a', None, ['b']), False),
(PythonDefinition('a', None, ['a']), PythonDefinition('a', None, []), False),
(PythonDefinition('a', None, ['a']), PythonDefinition('a', None, ['a', 'b']), False),
(PythonDefinition('a', None, ['b', 'a']), PythonDefinition('a', None, ['a', 'b']), False),
(PythonDefinition('a', PythonDocstring('doc'), []), PythonDefinition('b', None, ['a', 'b']), False),
(
PythonDefinition(
'a',
None,
[]
),
PythonDefinition(
'a',
None,
[]
),
True
),
(
PythonDefinition(
'a',
PythonDocstring('doc'),
[]
),
PythonDefinition(
'a',
PythonDocstring('doc'),
[]
),
True
),
(
PythonDefinition(
'a',
PythonDocstring('doc'),
['a']
),
PythonDefinition(
'a',
PythonDocstring('doc'),
['a']
),
True
),
(
PythonDefinition(
'a',
PythonDocstring('doc'),
['a', 'b']
),
PythonDefinition(
'a',
PythonDocstring('doc'),
['a', 'b']
),
True
),
(
PythonDefinition(
'a',
None,
[]
),
PythonDefinition(
'b',
None,
[]
),
False
),
(
PythonDefinition(
'a',
PythonDocstring('doc'),
[]
),
PythonDefinition(
'a',
None,
[]
),
False
),
(
PythonDefinition(
'a',
PythonDocstring('doc'),
[]
),
PythonDefinition(
'a',
PythonDocstring('docs'),
[]
),
False
),
(
PythonDefinition(
'a',
None,
['a']
),
PythonDefinition(
'a',
None,
['b']
),
False
),
(
PythonDefinition(
'a',
None,
['a']
),
PythonDefinition(
'a',
None,
[]
),
False
),
(
PythonDefinition(
'a',
None,
['a']
),
PythonDefinition(
'a',
None,
['a', 'b']
),
False
),
(
PythonDefinition(
'a',
None,
['b', 'a']
),
PythonDefinition(
'a',
None,
['a', 'b']
),
False
),
(
PythonDefinition(
'a',
PythonDocstring('doc'),
[]
),
PythonDefinition(
'b',
None,
['a', 'b']
),
False
),
])
def test_PythonDefinition___eq__(definition1, definition2, expected):
assert (definition1 == definition2) == expected
@@ -13,75 +13,447 @@
# limitations under the License.
from src.jcloud_docsgen.core.python.definitions import PythonFunctionDefinition
from src.jcloud_docsgen.core.python.arguments import PythonFunctionArgument, PythonArgumentKind
from src.jcloud_docsgen.core.python.arguments import (
PythonFunctionArgument,
PythonArgumentKind
)
from src.jcloud_docsgen.core.python.docstrings import PythonDocstring
from src.jcloud_docsgen.exceptions import InvalidPythonIdentifierError
from tests.utils.ast_node import ast_node
import pytest
@pytest.mark.parametrize('definition,expected', [
(PythonFunctionDefinition('a', [], None, None, []), 'PythonFunctionDefinition(\'a\', [], None, None, [])'),
(PythonFunctionDefinition('a', [], None, PythonDocstring('Hello, World!'), []), 'PythonFunctionDefinition(\'a\', [], None, PythonDocstring(\'Hello, World!\'), [])'),
(
PythonFunctionDefinition(
'a',
[],
None,
None,
[]
),
'PythonFunctionDefinition(\'a\', [], None, None, [])'
),
(
PythonFunctionDefinition(
'a',
[],
None,
PythonDocstring('Hello, World!'),
[]
),
(
'PythonFunctionDefinition(\'a\', [], None,'
' PythonDocstring(\'Hello, World!\'), [])'
)
),
])
def test_PythonDefinition_string_representation(definition, expected):
assert repr(definition) == expected
@pytest.mark.parametrize('name,args,returns,doc,decorators,expected_exception,expected_exception_message', [
('', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier'),
('.', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: .'),
('#', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: #'),
('1a', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: 1a'),
('1_', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: 1_'),
('1,', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: 1,'),
(',', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: ,'),
(':', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: :'),
('-', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: -'),
(';', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: ;'),
('|', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: |'),
('<', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: <'),
('>', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: >'),
('a,', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: a,'),
(',a', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: ,a'),
('a:', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: a:'),
(':a', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: :a'),
('a-', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: a-'),
('-a', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: -a'),
('a;', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: a;'),
(';a', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: ;a'),
('a|', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: a|'),
('|a', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: |a'),
('a<', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: a<'),
('<a', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: <a'),
('a>', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: a>'),
('>a', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: >a'),
('class', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: class'),
('def', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: def'),
('lambda', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: lambda'),
('None', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: None'),
('True', [], None, None, [], InvalidPythonIdentifierError, 'invalid identifier: True'),
@pytest.mark.parametrize(
(
'name,args,returns,doc,decorators,expect'
'ed_exception,expected_exception_message'
),
[
(
'',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier'
),
(
'.',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: .'
),
(
'#',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: #'
),
(
'1a',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1a'
),
(
'1_',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1_'
),
(
'1,',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1,'
),
(
',',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ,'
),
(
':',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: :'
),
(
'-',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: -'
),
(
';',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ;'
),
(
'|',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: |'
),
(
'<',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: <'
),
(
'>',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: >'
),
(
'a,',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a,'
),
(
',a',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ,a'
),
(
'a:',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a:'
),
(
':a',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: :a'
),
(
'a-',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a-'
),
(
'-a',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: -a'
),
(
'a;',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a;'
),
(
';a',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ;a'
),
(
'a|',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a|'
),
(
'|a',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: |a'
),
(
'a<',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a<'
),
(
'<a',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: <a'
),
(
'a>',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a>'
),
(
'>a',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: >a'
),
(
'class',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: class'
),
(
'def',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: def'
),
(
'lambda',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: lambda'
),
(
'None',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: None'
),
(
'True',
[],
None,
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: True'
),
])
def test_PythonFunctionDefinition_exceptions(name, args, returns, doc, decorators, expected_exception, expected_exception_message):
def test_PythonFunctionDefinition_exceptions(
name,
args,
returns,
doc,
decorators,
expected_exception,
expected_exception_message
):
with pytest.raises(expected_exception) as exc_info:
PythonFunctionDefinition(name, args, returns, doc, decorators)
assert str(exc_info.value) == expected_exception_message
@pytest.mark.parametrize('node,expected', [
(ast_node('def add(a: int, b: int) -> int: return a + b'), PythonFunctionDefinition('add', [
PythonFunctionArgument('a', PythonArgumentKind.NORMAL, None, 'int'),
PythonFunctionArgument('b', PythonArgumentKind.NORMAL, None, 'int'),
], 'int', None, [])),
(ast_node('@decorator\ndef add(a: int, b: int) -> int: return a + b'), PythonFunctionDefinition('add', [
PythonFunctionArgument('a', PythonArgumentKind.NORMAL, None, 'int'),
PythonFunctionArgument('b', PythonArgumentKind.NORMAL, None, 'int'),
], 'int', None, ['decorator'])),
(ast_node('@decorator1\n@decorator2\ndef add(a: int, b: int) -> int: return a + b'), PythonFunctionDefinition('add', [
PythonFunctionArgument('a', PythonArgumentKind.NORMAL, None, 'int'),
PythonFunctionArgument('b', PythonArgumentKind.NORMAL, None, 'int'),
], 'int', None, ['decorator1', 'decorator2'])),
(ast_node('def func(): ...'), PythonFunctionDefinition('func', [], None, None, [])),
(ast_node('@decorator\ndef func(): ...'), PythonFunctionDefinition('func', [], None, None, ['decorator'])),
(
ast_node('def add(a: int, b: int) -> int: return a + b'),
PythonFunctionDefinition(
'add', [
PythonFunctionArgument(
'a',
PythonArgumentKind.NORMAL,
None,
'int'
),
PythonFunctionArgument(
'b',
PythonArgumentKind.NORMAL,
None,
'int'
),
],
'int',
None,
[]
)
),
(
ast_node('@decorator\ndef add(a: int, b: int) -> int: return a + b'),
PythonFunctionDefinition(
'add',
[
PythonFunctionArgument(
'a',
PythonArgumentKind.NORMAL,
None,
'int'
),
PythonFunctionArgument(
'b',
PythonArgumentKind.NORMAL,
None,
'int'
),
],
'int',
None,
['decorator']
)
),
(
ast_node(
(
'@decorator1\n@decorator2\ndef add(a'
': int, b: int) -> int: return a + b'
)
),
PythonFunctionDefinition(
'add',
[
PythonFunctionArgument(
'a',
PythonArgumentKind.NORMAL,
None,
'int'
),
PythonFunctionArgument(
'b',
PythonArgumentKind.NORMAL,
None,
'int'
),
],
'int',
None,
['decorator1', 'decorator2']
)
),
(
ast_node('def func(): ...'),
PythonFunctionDefinition(
'func',
[],
None,
None,
[]
)
),
(
ast_node('@decorator\ndef func(): ...'),
PythonFunctionDefinition(
'func',
[],
None,
None,
['decorator']
)
),
])
def test_PythonDefinition_from_node(node, expected):
assert PythonFunctionDefinition.from_node(node) == expected