generated from jCloud/repository-template
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:
25 files changed
+6726
-1071
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -12,56 +12,374 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from src.jcloud_docsgen.core.python.arguments import PythonFunctionArgument, PythonArgumentKind
|
||||
from src.jcloud_docsgen.exceptions import InvalidPythonIdentifierError, InvalidPythonAnnotationError, PythonArgumentStructureError
|
||||
from src.jcloud_docsgen.core.python.arguments import (
|
||||
PythonFunctionArgument,
|
||||
PythonArgumentKind
|
||||
)
|
||||
from src.jcloud_docsgen.exceptions import (
|
||||
InvalidPythonIdentifierError,
|
||||
InvalidPythonAnnotationError,
|
||||
PythonArgumentStructureError
|
||||
)
|
||||
import pytest
|
||||
|
||||
@pytest.mark.parametrize('name,kind,default,annotation,expected_exception,expected_exception_msg', [
|
||||
(None, PythonArgumentKind.NORMAL, None, None, TypeError, 'expected \'str\', got \'NoneType\''),
|
||||
(1, PythonArgumentKind.NORMAL, None, None, TypeError, 'expected \'str\', got \'int\''),
|
||||
(42, PythonArgumentKind.NORMAL, None, None, TypeError, 'expected \'str\', got \'int\''),
|
||||
(4.2, PythonArgumentKind.NORMAL, None, None, TypeError, 'expected \'str\', got \'float\''),
|
||||
(4.2, PythonArgumentKind.NORMAL, None, None, TypeError, 'expected \'str\', got \'float\''),
|
||||
('a', PythonArgumentKind.NORMAL, 1, None, TypeError, 'expected either \'str\' or \'NoneType\', got \'int\''),
|
||||
('a', PythonArgumentKind.NORMAL, None, 1, TypeError, 'expected either \'str\' or \'NoneType\', got \'int\''),
|
||||
('a', 0, None, None, TypeError, 'expected \'PythonArgumentKind\', got \'int\''),
|
||||
('a', PythonArgumentKind.NORMAL, None, '', InvalidPythonAnnotationError, 'invalid annotation'),
|
||||
('', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier'),
|
||||
('.', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: .'),
|
||||
('#', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: #'),
|
||||
('1a', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: 1a'),
|
||||
('1_', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: 1_'),
|
||||
('1,', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: 1,'),
|
||||
(',', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: ,'),
|
||||
(':', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: :'),
|
||||
('-', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: -'),
|
||||
(';', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: ;'),
|
||||
('|', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: |'),
|
||||
('<', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: <'),
|
||||
('>', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: >'),
|
||||
('a,', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: a,'),
|
||||
(',a', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: ,a'),
|
||||
('a:', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: a:'),
|
||||
(':a', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: :a'),
|
||||
('a-', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: a-'),
|
||||
('-a', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: -a'),
|
||||
('a;', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: a;'),
|
||||
(';a', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: ;a'),
|
||||
('a|', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: a|'),
|
||||
('|a', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: |a'),
|
||||
('a<', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: a<'),
|
||||
('<a', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: <a'),
|
||||
('a>', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: a>'),
|
||||
('>a', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: >a'),
|
||||
('class', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: class'),
|
||||
('def', PythonArgumentKind.NORMAL, None, None, InvalidPythonIdentifierError, 'invalid identifier: def'),
|
||||
('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):
|
||||
@pytest.mark.parametrize(
|
||||
'name,kind,default,annotation,expected_exception,expected_exception_msg',
|
||||
[
|
||||
(
|
||||
None,
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
TypeError,
|
||||
'expected \'str\', got \'NoneType\''
|
||||
),
|
||||
(
|
||||
1,
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
TypeError,
|
||||
'expected \'str\', got \'int\''
|
||||
),
|
||||
(
|
||||
42,
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
TypeError,
|
||||
'expected \'str\', got \'int\''
|
||||
),
|
||||
(
|
||||
4.2,
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
TypeError,
|
||||
'expected \'str\', got \'float\''
|
||||
),
|
||||
(
|
||||
4.2,
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
TypeError,
|
||||
'expected \'str\', got \'float\''
|
||||
),
|
||||
(
|
||||
'a',
|
||||
PythonArgumentKind.NORMAL,
|
||||
1,
|
||||
None,
|
||||
TypeError,
|
||||
'expected either \'str\' or \'NoneType\', got \'int\''
|
||||
),
|
||||
(
|
||||
'a',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
1,
|
||||
TypeError,
|
||||
'expected either \'str\' or \'NoneType\', got \'int\''
|
||||
),
|
||||
(
|
||||
'a',
|
||||
0,
|
||||
None,
|
||||
None,
|
||||
TypeError,
|
||||
'expected \'PythonArgumentKind\', got \'int\''
|
||||
),
|
||||
(
|
||||
'a',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
'',
|
||||
InvalidPythonAnnotationError,
|
||||
'invalid annotation'
|
||||
),
|
||||
(
|
||||
'',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier'
|
||||
),
|
||||
(
|
||||
'.',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: .'
|
||||
),
|
||||
(
|
||||
'#',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: #'
|
||||
),
|
||||
(
|
||||
'1a',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: 1a'
|
||||
),
|
||||
(
|
||||
'1_',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: 1_'
|
||||
),
|
||||
(
|
||||
'1,',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: 1,'
|
||||
),
|
||||
(
|
||||
',',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: ,'
|
||||
),
|
||||
(
|
||||
':',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: :'
|
||||
),
|
||||
(
|
||||
'-',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: -'
|
||||
),
|
||||
(
|
||||
';',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: ;'
|
||||
),
|
||||
(
|
||||
'|',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: |'
|
||||
),
|
||||
(
|
||||
'<',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: <'
|
||||
),
|
||||
(
|
||||
'>',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: >'
|
||||
),
|
||||
(
|
||||
'a,',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: a,'
|
||||
),
|
||||
(
|
||||
',a',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: ,a'
|
||||
),
|
||||
(
|
||||
'a:',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: a:'
|
||||
),
|
||||
(
|
||||
':a',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: :a'
|
||||
),
|
||||
(
|
||||
'a-',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: a-'
|
||||
),
|
||||
(
|
||||
'-a',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: -a'
|
||||
),
|
||||
(
|
||||
'a;',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: a;'
|
||||
),
|
||||
(
|
||||
';a',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: ;a'
|
||||
),
|
||||
(
|
||||
'a|',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: a|'
|
||||
),
|
||||
(
|
||||
'|a',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: |a'
|
||||
),
|
||||
(
|
||||
'a<',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: a<'
|
||||
),
|
||||
(
|
||||
'<a',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: <a'
|
||||
),
|
||||
(
|
||||
'a>',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: a>'
|
||||
),
|
||||
(
|
||||
'>a',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: >a'
|
||||
),
|
||||
(
|
||||
'class',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: class'
|
||||
),
|
||||
(
|
||||
'def',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None,
|
||||
InvalidPythonIdentifierError,
|
||||
'invalid identifier: def'
|
||||
),
|
||||
(
|
||||
'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:
|
||||
PythonFunctionArgument(name, kind, default, annotation)
|
||||
assert str(exc_info.value) == expected_exception_msg
|
||||
@@ -136,22 +454,150 @@ def test_PythonFunctionArgument_asterik(name, kind, annotation):
|
||||
PythonFunctionArgument(name, kind, None, annotation)
|
||||
|
||||
@pytest.mark.parametrize('argument,expected', [
|
||||
(PythonFunctionArgument('a', PythonArgumentKind.NORMAL, None, None), 'a'),
|
||||
(PythonFunctionArgument('a', PythonArgumentKind.NORMAL, '1', None), 'a = 1'),
|
||||
(PythonFunctionArgument('a', PythonArgumentKind.NORMAL, None, 'int'), 'a: int'),
|
||||
(PythonFunctionArgument('a', PythonArgumentKind.NORMAL, '1', 'int'), 'a: int = 1'),
|
||||
(PythonFunctionArgument('a', PythonArgumentKind.POSITIONAL_ONLY, None, None), 'a'),
|
||||
(PythonFunctionArgument('a', PythonArgumentKind.POSITIONAL_ONLY, '1', None), 'a = 1'),
|
||||
(PythonFunctionArgument('a', PythonArgumentKind.POSITIONAL_ONLY, None, 'int'), 'a: int'),
|
||||
(PythonFunctionArgument('a', PythonArgumentKind.POSITIONAL_ONLY, '1', 'int'), 'a: int = 1'),
|
||||
(PythonFunctionArgument('a', PythonArgumentKind.KEYWORD_ONLY, None, None), 'a'),
|
||||
(PythonFunctionArgument('a', PythonArgumentKind.KEYWORD_ONLY, '1', None), 'a = 1'),
|
||||
(PythonFunctionArgument('a', PythonArgumentKind.KEYWORD_ONLY, None, 'int'), 'a: int'),
|
||||
(PythonFunctionArgument('a', PythonArgumentKind.KEYWORD_ONLY, '1', 'int'), 'a: int = 1'),
|
||||
(PythonFunctionArgument('a', PythonArgumentKind.VARARG, None, None), '*a'),
|
||||
(PythonFunctionArgument('a', PythonArgumentKind.VARARG, None, 'int'), '*a: int'),
|
||||
(PythonFunctionArgument('a', PythonArgumentKind.KWARGS, None, None), '**a'),
|
||||
(PythonFunctionArgument('a', PythonArgumentKind.KWARGS, None, 'int'), '**a: int'),
|
||||
(
|
||||
PythonFunctionArgument(
|
||||
'a',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
None
|
||||
),
|
||||
'a'
|
||||
),
|
||||
(
|
||||
PythonFunctionArgument(
|
||||
'a',
|
||||
PythonArgumentKind.NORMAL,
|
||||
'1',
|
||||
None
|
||||
),
|
||||
'a = 1'
|
||||
),
|
||||
(
|
||||
PythonFunctionArgument(
|
||||
'a',
|
||||
PythonArgumentKind.NORMAL,
|
||||
None,
|
||||
'int'
|
||||
),
|
||||
'a: int'
|
||||
),
|
||||
(
|
||||
PythonFunctionArgument(
|
||||
'a',
|
||||
PythonArgumentKind.NORMAL,
|
||||
'1',
|
||||
'int'
|
||||
),
|
||||
'a: int = 1'
|
||||
),
|
||||
(
|
||||
PythonFunctionArgument(
|
||||
'a',
|
||||
PythonArgumentKind.POSITIONAL_ONLY,
|
||||
None,
|
||||
None
|
||||
),
|
||||
'a'
|
||||
),
|
||||
(
|
||||
PythonFunctionArgument(
|
||||
'a',
|
||||
PythonArgumentKind.POSITIONAL_ONLY,
|
||||
'1',
|
||||
None
|
||||
),
|
||||
'a = 1'
|
||||
),
|
||||
(
|
||||
PythonFunctionArgument(
|
||||
'a',
|
||||
PythonArgumentKind.POSITIONAL_ONLY,
|
||||
None,
|
||||
'int'
|
||||
),
|
||||
'a: int'
|
||||
),
|
||||
(
|
||||
PythonFunctionArgument(
|
||||
'a',
|
||||
PythonArgumentKind.POSITIONAL_ONLY,
|
||||
'1',
|
||||
'int'
|
||||
),
|
||||
'a: int = 1'
|
||||
),
|
||||
(
|
||||
PythonFunctionArgument(
|
||||
'a',
|
||||
PythonArgumentKind.KEYWORD_ONLY,
|
||||
None,
|
||||
None
|
||||
),
|
||||
'a'
|
||||
),
|
||||
(
|
||||
PythonFunctionArgument(
|
||||
'a',
|
||||
PythonArgumentKind.KEYWORD_ONLY,
|
||||
'1',
|
||||
None
|
||||
),
|
||||
'a = 1'
|
||||
),
|
||||
(
|
||||
PythonFunctionArgument(
|
||||
'a',
|
||||
PythonArgumentKind.KEYWORD_ONLY,
|
||||
None,
|
||||
'int'
|
||||
),
|
||||
'a: int'
|
||||
),
|
||||
(
|
||||
PythonFunctionArgument(
|
||||
'a',
|
||||
PythonArgumentKind.KEYWORD_ONLY,
|
||||
'1',
|
||||
'int'
|
||||
),
|
||||
'a: int = 1'
|
||||
),
|
||||
(
|
||||
PythonFunctionArgument(
|
||||
'a',
|
||||
PythonArgumentKind.VARARG,
|
||||
None,
|
||||
None
|
||||
),
|
||||
'*a'
|
||||
),
|
||||
(
|
||||
PythonFunctionArgument(
|
||||
'a',
|
||||
PythonArgumentKind.VARARG,
|
||||
None,
|
||||
'int'
|
||||
),
|
||||
'*a: int'
|
||||
),
|
||||
(
|
||||
PythonFunctionArgument(
|
||||
'a',
|
||||
PythonArgumentKind.KWARGS,
|
||||
None,
|
||||
None
|
||||
),
|
||||
'**a'
|
||||
),
|
||||
(
|
||||
PythonFunctionArgument(
|
||||
'a',
|
||||
PythonArgumentKind.KWARGS,
|
||||
None,
|
||||
'int'
|
||||
),
|
||||
'**a: int'
|
||||
),
|
||||
])
|
||||
def test_PythonFunctionArgument_signature_repr(argument, expected):
|
||||
assert argument.signature_repr() == expected
|
||||
Reference in new issue
Block a user