refactor(utils)!: move fit_row_length to utility module

Moved the _fit_row_length function from the Python generator core module
to fit_row_length in the utility module. The public exports definition
of the utility module and all imports were updated.

The test module was also moved to the appropriate new path and the
testing functions were renamed.
This commit is contained in:
jakob.scheid committed 2026-10-21 13:01:28 +02:00
1 parent 39d3b0ace4
commit 36bc14185a
3 files changed
+31 -30

No files matched your search

+3 -25
View File
@@ -28,7 +28,7 @@ from ...exceptions import (
InvalidNamespaceError,
PythonArgumentStructureError,
)
from ...utils import get_relative_path_segments, non_empty_str
from ...utils import fit_row_length, get_relative_path_segments, non_empty_str
from .arguments import PythonArgumentKind, PythonFunctionArgument
from .definitions import (
PythonAsyncFunctionDefinition,
@@ -184,28 +184,6 @@ def _signature_argument_list(
return args
def _fit_row_length(expected: int, row: tuple) -> tuple:
"""
Fits the row length to the expected length.
If the row is too long, the tail, that makes it too long, is omitted.
If it is too short, it is filled with ``None`` (at the end).
:param expected: The expected length.
:type expected: int
:param row: The row.
:type row: tuple
"""
if expected < 0:
raise ValueError('expected must be larger than or equal 0.')
if len(row) > expected:
return row[:expected]
else:
return row + (None,) * (expected - len(row))
def _markdown_table(
header: tuple,
body: list[tuple],
@@ -257,7 +235,7 @@ def _markdown_table(
f'{"s" if header_len > 1 else ""}, got {len(row)}'
)
else:
row = _fit_row_length(header_len, row)
row = fit_row_length(header_len, row)
table += (
'| '
@@ -286,7 +264,7 @@ def _markdown_table(
f'{"s" if header_len > 1 else ""}, got {len(row)}'
)
else:
row = _fit_row_length(header_len, row)
row = fit_row_length(header_len, row)
sep = '- '
for i, col in enumerate(row):
+23
View File
@@ -34,6 +34,7 @@ __all__ = [
'assert_that_is_instance',
'non_empty_str',
'get_relative_path_segments',
'fit_row_length',
]
@@ -237,3 +238,25 @@ def get_relative_path_segments(
)
.parts,
)
def fit_row_length(expected: int, row: tuple) -> tuple:
"""
Fits the row length to the expected length.
If the row is too long, the tail, that makes it too long, is omitted.
If it is too short, it is filled with ``None`` (at the end).
:param expected: The expected length.
:type expected: int
:param row: The row.
:type row: tuple
"""
if expected < 0:
raise ValueError('expected must be larger than or equal 0.')
if len(row) > expected:
return row[:expected]
else:
return row + (None,) * (expected - len(row))
@@ -14,7 +14,7 @@
import pytest
from src.jcloud_docsgen.core.python._core import _fit_row_length
from src.jcloud_docsgen.utils import fit_row_length
@pytest.mark.parametrize(
@@ -37,8 +37,8 @@ from src.jcloud_docsgen.core.python._core import _fit_row_length
(3, (1, 2, 3), (1, 2, 3)),
],
)
def test__fit_row_length(expected_length, row, expected):
assert _fit_row_length(expected_length, row) == expected
def test_fit_row_length(expected_length, row, expected):
assert fit_row_length(expected_length, row) == expected
@pytest.mark.parametrize(
@@ -60,7 +60,7 @@ def test__fit_row_length(expected_length, row, expected):
(-42, ValueError),
],
)
def test__fit_row_length_exceptions(expected_length, row, expected_exception):
def test_fit_row_length_exceptions(expected_length, row, expected_exception):
with pytest.raises(expected_exception) as exc_info:
_fit_row_length(expected_length, row)
fit_row_length(expected_length, row)
assert str(exc_info.value) == 'expected must be larger than or equal 0.'