style: format source code using Ruff

This commit is contained in:
jakob.scheid committed 2026-09-21 20:10:04 +02:00
1 parent d9887f34c9
commit aa4a139878
41 files changed
+6061 -5670

No files matched your search

@@ -25,31 +25,35 @@ 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!'),
[],
@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, "
"PythonDocstring('Hello, World!'), [])"
),
),
),
])
],
)
def test_PythonDefinition_string_representation(definition, expected):
assert repr(definition) == expected
@@ -364,129 +368,132 @@ def test_PythonFunctionDefinition_exceptions(
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'
@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'],
),
],
),
),
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: ...'),
PythonClassDefinition(
'Class',
[],
None,
[],
[],
(
ast_node("class Class: '''docstring'''"),
PythonClassDefinition(
'Class',
[],
PythonDocstring('docstring'),
[],
[],
),
),
),
(
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\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('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
@@ -17,24 +17,28 @@ from src.jcloud_docsgen.core.python.docstrings import PythonDocstring
from src.jcloud_docsgen.exceptions import InvalidPythonIdentifierError
import pytest
@pytest.mark.parametrize('definition,expected', [
(
PythonDefinition(
'a',
None,
[],
@pytest.mark.parametrize(
'definition,expected',
[
(
PythonDefinition(
'a',
None,
[],
),
"PythonDefinition('a', None, [])",
),
'PythonDefinition(\'a\', None, [])',
),
(
PythonDefinition(
'a',
PythonDocstring('Hello, World!'),
[],
(
PythonDefinition(
'a',
PythonDocstring('Hello, World!'),
[],
),
"PythonDefinition('a', PythonDocstring('Hello, World!'), [])",
),
'PythonDefinition(\'a\', PythonDocstring(\'Hello, World!\'), [])',
),
])
],
)
def test_PythonDefinition_string_representation(definition, expected):
assert repr(definition) == expected
@@ -280,164 +284,167 @@ def test_PythonDefinition_exceptions(
assert str(exc_info.value) == expected_exception_message
@pytest.mark.parametrize('definition1,definition2,expected', [
(
PythonDefinition(
'a',
None,
[],
@pytest.mark.parametrize(
'definition1,definition2,expected',
[
(
PythonDefinition(
'a',
None,
[],
),
PythonDefinition(
'a',
None,
[],
),
True,
),
PythonDefinition(
'a',
None,
[],
(
PythonDefinition(
'a',
PythonDocstring('doc'),
[],
),
PythonDefinition(
'a',
PythonDocstring('doc'),
[],
),
True,
),
True,
),
(
PythonDefinition(
'a',
PythonDocstring('doc'),
[],
(
PythonDefinition(
'a',
PythonDocstring('doc'),
['a'],
),
PythonDefinition(
'a',
PythonDocstring('doc'),
['a'],
),
True,
),
PythonDefinition(
'a',
PythonDocstring('doc'),
[],
(
PythonDefinition(
'a',
PythonDocstring('doc'),
['a', 'b'],
),
PythonDefinition(
'a',
PythonDocstring('doc'),
['a', 'b'],
),
True,
),
True,
),
(
PythonDefinition(
'a',
PythonDocstring('doc'),
['a'],
(
PythonDefinition(
'a',
None,
[],
),
PythonDefinition(
'b',
None,
[],
),
False,
),
PythonDefinition(
'a',
PythonDocstring('doc'),
['a'],
(
PythonDefinition(
'a',
PythonDocstring('doc'),
[],
),
PythonDefinition(
'a',
None,
[],
),
False,
),
True,
),
(
PythonDefinition(
'a',
PythonDocstring('doc'),
['a', 'b'],
(
PythonDefinition(
'a',
PythonDocstring('doc'),
[],
),
PythonDefinition(
'a',
PythonDocstring('docs'),
[],
),
False,
),
PythonDefinition(
'a',
PythonDocstring('doc'),
['a', 'b'],
(
PythonDefinition(
'a',
None,
['a'],
),
PythonDefinition(
'a',
None,
['b'],
),
False,
),
True,
),
(
PythonDefinition(
'a',
None,
[],
(
PythonDefinition(
'a',
None,
['a'],
),
PythonDefinition(
'a',
None,
[],
),
False,
),
PythonDefinition(
'b',
None,
[],
(
PythonDefinition(
'a',
None,
['a'],
),
PythonDefinition(
'a',
None,
['a', 'b'],
),
False,
),
False,
),
(
PythonDefinition(
'a',
PythonDocstring('doc'),
[],
(
PythonDefinition(
'a',
None,
['b', 'a'],
),
PythonDefinition(
'a',
None,
['a', 'b'],
),
False,
),
PythonDefinition(
'a',
None,
[],
(
PythonDefinition(
'a',
PythonDocstring('doc'),
[],
),
PythonDefinition(
'b',
None,
['a', 'b'],
),
False,
),
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
assert (definition2 == definition1) == expected
@@ -22,31 +22,35 @@ 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!'),
[],
@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,"
" PythonDocstring('Hello, World!'), [])"
),
),
),
])
],
)
def test_PythonDefinition_string_representation(definition, expected):
assert repr(definition) == expected
@@ -57,295 +61,296 @@ def test_PythonDefinition_string_representation(definition, expected):
'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',
),
])
(
'',
[],
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,
@@ -360,100 +365,106 @@ def test_PythonFunctionDefinition_exceptions(
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'
@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,
[],
),
),
PythonFunctionDefinition(
'add',
[
PythonFunctionArgument(
'a',
PythonArgumentKind.NORMAL,
None,
'int',
(
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'
),
PythonFunctionArgument(
'b',
PythonArgumentKind.NORMAL,
None,
'int',
),
],
'int',
None,
['decorator1', 'decorator2'],
),
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('def func(): ...'),
PythonFunctionDefinition(
'func',
[],
None,
None,
[],
),
),
),
(
ast_node('@decorator\ndef func(): ...'),
PythonFunctionDefinition(
'func',
[],
None,
None,
['decorator'],
(
ast_node('@decorator\ndef func(): ...'),
PythonFunctionDefinition(
'func',
[],
None,
None,
['decorator'],
),
),
),
])
],
)
def test_PythonDefinition_from_node(node, expected):
assert PythonFunctionDefinition.from_node(node) == expected