Merge pull request 'Style: trailing commas in multi-line statements' (#21) from style/multiline-trailing-commas into main

Reviewed-on: #21
This commit was merged in pull request #21.
This commit is contained in:
jakob.scheid authored and Gitea committed 2026-09-18 22:22:15 +02:00
commit f680110110
30 files changed
+1778 -1774

No files matched your search

+1 -1
View File
@@ -18,5 +18,5 @@ from .core import __all__ as _core__all__
__all__ = [
'cli',
*_core__all__
*_core__all__,
]
+1 -1
View File
@@ -19,5 +19,5 @@ from .cli import main
__all__ = [
'cli',
'languages',
'main'
'main',
]
+10 -10
View File
@@ -25,7 +25,7 @@ __all__ = [
'existing_directory',
'error',
'create_argument_parser',
'main'
'main',
]
_LANG_PYTHON = 'python'
@@ -70,33 +70,33 @@ def create_argument_parser() -> argparse.ArgumentParser:
type = existing_directory,
nargs = '?',
default = pathlib.Path('.'),
help = 'The directory of the project'
help = 'The directory of the project',
)
common_parser.add_argument(
'-o',
'--output-dir',
type = pathlib.Path,
help = 'the output directory the documentation will be written to'
help = 'the output directory the documentation will be written to',
)
argument_parser = argparse.ArgumentParser()
subparsers = argument_parser.add_subparsers(
dest = 'language',
required = True
required = True,
)
python_parser = subparsers.add_parser(
_LANG_PYTHON,
parents = [common_parser],
help = 'generate documentation for Python project'
help = 'generate documentation for Python project',
)
python_parser.add_argument(
'-s',
'--sections',
nargs = '+',
choices = VALID_PYTHON_SECTIONS,
help = 'the sections to be included in the documentation'
help = 'the sections to be included in the documentation',
)
python_parser.add_argument(
'-S',
@@ -107,7 +107,7 @@ def create_argument_parser() -> argparse.ArgumentParser:
help = (
'the sections to be excluded in the documentation. '
'If a section shall be included AND excluded, it is excluded.'
)
),
)
python_parser.add_argument(
'-H',
@@ -116,7 +116,7 @@ def create_argument_parser() -> argparse.ArgumentParser:
help = (
'indicates whether HTML is allowed in the documentation. '
'By default, HTML is disabled.'
)
),
)
python_parser.add_argument(
'-T',
@@ -126,7 +126,7 @@ def create_argument_parser() -> argparse.ArgumentParser:
'indicates whether Markdown tables are allowed in the '
'documentation. By default, Markdown tables are disabled. '
'Warning: Markdown tables are not CommonMark.'
)
),
)
return argument_parser
@@ -147,7 +147,7 @@ def main(argv = None) -> int:
include_sections = args.sections,
exclude_sections = args.sections_exclude,
allow_html = args.allow_html,
allow_tables = args.allow_tables
allow_tables = args.allow_tables,
)
except FileNotFoundError as exc:
return error(f'{exc.filename}: no such file or directory')
+1 -1
View File
@@ -15,5 +15,5 @@
from . import python
__all__ = [
'python'
'python',
]
+8 -8
View File
@@ -15,14 +15,14 @@
import pathlib
from ...core.python import (
PythonDefinitionDocumentationIncludeSections,
PythonDocumentationGenerator
PythonDocumentationGenerator,
)
from typing import Optional
__all__ = [
'VALID_SECTIONS',
'parse_sections_list',
'generate'
'generate',
]
VALID_SECTIONS = list(
@@ -31,7 +31,7 @@ VALID_SECTIONS = list(
def parse_sections_list(
include_sections: Optional[list[str]] = None,
exclude_sections: list[str] = []
exclude_sections: list[str] = [],
) -> PythonDefinitionDocumentationIncludeSections:
'''
Returns a Python definition documentation sections list from the
@@ -64,7 +64,7 @@ def parse_sections_list(
docstring = 'docstring' in include_sections,
bases = 'bases' in include_sections,
decorators = 'decorators' in include_sections,
class_body = 'class_body' in include_sections
class_body = 'class_body' in include_sections,
)
def _generate(
@@ -75,7 +75,7 @@ def _generate(
PythonDefinitionDocumentationIncludeSections()
),
allow_html: bool = False,
allow_tables: bool = False
allow_tables: bool = False,
) -> None:
'''
Generates the documentation for a Python project.
@@ -99,7 +99,7 @@ def _generate(
output_directory,
include_sections = include_sections,
allow_html = allow_html,
allow_tables = allow_tables
allow_tables = allow_tables,
)
docs_generator.generate_documentation()
@@ -110,7 +110,7 @@ def generate(
include_sections: Optional[list[str]] = None,
exclude_sections: list[str] = [],
allow_html: bool = False,
allow_tables: bool = False
allow_tables: bool = False,
) -> None:
'''
Generates the documentation for a Python project.
@@ -139,5 +139,5 @@ def generate(
output_directory,
include_sections = sections,
allow_html = allow_html,
allow_tables = allow_tables
allow_tables = allow_tables,
)
+1 -1
View File
@@ -15,5 +15,5 @@
from . import python
__all__ = [
'python'
'python',
]
+1 -1
View File
@@ -18,5 +18,5 @@ from . import namespaces
__all__ = [
*_core__all__,
'namespaces'
'namespaces',
]
+34 -34
View File
@@ -20,7 +20,7 @@ from .definitions import (
PythonAsyncFunctionDefinition,
PythonClassDefinition,
PythonDefinition,
PythonFunctionDefinition
PythonFunctionDefinition,
)
from .arguments import PythonArgumentKind, PythonFunctionArgument
from .docstrings import PythonDocstring
@@ -63,11 +63,11 @@ _Arguments: TypeAlias = tuple[
list[PythonFunctionArgument],
Union[PythonFunctionArgument, None],
list[PythonFunctionArgument],
Union[PythonFunctionArgument, None]
Union[PythonFunctionArgument, None],
]
def _group_argument_list(
argument_list: list[PythonFunctionArgument]
argument_list: list[PythonFunctionArgument],
) -> _Arguments:
'''
Groups the argument list into a list of positional-only arguments, a
@@ -86,7 +86,7 @@ def _group_argument_list(
for arg in argument_list
]):
raise PythonArgumentStructureError(
'arguments cannot follow var-keyword argument'
'arguments cannot follow var-keyword argument',
)
positional_only_args = []
@@ -106,7 +106,7 @@ def _group_argument_list(
if vararg is not None:
raise PythonArgumentStructureError(
'* argument may only appear once',
definition = arg
definition = arg,
)
vararg = arg
@@ -121,11 +121,11 @@ def _group_argument_list(
normal_args,
vararg,
keyword_only_args,
kwargs
kwargs,
)
def _signature_argument_list(
argument_list: list[PythonFunctionArgument]
argument_list: list[PythonFunctionArgument],
) -> list[str]:
'''
Returns a list of the arguments as strings for a function signature.
@@ -142,7 +142,7 @@ def _signature_argument_list(
normal_args,
vararg,
keyword_only_args,
kwargs
kwargs,
) = _group_argument_list(argument_list)
args = []
@@ -198,7 +198,7 @@ def _markdown_table(
allow_markdown_table: bool = False,
force_row_lengths: bool = False,
one_line_values: bool = True,
missing_value: str = '--'
missing_value: str = '--',
) -> str:
'''
Generates a table.
@@ -247,7 +247,7 @@ def _markdown_table(
"s"
if header_len > 1
else ""
}, got {len(row)}'
}, got {len(row)}',
)
else:
row = _fit_row_length(header_len, row)
@@ -273,7 +273,7 @@ def _markdown_table(
"s"
if header_len > 1
else ""
}, got {len(row)}'
}, got {len(row)}',
)
else:
row = _fit_row_length(header_len, row)
@@ -358,7 +358,7 @@ def _argument_kind_human_readable(argument_kind: PythonArgumentKind) -> str:
def _function_params_info(
arg_list: list[PythonFunctionArgument],
docstring_arg_list: list[docstring_parser.DocstringParam]
docstring_arg_list: list[docstring_parser.DocstringParam],
) -> dict[str, _FunctionParamInfo]:
'''
Returns a dictionary with the parameter info.
@@ -388,7 +388,7 @@ def _function_params_info(
if arg.arg_name in arg_annotations.keys():
arg_annotations[arg.arg_name] = _FunctionParamInfo(
arg_annotations[arg.arg_name].annotation or arg.type_name,
arg.description
arg.description,
)
return arg_annotations
@@ -427,7 +427,7 @@ class PythonDefinitionDocumentationIncludeSections:
docstring: bool = True,
bases: bool = True,
decorators: bool = True,
class_body: bool = True
class_body: bool = True,
):
self.signature = signature
self.returns = returns
@@ -456,13 +456,13 @@ class PythonDefinitionDocumentationIncludeSections:
[
key + ' = ' + repr(value)
for key, value in self._args.items()
]
],
) + ')'
def __eq__(self, value) -> str:
if not isinstance(
value,
PythonDefinitionDocumentationIncludeSections
PythonDefinitionDocumentationIncludeSections,
):
return False
return self._args == value._args
@@ -505,7 +505,7 @@ class PythonDefinitionDocumentationGenerator:
allow_html: bool = True,
allow_tables: bool = False,
skip_empty_sections: bool = True,
is_method: bool = False
is_method: bool = False,
) -> None:
self.definition = definition
self.include_sections = include_sections
@@ -539,13 +539,13 @@ class PythonDefinitionDocumentationGenerator:
if isinstance(self.definition, PythonClassDefinition):
raise TypeError(
'Cannot generate a signature of a class definition.'
'Cannot generate a signature of a class definition.',
)
signature = self.definition.name + '(' + ', '.join(
_signature_argument_list(
self.definition.args
)
self.definition.args,
),
) + ')'
if self.definition.returns is not None:
@@ -616,7 +616,7 @@ class PythonDefinitionDocumentationGenerator:
params_types = _function_params_info(
self.definition.args,
self._docstring.params
self._docstring.params,
)
if params_types:
@@ -632,11 +632,11 @@ class PythonDefinitionDocumentationGenerator:
('`' + arg.default + '`')
if arg.default is not None
else None,
non_empty_str(params_types.get(arg.name).description)
non_empty_str(params_types.get(arg.name).description),
)
for arg in self.definition.args
],
allow_markdown_table = self.allow_tables
allow_markdown_table = self.allow_tables,
)
md += '\n\n'
@@ -800,7 +800,7 @@ class PythonDefinitionDocumentationGenerator:
allow_html = self.allow_html,
allow_tables = self.allow_tables,
skip_empty_sections = self.skip_empty_sections,
is_method = True
is_method = True,
).generate_documentation() + '\n\n'
if not self.definition.body and not self.skip_empty_sections:
@@ -896,12 +896,12 @@ class PythonModuleDocumentationGenerator:
include_sections: PythonDefinitionDocumentationIncludeSections = (
PythonDefinitionDocumentationIncludeSections()
),
**kwargs
**kwargs,
) -> None:
if module_path.name.count('.') > 1:
raise InvalidNamespaceError(
'namespace identifier cannot contain more than one dot',
namespace_identifier = module_path.name
namespace_identifier = module_path.name,
)
self.module_path = pathlib.Path(str(module_path))
@@ -956,8 +956,8 @@ class PythonModuleDocumentationGenerator:
module_identifier = '.'.join(
get_relative_path_segments(
self.module_path,
self.src_directory
)
self.src_directory,
),
)
if module_identifier.endswith('.py'):
md += module_identifier[:-3]
@@ -977,7 +977,7 @@ class PythonModuleDocumentationGenerator:
definition,
self.include_sections,
2,
**self.kwargs
**self.kwargs,
).generate_documentation() + '\n\n'
return md.strip()
@@ -990,7 +990,7 @@ def _generate_package_namespace_documentation(
include_sections: PythonDefinitionDocumentationIncludeSections = (
PythonDefinitionDocumentationIncludeSections()
),
kwargs: dict = {}
kwargs: dict = {},
) -> None:
'''
Generates the documentation for a package namespace and writes it to
@@ -1021,7 +1021,7 @@ def _generate_package_namespace_documentation(
documentation_directory / sub_namespace.name,
root_directory, dir / sub_namespace.name,
include_sections,
kwargs
kwargs,
)
elif isinstance(sub_namespace, PythonModuleNamespace):
(
@@ -1031,7 +1031,7 @@ def _generate_package_namespace_documentation(
pathlib.Path(str(dir / (sub_namespace.name + '.py'))),
pathlib.Path(str(root_directory)),
include_sections,
**kwargs
**kwargs,
).generate_documentation()
)
@@ -1055,7 +1055,7 @@ class PythonDocumentationGenerator:
include_sections: PythonDefinitionDocumentationIncludeSections = (
PythonDefinitionDocumentationIncludeSections()
),
**kwargs
**kwargs,
) -> None:
self.project_directory = pathlib.Path(str(project_directory))
self.docs_directory = pathlib.Path(str(docs_directory))
@@ -1100,5 +1100,5 @@ class PythonDocumentationGenerator:
self.project_directory / 'src',
self.project_directory / 'src',
self.include_sections,
self.kwargs
self.kwargs,
)
+29 -27
View File
@@ -20,7 +20,7 @@ from ...utils import assert_that_is_instance
from ...exceptions import (
InvalidPythonAnnotationError,
InvalidPythonIdentifierError,
PythonArgumentStructureError
PythonArgumentStructureError,
)
import keyword
import types
@@ -28,7 +28,7 @@ import types
__all__ = [
'PythonArgumentKind',
'PythonFunctionArgument',
'PythonASTArgumentsListParser'
'PythonASTArgumentsListParser',
]
class PythonArgumentKind(Enum):
@@ -57,7 +57,7 @@ class PythonFunctionArgument:
name: str,
kind: PythonArgumentKind,
default: Union[str, None],
annotation: Union[str, None]
annotation: Union[str, None],
) -> None:
assert_that_is_instance(name, str)
assert_that_is_instance(kind, PythonArgumentKind)
@@ -68,7 +68,7 @@ class PythonFunctionArgument:
if not name or not name.isidentifier() or keyword.iskeyword(name):
raise InvalidPythonIdentifierError(
'invalid identifier',
identifier = name
identifier = name,
)
# check whether the annotation is a valid annotation
@@ -77,7 +77,7 @@ class PythonFunctionArgument:
if annotation is not None and not annotation:
raise InvalidPythonAnnotationError(
'invalid annotation',
annotation = annotation
annotation = annotation,
)
self.name = name
@@ -87,11 +87,11 @@ class PythonFunctionArgument:
if self.kind in (
PythonArgumentKind.VARARG,
PythonArgumentKind.KWARGS
PythonArgumentKind.KWARGS,
) and self.default is not None:
raise PythonArgumentStructureError(
'* or ** arguments cannot have default values',
definition = self.signature_repr()
definition = self.signature_repr(),
)
def __eq__(self, value: PythonFunctionArgument) -> bool:
@@ -109,7 +109,7 @@ class PythonFunctionArgument:
self.name,
self.kind,
self.default,
self.annotation
self.annotation,
))
def signature_repr(self) -> str:
@@ -192,8 +192,8 @@ class PythonASTArgumentsListParser:
arg.arg,
PythonArgumentKind.POSITIONAL_ONLY,
defaults[i],
None
)
None,
),
)
else:
arguments.append(
@@ -201,7 +201,9 @@ class PythonASTArgumentsListParser:
arg.arg,
PythonArgumentKind.POSITIONAL_ONLY,
defaults[i],
ast.unparse(arg.annotation)))
ast.unparse(arg.annotation),
),
)
i += 1
for arg in self.ast_arguments_list.args:
if arg.annotation is None:
@@ -210,8 +212,8 @@ class PythonASTArgumentsListParser:
arg.arg,
PythonArgumentKind.NORMAL,
defaults[i],
None
)
None,
),
)
else:
arguments.append(
@@ -219,8 +221,8 @@ class PythonASTArgumentsListParser:
arg.arg,
PythonArgumentKind.NORMAL,
defaults[i],
ast.unparse(arg.annotation)
)
ast.unparse(arg.annotation),
),
)
i += 1
if self.ast_arguments_list.vararg is not None:
@@ -230,8 +232,8 @@ class PythonASTArgumentsListParser:
self.ast_arguments_list.vararg.arg,
PythonArgumentKind.VARARG,
None,
None
)
None,
),
)
else:
arguments.append(
@@ -239,8 +241,8 @@ class PythonASTArgumentsListParser:
self.ast_arguments_list.vararg.arg,
PythonArgumentKind.VARARG,
None,
ast.unparse(self.ast_arguments_list.vararg.annotation)
)
ast.unparse(self.ast_arguments_list.vararg.annotation),
),
)
for arg in self.ast_arguments_list.kwonlyargs:
if arg.annotation is None:
@@ -249,8 +251,8 @@ class PythonASTArgumentsListParser:
arg.arg,
PythonArgumentKind.KEYWORD_ONLY,
defaults[i],
None
)
None,
),
)
else:
arguments.append(
@@ -258,8 +260,8 @@ class PythonASTArgumentsListParser:
arg.arg,
PythonArgumentKind.KEYWORD_ONLY,
defaults[i],
ast.unparse(arg.annotation)
)
ast.unparse(arg.annotation),
),
)
i += 1
if self.ast_arguments_list.kwarg is not None:
@@ -269,8 +271,8 @@ class PythonASTArgumentsListParser:
self.ast_arguments_list.kwarg.arg,
PythonArgumentKind.KWARGS,
None,
None
)
None,
),
)
else:
arguments.append(
@@ -278,8 +280,8 @@ class PythonASTArgumentsListParser:
self.ast_arguments_list.kwarg.arg,
PythonArgumentKind.KWARGS,
None,
ast.unparse(self.ast_arguments_list.kwarg.annotation)
)
ast.unparse(self.ast_arguments_list.kwarg.annotation),
),
)
return arguments
+11 -11
View File
@@ -26,7 +26,7 @@ __all__ = [
'PythonDefinition',
'PythonFunctionDefinition',
'PythonAsyncFunctionDefinition',
'PythonClassDefinition'
'PythonClassDefinition',
]
def _python_docstring(doc: Union[str, None]) -> Union[PythonDocstring, None]:
@@ -63,12 +63,12 @@ class PythonDefinition:
self,
name: str,
doc: Union[PythonDocstring, None],
decorators: list[str]
decorators: list[str],
) -> None:
if keyword.iskeyword(name) or not name.isidentifier() or not name:
raise InvalidPythonIdentifierError(
'invalid identifier',
identifier = name
identifier = name,
)
assert_that_is_instance(doc, (PythonDocstring, types.NoneType))
@@ -81,7 +81,7 @@ class PythonDefinition:
return (
self.name,
self.doc,
self.decorators
self.decorators,
)
def __repr__(self) -> str:
@@ -99,7 +99,7 @@ class PythonDefinition:
return cls(
node.name,
_python_docstring(ast.get_docstring(node)),
[ast.unparse(d) for d in node.decorator_list]
[ast.unparse(d) for d in node.decorator_list],
)
def __eq__(self, value: object) -> bool:
@@ -133,7 +133,7 @@ class PythonFunctionDefinition(PythonDefinition):
args: list[PythonFunctionArgument],
returns: Union[str, None],
doc: Union[PythonDocstring, None],
decorators: list[str]
decorators: list[str],
) -> None:
super().__init__(name, doc, decorators)
self.args = args
@@ -145,7 +145,7 @@ class PythonFunctionDefinition(PythonDefinition):
self.args,
self.returns,
self.doc,
self.decorators
self.decorators,
)
@classmethod
@@ -162,7 +162,7 @@ class PythonFunctionDefinition(PythonDefinition):
PythonASTArgumentsListParser(node.args).to_argument_list(),
ast.unparse(node.returns) if node.returns is not None else None,
_python_docstring(ast.get_docstring(node)),
[ast.unparse(d) for d in node.decorator_list]
[ast.unparse(d) for d in node.decorator_list],
)
class PythonAsyncFunctionDefinition(PythonFunctionDefinition):
@@ -210,7 +210,7 @@ class PythonClassDefinition(PythonDefinition):
bases: list[str],
doc: Union[PythonDocstring, None],
decorators: list[str],
body: list[PythonDefinition]
body: list[PythonDefinition],
) -> None:
super().__init__(name, doc, decorators)
self.bases = bases
@@ -222,7 +222,7 @@ class PythonClassDefinition(PythonDefinition):
self.bases,
self.doc,
self.decorators,
self.body
self.body,
)
@classmethod
@@ -253,5 +253,5 @@ class PythonClassDefinition(PythonDefinition):
expr,
(ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)
)
]
],
)
+9 -9
View File
@@ -16,7 +16,7 @@ from __future__ import annotations
from ...exceptions import (
InvalidNamespaceError,
NamespaceNotFoundError,
NamespaceExistsError
NamespaceExistsError,
)
from ...utils import assert_that_is_instance
from typing import Union, TypeAlias, Dict, List
@@ -24,7 +24,7 @@ from typing import Union, TypeAlias, Dict, List
__all__ = [
'PythonNamespace',
'PythonPackageNamespace',
'PythonModuleNamespace'
'PythonModuleNamespace',
]
class PythonNamespace:
@@ -40,7 +40,7 @@ class PythonNamespace:
if not name.strip():
raise InvalidNamespaceError(
'invalid namespace',
namespace_identifier = name
namespace_identifier = name,
)
self.name = name
@@ -52,8 +52,8 @@ PythonPackageNamespaceDictType: TypeAlias = Dict[
str,
Union[
str,
'PythonPackageNamespaceDictType'
]
'PythonPackageNamespaceDictType',
],
]
class PythonPackageNamespace(PythonNamespace):
@@ -69,7 +69,7 @@ class PythonPackageNamespace(PythonNamespace):
def __init__(
self,
name: str,
sub_namespaces: List[PythonNamespace]
sub_namespaces: List[PythonNamespace],
) -> None:
assert_that_is_instance(sub_namespaces, list)
@@ -113,7 +113,7 @@ class PythonPackageNamespace(PythonNamespace):
def _sub_namespaces_names(
self,
package: PythonPackageNamespace
package: PythonPackageNamespace,
) -> PythonPackageNamespaceDictType:
'''
Returns the names of all sub-namespaces of the specified package
@@ -177,7 +177,7 @@ class PythonPackageNamespace(PythonNamespace):
raise NamespaceNotFoundError(
'no such namespace',
namespace_identifier = name
namespace_identifier = name,
)
def add(self, namespace: PythonNamespace) -> None:
@@ -195,7 +195,7 @@ class PythonPackageNamespace(PythonNamespace):
self.__getitem__(namespace.name)
raise NamespaceExistsError(
'namespace already exists',
namespace_identifier = namespace.name
namespace_identifier = namespace.name,
)
except NamespaceNotFoundError:
self._sub_namespaces.append(namespace)
+13 -12
View File
@@ -41,7 +41,7 @@ class ExistingDirectory(pathlib.Path):
raise FileNotFoundError(
errno.ENOENT,
'no such file or directory',
path
path,
)
if not os.path.isdir(path):
raise NotADirectoryError(errno.ENOTDIR, 'not a directory', path)
@@ -61,7 +61,7 @@ class ExistingFile(pathlib.Path):
raise FileNotFoundError(
errno.ENOENT,
'no such file or directory',
path
path,
)
if not os.path.isfile(path):
raise IsADirectoryError(errno.EISDIR, 'is a directory', path)
@@ -85,7 +85,7 @@ def _quote(string: str, quotation_mark: str) -> str:
def human_readable_list(
ls: list,
final_separator: str = 'and',
quotation_mark: str = ''
quotation_mark: str = '',
) -> str:
'''
Generates a human-readable list from a list.
@@ -118,7 +118,7 @@ def human_readable_list(
quotation_mark
) # quote the string representation of the object
for obj in ls[:-1] # do not include the last element of the list
]
],
) + ' ' + final_separator + ' ' + _quote(str(ls[-1]), quotation_mark)
def _list_type_names(types: list[type]) -> list[str]:
@@ -140,13 +140,13 @@ def assert_that_is_instance(
class_or_tuple: Union[
type,
types.UnionType,
tuple[type, ...]
]
tuple[type, ...],
],
) -> None:
if not isinstance(class_or_tuple, Union[type, types.UnionType, tuple]):
raise TypeError(
f'class_or_tuple: expected \'Union[type, types.UnionType, '
f'tuple[type, ...]]\', \'got {type(class_or_tuple).__name__}\''
f'tuple[type, ...]]\', \'got {type(class_or_tuple).__name__}\'',
)
if not isinstance(obj, class_or_tuple):
if isinstance(class_or_tuple, (tuple, types.UnionType)):
@@ -157,13 +157,14 @@ def assert_that_is_instance(
else:
exception_message_expected = ''
exception_message_expected += human_readable_list(
_list_type_names(class_or_tuple), 'or', '\'')
_list_type_names(class_or_tuple), 'or', '\'',
)
else:
exception_message_expected = '\'' + class_or_tuple.__name__ + '\''
raise TypeError(
f'expected {exception_message_expected}, got \'{type(
obj
).__name__}\''
).__name__}\'',
)
def non_empty_str(value: Union[str, None]) -> Union[str, None]:
@@ -192,7 +193,7 @@ def non_empty_str(value: Union[str, None]) -> Union[str, None]:
def get_relative_path_segments(
path: pathlib.Path,
root: pathlib.Path
root: pathlib.Path,
) -> list[str]:
'''
Returns the path segments relative to ``root``.
@@ -209,7 +210,7 @@ def get_relative_path_segments(
return list(
path.resolve()
.relative_to(
root.resolve()
root.resolve(),
)
.parts
.parts,
)
+2 -2
View File
@@ -21,10 +21,10 @@ def test_cli():
sys.executable,
'-m',
'jcloud_docsgen',
'--help'
'--help',
],
capture_output = True,
text = True
text = True,
)
stdout = result.stdout.lower()
assert \
+2 -2
View File
@@ -18,7 +18,7 @@ from jcloud_docsgen.cli.cli import create_argument_parser
@pytest.mark.parametrize('lang', [
'javascript',
'Python',
'PYTHON'
'PYTHON',
])
def test_language_error(lang):
parser = create_argument_parser()
@@ -27,7 +27,7 @@ def test_language_error(lang):
parser.parse_args([lang])
@pytest.mark.parametrize('lang', [
'python'
'python',
])
def test_language_success(lang):
parser = create_argument_parser()
+18 -18
View File
@@ -33,8 +33,8 @@ from jcloud_docsgen.core.python import (
docstring = False,
bases = False,
decorators = False,
class_body = False
)
class_body = False,
),
),
(
[],
@@ -48,8 +48,8 @@ from jcloud_docsgen.core.python import (
docstring = False,
bases = False,
decorators = False,
class_body = False
)
class_body = False,
),
),
(
['signature'],
@@ -63,8 +63,8 @@ from jcloud_docsgen.core.python import (
docstring = False,
bases = False,
decorators = False,
class_body = False
)
class_body = False,
),
),
(
['signature'],
@@ -78,13 +78,13 @@ from jcloud_docsgen.core.python import (
docstring = False,
bases = False,
decorators = False,
class_body = False
)
class_body = False,
),
),
(
None,
[],
PythonDefinitionDocumentationIncludeSections()
PythonDefinitionDocumentationIncludeSections(),
),
(
['signature', 'exceptions', 'bases', 'class_body'],
@@ -98,8 +98,8 @@ from jcloud_docsgen.core.python import (
docstring = False,
bases = False,
decorators = False,
class_body = True
)
class_body = True,
),
),
(
None,
@@ -113,8 +113,8 @@ from jcloud_docsgen.core.python import (
docstring = False,
bases = True,
decorators = True,
class_body = True
)
class_body = True,
),
)
])
def test_parse_sections_list(include, exclude, expected):
@@ -127,7 +127,7 @@ def test_sections_error():
parser.parse_args([
'python',
'-s',
'param' # correct: `params`
'param', # correct: `params`
])
with pytest.raises(SystemExit):
@@ -135,7 +135,7 @@ def test_sections_error():
'python',
'-s',
'params',
'docstrng' # correct: `docstring`
'docstrng', # correct: `docstring`
])
def test_sections_success():
@@ -144,13 +144,13 @@ def test_sections_success():
parser.parse_args([
'python',
'-s',
'params'
'params',
])
parser.parse_args([
'python',
'-s',
'params',
'docstring'
'docstring',
])
def test_docs_generation(expectdir):
@@ -164,5 +164,5 @@ def test_docs_generation(expectdir):
'docstring',
'-HTo',
str(output_dir),
str(input_dir)
str(input_dir),
])
File diff suppressed because it is too large. Load diff
@@ -15,7 +15,7 @@
from src.jcloud_docsgen.core.python import PythonDocumentationGenerator
from src.jcloud_docsgen.core.python.namespaces import (
PythonModuleNamespace,
PythonPackageNamespace
PythonPackageNamespace,
)
import pytest
import pathlib
@@ -28,9 +28,9 @@ import pathlib
),
pathlib.Path(
'tests/unit/core/python/_core/test_project_dirs/pdir_1/docs'
)
),
),
[]
[],
),
(
PythonDocumentationGenerator(
@@ -39,16 +39,16 @@ import pathlib
),
pathlib.Path(
'tests/unit/core/python/_core/test_project_dirs/pdir_2/docs'
)
),
),
[
PythonPackageNamespace(
'pkg',
[
PythonModuleNamespace('module')
]
)
]
],
),
],
),
(
PythonDocumentationGenerator(
@@ -57,7 +57,7 @@ import pathlib
),
pathlib.Path(
'tests/unit/core/python/_core/test_project_dirs/pdir_3/docs'
)
),
),
[
PythonPackageNamespace(
@@ -69,17 +69,17 @@ import pathlib
[
PythonModuleNamespace(
'module2'
)
]
)
]
)
]
),
],
),
],
),
],
),
])
def test_PythonDocumentationGenerator_collect_modules(
python_documentation_generator: PythonDocumentationGenerator,
expected
expected,
):
assert python_documentation_generator.namespace() == expected
@@ -89,7 +89,7 @@ def test_PythonDocumentationGenerator_collect_modules(
(
'tests/unit/core/python/_core/test_PythonDocume'
'ntationGenerator/test_generate_documentation/'
)
),
).iterdir()
])
def test_generate_documentation(dir, expectdir):
@@ -103,13 +103,13 @@ def test_generate_documentation(dir, expectdir):
(
'tests/unit/core/python/_core/test_PythonDocume'
'ntationGenerator/test_generate_documentation/'
)
),
) /
dir /
'project'
)
'project',
),
),
pathlib.Path(str(d)),
allow_tables = True,
allow_html = False
allow_html = False,
).generate_documentation() # simplify the tests
@@ -25,194 +25,192 @@ import pytest
(
'tests/unit/core/python/_core/fil'
'es_with_more_than_one_dot/a.b.c'
)
),
),
None,
InvalidNamespaceError,
'namespace identifier cannot contain more than one dot: a.b.c'
'namespace identifier cannot contain more than one dot: a.b.c',
),
(
pathlib.Path(
(
'tests/unit/core/python/_core/file'
's_with_more_than_one_dot/a.b.c.d'
)
),
),
None,
InvalidNamespaceError,
'namespace identifier cannot contain more than one dot: a.b.c.d'
'namespace identifier cannot contain more than one dot: a.b.c.d',
),
(
pathlib.Path(
(
'tests/unit/core/python/_core/files'
'_with_more_than_one_dot/a.b.c.d.e'
)
),
),
None,
InvalidNamespaceError,
(
'namespace identifier cannot cont'
'ain more than one dot: a.b.c.d.e'
)
),
),
(
pathlib.Path(
(
'tests/unit/core/python/_core/files_'
'with_more_than_one_dot/a.b.c.d.e.f'
)
),
),
None,
InvalidNamespaceError,
(
'namespace identifier cannot conta'
'in more than one dot: a.b.c.d.e.f'
)
),
),
(
pathlib.Path(
(
'tests/unit/core/python/_core/files_w'
'ith_more_than_one_dot/a.b.c.d.e.f.g'
)
),
),
None,
InvalidNamespaceError,
(
'namespace identifier cannot contai'
'n more than one dot: a.b.c.d.e.f.g'
)
),
),
(
pathlib.Path(
(
'tests/unit/core/python/_core/files_wi'
'th_more_than_one_dot/a.b.c.d.e.f.g.h'
)
),
),
None,
InvalidNamespaceError,
(
'namespace identifier cannot contain'
' more than one dot: a.b.c.d.e.f.g.h'
)
),
),
(
pathlib.Path(
(
'tests/unit/core/python/_core/files_wit'
'h_more_than_one_dot/a.b.c.d.e.f.g.h.py'
)
),
),
None,
InvalidNamespaceError,
(
'namespace identifier cannot contain m'
'ore than one dot: a.b.c.d.e.f.g.h.py'
)
),
),
(
pathlib.Path(
(
'tests/unit/core/python/_core/files_wi'
'th_more_than_one_dot/a.b.c.d.e.f.g.py'
)
),
),
None,
InvalidNamespaceError,
(
'namespace identifier cannot contain '
'more than one dot: a.b.c.d.e.f.g.py'
)
),
),
(
pathlib.Path(
(
'tests/unit/core/python/_core/files_w'
'ith_more_than_one_dot/a.b.c.d.e.f.py'
)
),
),
None,
InvalidNamespaceError,
(
'namespace identifier cannot contain'
' more than one dot: a.b.c.d.e.f.py'
)
),
),
(
pathlib.Path(
(
'tests/unit/core/python/_core/files_'
'with_more_than_one_dot/a.b.c.d.e.py'
)
),
),
None,
InvalidNamespaceError,
(
'namespace identifier cannot contai'
'n more than one dot: a.b.c.d.e.py'
)
),
),
(
pathlib.Path(
(
'tests/unit/core/python/_core/files'
'_with_more_than_one_dot/a.b.c.d.py'
)
),
),
None,
InvalidNamespaceError,
(
'namespace identifier cannot conta'
'in more than one dot: a.b.c.d.py'
)
),
),
(
pathlib.Path(
(
'tests/unit/core/python/_core/file'
's_with_more_than_one_dot/a.b.c.py'
)
),
),
None,
InvalidNamespaceError,
(
'namespace identifier cannot cont'
'ain more than one dot: a.b.c.py'
)
),
),
(
pathlib.Path(
(
(
'tests/unit/core/python/_core/fil'
'es_with_more_than_one_dot/a.b.py'
)
)
'tests/unit/core/python/_core/fil'
'es_with_more_than_one_dot/a.b.py'
),
),
None,
InvalidNamespaceError,
'namespace identifier cannot contain more than one dot: a.b.py'
'namespace identifier cannot contain more than one dot: a.b.py',
),
(
pathlib.Path(
(
'tests/unit/core/python/_core/direc'
'tory.with.more.than.one.dot/a.b.py'
)
),
),
None,
InvalidNamespaceError,
'namespace identifier cannot contain more than one dot: a.b.py'
'namespace identifier cannot contain more than one dot: a.b.py',
),
]
],
)
def test_PythonModuleDocumentationGenerator_exceptions(
module_path,
src_directory,
expected_exception,
expected_exception_msg
expected_exception_msg,
):
with pytest.raises(expected_exception) as exc_info:
PythonModuleDocumentationGenerator(module_path, src_directory)
@@ -225,13 +223,13 @@ def test_PythonModuleDocumentationGenerator_exceptions(
(
'tests/unit/core/python/_core/test_pr'
'oject_dirs/pdir_2/src/pkg/module.py'
)
),
),
pathlib.Path(
'tests/unit/core/python/_core/test_project_dirs/pdir_2/src/'
),
allow_tables = True,
allow_html = False
allow_html = False,
),
'''# Module `pkg.module`
@@ -409,11 +407,11 @@ A dog.'''
(
'tests/unit/core/python/_core/test_pr'
'oject_dirs/pdir_2/src/pkg/module.py'
)
),
),
None,
allow_tables = True,
allow_html = False
allow_html = False,
),
'''# Module `module`
@@ -591,11 +589,11 @@ A dog.'''
(
'tests/unit/core/python/_core/test_pr'
'oject_dirs/pdir_2/src/pkg/module.py'
)
),
),
None,
allow_tables = True,
allow_html = True
allow_html = True,
),
(
'''# Module `module`
@@ -761,7 +759,7 @@ Return type: `None`
<details><summary><h3 style="display:inline">Docstring</h3></summary>A dog.'''
'</details>'
)
),
),
(
@@ -770,11 +768,11 @@ Return type: `None`
(
'tests/unit/core/python/_core/test_pr'
'oject_dirs/pdir_2/src/pkg/module.py'
)
),
),
None,
allow_tables = False,
allow_html = True
allow_html = True,
),
(
'''# Module `module`
@@ -982,7 +980,7 @@ Return type: `None`
<details><summary><h3 style="display:inline">Docstring</h3></summary>A '''
'dog.</details>'
)
),
),
(
@@ -991,11 +989,11 @@ Return type: `None`
(
'tests/unit/core/python/_core/test_pr'
'oject_dirs/pdir_2/src/pkg/module.py'
)
),
),
None,
allow_tables = False,
allow_html = False
allow_html = False,
),
'''# Module `module`
@@ -1211,6 +1209,6 @@ A dog.'''
])
def test_PythonModuleDocumentationGenerator_exceptions(
module_documentation_generator,
expected
expected,
):
assert module_documentation_generator.generate_documentation() == expected
@@ -15,11 +15,11 @@
from src.jcloud_docsgen.core.python._core import _collect_definitions
from src.jcloud_docsgen.core.python.definitions import (
PythonClassDefinition,
PythonFunctionDefinition
PythonFunctionDefinition,
)
from src.jcloud_docsgen.core.python.arguments import (
PythonFunctionArgument,
PythonArgumentKind
PythonArgumentKind,
)
from src.jcloud_docsgen.core.python.docstrings import PythonDocstring
import pytest
@@ -49,20 +49,20 @@ def module(source_code: str) -> ast.Module:
'a',
PythonArgumentKind.NORMAL,
None,
None
None,
),
PythonFunctionArgument(
'b',
PythonArgumentKind.NORMAL,
None,
None
None,
),
],
None,
None,
[]
)
]
[],
),
],
),
(
module('''def add(a: int | float, b: int | float) -> int | float:
@@ -97,18 +97,18 @@ class Something:
'a',
PythonArgumentKind.NORMAL,
None,
'int | float'
'int | float',
),
PythonFunctionArgument(
'b',
PythonArgumentKind.NORMAL,
None,
'int | float'
'int | float',
),
],
'int | float',
PythonDocstring('Adds two numbers.'),
[]
[],
),
PythonClassDefinition(
'Something',
@@ -123,18 +123,18 @@ class Something:
'self',
PythonArgumentKind.NORMAL,
None,
None
None,
),
PythonFunctionArgument(
'value',
PythonArgumentKind.NORMAL,
'42',
'typing.Any'
'typing.Any',
),
],
'None',
None,
[]
[],
),
PythonFunctionDefinition(
'value',
@@ -143,12 +143,12 @@ class Something:
'self',
PythonArgumentKind.NORMAL,
None,
None
None,
),
],
'typing.Any',
PythonDocstring('The value.'),
['property']
['property'],
),
PythonFunctionDefinition(
'get_value',
@@ -157,16 +157,16 @@ class Something:
'self',
PythonArgumentKind.NORMAL,
None,
None
None,
),
],
'typing.Any',
PythonDocstring('Returns the value.'),
[]
[],
),
]
)
]
],
),
],
),
(
module('''from src.jcloud_docsgen.core.python import (
@@ -244,13 +244,13 @@ def test_PythonDocumentationGenerator_collect_modules(
'project_directory',
PythonArgumentKind.NORMAL,
None,
None
None,
),
PythonFunctionArgument(
'docs_directory',
PythonArgumentKind.NORMAL,
None,
None
None,
)
],
None,
@@ -263,8 +263,8 @@ def test_PythonDocumentationGenerator_collect_modules(
'''(pathlib.Path('tests/'), 1), (1, pathlib'''
'''.Path('tests/')), (1, pathlib.Path('test'''
'''s')), (None, pathlib.Path('tests'))])'''
)
]
),
],
),
PythonFunctionDefinition(
'test_PythonDocumentationGenerator_collect_modules',
@@ -273,13 +273,13 @@ def test_PythonDocumentationGenerator_collect_modules(
'python_documentation_generator',
PythonArgumentKind.NORMAL,
None,
'PythonDocumentationGenerator'
'PythonDocumentationGenerator',
),
PythonFunctionArgument(
'expected',
PythonArgumentKind.NORMAL,
None,
None
None,
)
],
None,
@@ -301,9 +301,9 @@ def test_PythonDocumentationGenerator_collect_modules(
'''r_3/docs')), [PythonPackageNamespace('pkg', [Python'''
'''ModuleNamespace(\'module'), PythonPackageNamespace('''
'''\'pkg\', [PythonModuleNamespace(\'module2')])])])])'''
)]
)
]
)],
),
],
),
(
module(
@@ -341,33 +341,33 @@ def test_PythonDocumentationGenerator_collect_modules(
'self',
PythonArgumentKind.POSITIONAL_ONLY,
None,
None
None,
),
PythonFunctionArgument(
'value',
PythonArgumentKind.POSITIONAL_ONLY,
None,
'bool'
'bool',
),
PythonFunctionArgument(
'arg',
PythonArgumentKind.NORMAL,
None,
None
None,
)
],
'bool',
None,
[]
)
]
)
]
)
]
)
]
)
[],
),
],
),
],
),
],
),
],
),
])
def test___collect_definitions(module, expected):
assert list(_collect_definitions(module)) == expected
@@ -14,17 +14,17 @@
from src.jcloud_docsgen.core.python._core import (
_function_params_info,
_FunctionParamInfo
_FunctionParamInfo,
)
from src.jcloud_docsgen.core.python.arguments import (
PythonFunctionArgument,
PythonArgumentKind
PythonArgumentKind,
)
import pytest
import docstring_parser
def docstring_args_list(
docstring: str
docstring: str,
) -> list[docstring_parser.DocstringParam]:
'''
Returns the parameter list of a docstring.
@@ -42,68 +42,68 @@ def docstring_args_list(
([
PythonFunctionArgument('a', PythonArgumentKind.NORMAL, '', 'int'),
], ':param a: a\n:type a: str', {
'a': _FunctionParamInfo('int', 'a')
'a': _FunctionParamInfo('int', 'a'),
}),
([
PythonFunctionArgument('a', PythonArgumentKind.NORMAL, '', None),
], ':param a: a\n:type a: str', {
'a': _FunctionParamInfo('str', 'a')
'a': _FunctionParamInfo('str', 'a'),
}),
([
PythonFunctionArgument('a', PythonArgumentKind.NORMAL, '', None),
PythonFunctionArgument('b', PythonArgumentKind.NORMAL, '', None),
], ':param a: a\n:type a: str', {
'a': _FunctionParamInfo('str', 'a'),
'b': _FunctionParamInfo(None, None)
'b': _FunctionParamInfo(None, None),
}),
([
PythonFunctionArgument('a', PythonArgumentKind.NORMAL, '', None),
PythonFunctionArgument('b', PythonArgumentKind.NORMAL, '', 'int'),
], ':param a: a\n:type a: str', {
'a': _FunctionParamInfo('str', 'a'),
'b': _FunctionParamInfo('int', None)
'b': _FunctionParamInfo('int', None),
}),
([
PythonFunctionArgument('a', PythonArgumentKind.NORMAL, '', None),
PythonFunctionArgument('b', PythonArgumentKind.NORMAL, '', 'int'),
], ':param a: a\n:type a: str\n:param b: b\n:type b: str', {
'a': _FunctionParamInfo('str', 'a'),
'b': _FunctionParamInfo('int', 'b')
'b': _FunctionParamInfo('int', 'b'),
}),
([
PythonFunctionArgument('a', PythonArgumentKind.NORMAL, '', None),
], ':param a: a\n:type a: str\n:param b: b\n:type b: int', {
'a': _FunctionParamInfo('str', 'a')
'a': _FunctionParamInfo('str', 'a'),
}),
([
PythonFunctionArgument('a', PythonArgumentKind.NORMAL, '', None),
], '', {
'a': _FunctionParamInfo(None, None)
'a': _FunctionParamInfo(None, None),
}),
([
PythonFunctionArgument('a', PythonArgumentKind.NORMAL, '', 'str'),
], '', {
'a': _FunctionParamInfo('str', None)
'a': _FunctionParamInfo('str', None),
}),
([
PythonFunctionArgument('a', PythonArgumentKind.NORMAL, '', 'str'),
], ':param a:\n:type a: int', {
'a': _FunctionParamInfo('str', '')
'a': _FunctionParamInfo('str', ''),
}),
([
PythonFunctionArgument('a', PythonArgumentKind.NORMAL, '', None),
], ':param a:\n:type a: int', {
'a': _FunctionParamInfo('int', '')
'a': _FunctionParamInfo('int', ''),
}),
([
PythonFunctionArgument('a', PythonArgumentKind.NORMAL, '', None),
], ':param a: a', {
'a': _FunctionParamInfo(None, 'a')
'a': _FunctionParamInfo(None, 'a'),
}),
([
PythonFunctionArgument('a', PythonArgumentKind.NORMAL, '', 'str'),
], ':param a: a', {
'a': _FunctionParamInfo('str', 'a')
'a': _FunctionParamInfo('str', 'a'),
}),
([], ':param a: a\n:type a: str', {}),
([], '', {}),
@@ -28,7 +28,7 @@ import pytest
False,
True,
'--',
''
'',
),
(
[],
@@ -37,7 +37,7 @@ import pytest
False,
True,
'--',
''
'',
),
(
['a'],
@@ -46,7 +46,7 @@ import pytest
False,
True,
'--',
''
'',
),
(
['a'],
@@ -57,7 +57,7 @@ import pytest
'--',
'''| a |
| --- |
| 1 |'''
| 1 |''',
),
(
['a'],
@@ -68,7 +68,7 @@ import pytest
'--',
'''| a |
| --- |
| 1 |'''
| 1 |''',
),
(
['a', 'b'],
@@ -79,7 +79,7 @@ import pytest
'--',
'''| a | b |
| --- | --- |
| 1 | 2 |'''
| 1 | 2 |''',
),
(
['a', 'b'],
@@ -90,7 +90,7 @@ import pytest
'--',
'''| a | b |
| --- | --- |
| 1 | -- |'''
| 1 | -- |''',
),
(
['a', 'b'],
@@ -101,7 +101,7 @@ import pytest
'--',
'''| a | b |
| --- | --- |
| -- | -- |'''
| -- | -- |''',
),
(
['a', 'b'],
@@ -113,7 +113,7 @@ import pytest
'''| a | b |
| --- | --- |
| 1 | 2 |
| 3 | 4 |'''
| 3 | 4 |''',
),
(
['a'],
@@ -124,7 +124,7 @@ import pytest
'--',
'''| a |
| --- |
| line1 line2 |'''
| line1 line2 |''',
),
(
['a'],
@@ -135,7 +135,7 @@ import pytest
'--',
'''| a |
| --- |
| line1\nline2 |'''
| line1\nline2 |''',
),
(
@@ -145,7 +145,7 @@ import pytest
False,
True,
'--',
''
'',
),
(
[],
@@ -154,7 +154,7 @@ import pytest
False,
True,
'--',
''
'',
),
(
['a'],
@@ -163,7 +163,7 @@ import pytest
False,
True,
'--',
''
'',
),
(
['a'],
@@ -172,7 +172,7 @@ import pytest
False,
True,
'--',
'- a: 1'
'- a: 1',
),
(
['a'],
@@ -181,7 +181,7 @@ import pytest
False,
True,
'--',
'- a: 1'
'- a: 1',
),
(
['a', 'b'],
@@ -192,7 +192,7 @@ import pytest
'--',
'''- a: 1
b: 2'''
b: 2''',
),
(
['a', 'b'],
@@ -203,7 +203,7 @@ import pytest
'--',
'''- a: 1
b: --'''
b: --''',
),
(
['a', 'b'],
@@ -214,7 +214,7 @@ import pytest
'--',
'''- a: --
b: --'''
b: --''',
),
(
['a', 'b'],
@@ -229,7 +229,7 @@ import pytest
- a: 3
b: 4'''
b: 4''',
),
(
['a'],
@@ -238,7 +238,7 @@ import pytest
False,
True,
'--',
'- a: line1 line2'
'- a: line1 line2',
),
(
['a'],
@@ -247,9 +247,9 @@ import pytest
False,
False,
'--',
'- a: line1\nline2'
)
]
'- a: line1\nline2',
),
],
)
def test__markdown_table(
header,
@@ -258,7 +258,7 @@ def test__markdown_table(
force_row_lengths,
one_line_values,
missing_value,
expected
expected,
):
assert _markdown_table(
header,
@@ -266,7 +266,7 @@ def test__markdown_table(
allow_markdown_table = allow_markdown_table,
force_row_lengths = force_row_lengths,
one_line_values = one_line_values,
missing_value = missing_value
missing_value = missing_value,
) == expected
@pytest.mark.parametrize(
@@ -283,7 +283,7 @@ def test__markdown_table(
True,
'--',
ValueError,
'expected 1 value, got 2'
'expected 1 value, got 2',
),
(
['a'],
@@ -293,7 +293,7 @@ def test__markdown_table(
True,
'--',
ValueError,
'expected 1 value, got 3'
'expected 1 value, got 3',
),
(
['a'],
@@ -303,7 +303,7 @@ def test__markdown_table(
True,
'--',
ValueError,
'expected 1 value, got 0'
'expected 1 value, got 0',
),
(
['a', 'b'],
@@ -313,7 +313,7 @@ def test__markdown_table(
True,
'--',
ValueError,
'expected 2 values, got 0'
'expected 2 values, got 0',
),
(
['a', 'b'],
@@ -323,7 +323,7 @@ def test__markdown_table(
True,
'--',
ValueError,
'expected 2 values, got 1'
'expected 2 values, got 1',
),
(
['a', 'b'],
@@ -333,7 +333,7 @@ def test__markdown_table(
True,
'--',
ValueError,
'expected 2 values, got 3'
'expected 2 values, got 3',
),
(
@@ -344,7 +344,7 @@ def test__markdown_table(
True,
'--',
ValueError,
'expected 1 value, got 2'
'expected 1 value, got 2',
),
(
['a'],
@@ -354,7 +354,7 @@ def test__markdown_table(
True,
'--',
ValueError,
'expected 1 value, got 3'
'expected 1 value, got 3',
),
(
['a'],
@@ -364,7 +364,7 @@ def test__markdown_table(
True,
'--',
ValueError,
'expected 1 value, got 0'
'expected 1 value, got 0',
),
(
['a', 'b'],
@@ -374,7 +374,7 @@ def test__markdown_table(
True,
'--',
ValueError,
'expected 2 values, got 0'
'expected 2 values, got 0',
),
(
['a', 'b'],
@@ -384,7 +384,7 @@ def test__markdown_table(
True,
'--',
ValueError,
'expected 2 values, got 1'
'expected 2 values, got 1',
),
(
['a', 'b'],
@@ -394,9 +394,9 @@ def test__markdown_table(
True,
'--',
ValueError,
'expected 2 values, got 3'
)
]
'expected 2 values, got 3',
),
],
)
def test__markdown_table_exceptions(
header,
@@ -406,7 +406,7 @@ def test__markdown_table_exceptions(
one_line_values,
missing_value,
expected_exception,
expected_exception_msg
expected_exception_msg,
):
with pytest.raises(expected_exception) as exc_info:
_markdown_table(
@@ -415,6 +415,6 @@ def test__markdown_table_exceptions(
allow_markdown_table = allow_markdown_table,
force_row_lengths = force_row_lengths,
one_line_values = one_line_values,
missing_value = missing_value
missing_value = missing_value,
)
assert str(exc_info.value) == expected_exception_msg
@@ -15,7 +15,7 @@
from src.jcloud_docsgen.core.python._core import _signature_argument_list
from src.jcloud_docsgen.core.python.arguments import (
PythonFunctionArgument,
PythonArgumentKind
PythonArgumentKind,
)
import pytest
@@ -25,93 +25,93 @@ import pytest
'a',
PythonArgumentKind.NORMAL,
None,
None
)
None,
),
], ['a']),
([
PythonFunctionArgument(
'a',
PythonArgumentKind.POSITIONAL_ONLY,
None,
None
)
None,
),
], ['a', '/']),
([
PythonFunctionArgument(
'a',
PythonArgumentKind.POSITIONAL_ONLY,
None,
None
None,
),
PythonFunctionArgument(
'b',
PythonArgumentKind.NORMAL,
None,
None
)
None,
),
], ['a', '/', 'b']),
([
PythonFunctionArgument(
'a',
PythonArgumentKind.POSITIONAL_ONLY,
None,
None
None,
),
PythonFunctionArgument(
'b',
PythonArgumentKind.NORMAL,
None,
None
None,
),
PythonFunctionArgument(
'c',
PythonArgumentKind.KEYWORD_ONLY,
None,
None
)
None,
),
], ['a', '/', 'b', '*', 'c']),
([
PythonFunctionArgument(
'b',
PythonArgumentKind.NORMAL,
None,
None
None,
),
PythonFunctionArgument(
'c',
PythonArgumentKind.KEYWORD_ONLY,
None,
None
)
None,
),
], ['b', '*', 'c']),
([
PythonFunctionArgument(
'c',
PythonArgumentKind.KEYWORD_ONLY,
None,
None
)
None,
),
], ['*', 'c']),
([
PythonFunctionArgument(
'b',
PythonArgumentKind.POSITIONAL_ONLY,
None,
None
None,
),
PythonFunctionArgument(
'c',
PythonArgumentKind.KEYWORD_ONLY,
None,
None
)
None,
),
], ['b', '/', '*', 'c']),
([
PythonFunctionArgument(
'args',
PythonArgumentKind.VARARG,
None,
None
None,
)
], ['*args']),
([
@@ -119,164 +119,164 @@ import pytest
'a',
PythonArgumentKind.NORMAL,
None,
None
None,
),
PythonFunctionArgument(
'args',
PythonArgumentKind.VARARG,
None,
None
)
None,
),
], ['a', '*args']),
([
PythonFunctionArgument(
'a', PythonArgumentKind.POSITIONAL_ONLY,
None,
None
None,
),
PythonFunctionArgument(
'args',
PythonArgumentKind.VARARG,
None,
None
)
None,
),
], ['a', '/', '*args']),
([
PythonFunctionArgument(
'args',
PythonArgumentKind.VARARG,
None,
None
None,
),
PythonFunctionArgument(
'a',
PythonArgumentKind.KEYWORD_ONLY,
None,
None
)
None,
),
], ['*args', 'a']),
([
PythonFunctionArgument(
'args',
PythonArgumentKind.VARARG,
None,
None
None,
),
PythonFunctionArgument(
'kwargs',
PythonArgumentKind.KWARGS,
None,
None
)
None,
),
], ['*args', '**kwargs']),
([
PythonFunctionArgument(
'a',
PythonArgumentKind.POSITIONAL_ONLY,
None,
None
None,
),
PythonFunctionArgument(
'args',
PythonArgumentKind.VARARG,
None,
None
None,
),
PythonFunctionArgument(
'kwargs',
PythonArgumentKind.KWARGS,
None,
None
)
None,
),
], ['a', '/', '*args', '**kwargs']),
([
PythonFunctionArgument(
'a',
PythonArgumentKind.NORMAL,
None,
None
None,
),
PythonFunctionArgument(
'args',
PythonArgumentKind.VARARG,
None,
None
None,
),
PythonFunctionArgument(
'kwargs',
PythonArgumentKind.KWARGS,
None,
None
)
None,
),
], ['a', '*args', '**kwargs']),
([
PythonFunctionArgument(
'args',
PythonArgumentKind.VARARG,
None,
None
None,
),
PythonFunctionArgument(
'a',
PythonArgumentKind.KEYWORD_ONLY,
None,
None
None,
),
PythonFunctionArgument(
'kwargs',
PythonArgumentKind.KWARGS,
None,
None
)
None,
),
], ['*args', 'a', '**kwargs']),
([
PythonFunctionArgument(
'a',
PythonArgumentKind.KEYWORD_ONLY,
None,
None
None,
),
PythonFunctionArgument(
'kwargs',
PythonArgumentKind.KWARGS,
None,
None
)
None,
),
], ['*', 'a', '**kwargs']),
([
PythonFunctionArgument(
'a',
PythonArgumentKind.NORMAL,
None,
None
None,
),
PythonFunctionArgument(
'kwargs',
PythonArgumentKind.KWARGS,
None,
None
)
None,
),
], ['a', '**kwargs']),
([
PythonFunctionArgument(
'a',
PythonArgumentKind.POSITIONAL_ONLY,
None,
None
None,
),
PythonFunctionArgument(
'kwargs',
PythonArgumentKind.KWARGS,
None,
None
)
None,
),
], ['a', '/', '**kwargs']),
([
PythonFunctionArgument(
'a',
PythonArgumentKind.NORMAL,
'1',
'int'
'int',
),
], ['a: int = 1']),
])
File diff suppressed because it is too large. Load diff
@@ -14,12 +14,12 @@
from src.jcloud_docsgen.core.python.arguments import (
PythonFunctionArgument,
PythonArgumentKind
PythonArgumentKind,
)
from src.jcloud_docsgen.exceptions import (
InvalidPythonIdentifierError,
InvalidPythonAnnotationError,
PythonArgumentStructureError
PythonArgumentStructureError,
)
import pytest
@@ -32,7 +32,7 @@ import pytest
None,
None,
TypeError,
'expected \'str\', got \'NoneType\''
'expected \'str\', got \'NoneType\'',
),
(
1,
@@ -40,7 +40,7 @@ import pytest
None,
None,
TypeError,
'expected \'str\', got \'int\''
'expected \'str\', got \'int\'',
),
(
42,
@@ -48,7 +48,7 @@ import pytest
None,
None,
TypeError,
'expected \'str\', got \'int\''
'expected \'str\', got \'int\'',
),
(
4.2,
@@ -56,7 +56,7 @@ import pytest
None,
None,
TypeError,
'expected \'str\', got \'float\''
'expected \'str\', got \'float\'',
),
(
4.2,
@@ -64,7 +64,7 @@ import pytest
None,
None,
TypeError,
'expected \'str\', got \'float\''
'expected \'str\', got \'float\'',
),
(
'a',
@@ -72,7 +72,7 @@ import pytest
1,
None,
TypeError,
'expected either \'str\' or \'NoneType\', got \'int\''
'expected either \'str\' or \'NoneType\', got \'int\'',
),
(
'a',
@@ -80,7 +80,7 @@ import pytest
None,
1,
TypeError,
'expected either \'str\' or \'NoneType\', got \'int\''
'expected either \'str\' or \'NoneType\', got \'int\'',
),
(
'a',
@@ -88,7 +88,7 @@ import pytest
None,
None,
TypeError,
'expected \'PythonArgumentKind\', got \'int\''
'expected \'PythonArgumentKind\', got \'int\'',
),
(
'a',
@@ -96,7 +96,7 @@ import pytest
None,
'',
InvalidPythonAnnotationError,
'invalid annotation'
'invalid annotation',
),
(
'',
@@ -104,7 +104,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier'
'invalid identifier',
),
(
'.',
@@ -112,7 +112,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: .'
'invalid identifier: .',
),
(
'#',
@@ -120,7 +120,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: #'
'invalid identifier: #',
),
(
'1a',
@@ -128,7 +128,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: 1a'
'invalid identifier: 1a',
),
(
'1_',
@@ -136,7 +136,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: 1_'
'invalid identifier: 1_',
),
(
'1,',
@@ -144,7 +144,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: 1,'
'invalid identifier: 1,',
),
(
',',
@@ -152,7 +152,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: ,'
'invalid identifier: ,',
),
(
':',
@@ -160,7 +160,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: :'
'invalid identifier: :',
),
(
'-',
@@ -168,7 +168,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: -'
'invalid identifier: -',
),
(
';',
@@ -176,7 +176,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: ;'
'invalid identifier: ;',
),
(
'|',
@@ -184,7 +184,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: |'
'invalid identifier: |',
),
(
'<',
@@ -192,7 +192,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: <'
'invalid identifier: <',
),
(
'>',
@@ -200,7 +200,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: >'
'invalid identifier: >',
),
(
'a,',
@@ -208,7 +208,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: a,'
'invalid identifier: a,',
),
(
',a',
@@ -216,7 +216,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: ,a'
'invalid identifier: ,a',
),
(
'a:',
@@ -224,7 +224,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: a:'
'invalid identifier: a:',
),
(
':a',
@@ -232,7 +232,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: :a'
'invalid identifier: :a',
),
(
'a-',
@@ -240,7 +240,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: a-'
'invalid identifier: a-',
),
(
'-a',
@@ -248,7 +248,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: -a'
'invalid identifier: -a',
),
(
'a;',
@@ -256,7 +256,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: a;'
'invalid identifier: a;',
),
(
';a',
@@ -264,7 +264,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: ;a'
'invalid identifier: ;a',
),
(
'a|',
@@ -272,7 +272,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: a|'
'invalid identifier: a|',
),
(
'|a',
@@ -280,7 +280,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: |a'
'invalid identifier: |a',
),
(
'a<',
@@ -288,7 +288,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: a<'
'invalid identifier: a<',
),
(
'<a',
@@ -296,7 +296,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: <a'
'invalid identifier: <a',
),
(
'a>',
@@ -304,7 +304,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: a>'
'invalid identifier: a>',
),
(
'>a',
@@ -312,7 +312,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: >a'
'invalid identifier: >a',
),
(
'class',
@@ -320,7 +320,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: class'
'invalid identifier: class',
),
(
'def',
@@ -328,7 +328,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: def'
'invalid identifier: def',
),
(
'lambda',
@@ -336,7 +336,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: lambda'
'invalid identifier: lambda',
),
(
'None',
@@ -344,7 +344,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: None'
'invalid identifier: None',
),
(
'True',
@@ -352,7 +352,7 @@ import pytest
None,
None,
InvalidPythonIdentifierError,
'invalid identifier: True'
'invalid identifier: True',
),
(
'a',
@@ -360,7 +360,7 @@ import pytest
'1',
None,
PythonArgumentStructureError,
'* or ** arguments cannot have default values: *a = 1'
'* or ** arguments cannot have default values: *a = 1',
),
(
'a',
@@ -368,9 +368,9 @@ import pytest
'1',
None,
PythonArgumentStructureError,
'* or ** arguments cannot have default values: **a = 1'
'* or ** arguments cannot have default values: **a = 1',
),
]
],
)
def test_PythonFunctionArgument_exceptions(
name,
@@ -378,7 +378,7 @@ def test_PythonFunctionArgument_exceptions(
default,
annotation,
expected_exception,
expected_exception_msg
expected_exception_msg,
):
with pytest.raises(expected_exception) as exc_info:
PythonFunctionArgument(name, kind, default, annotation)
@@ -459,18 +459,18 @@ def test_PythonFunctionArgument_asterik(name, kind, annotation):
'a',
PythonArgumentKind.NORMAL,
None,
None
None,
),
'a'
'a',
),
(
PythonFunctionArgument(
'a',
PythonArgumentKind.NORMAL,
'1',
None
None,
),
'a = 1'
'a = 1',
),
(
PythonFunctionArgument(
@@ -479,124 +479,124 @@ def test_PythonFunctionArgument_asterik(name, kind, annotation):
None,
'int'
),
'a: int'
'a: int',
),
(
PythonFunctionArgument(
'a',
PythonArgumentKind.NORMAL,
'1',
'int'
'int',
),
'a: int = 1'
'a: int = 1',
),
(
PythonFunctionArgument(
'a',
PythonArgumentKind.POSITIONAL_ONLY,
None,
None
None,
),
'a'
'a',
),
(
PythonFunctionArgument(
'a',
PythonArgumentKind.POSITIONAL_ONLY,
'1',
None
None,
),
'a = 1'
'a = 1',
),
(
PythonFunctionArgument(
'a',
PythonArgumentKind.POSITIONAL_ONLY,
None,
'int'
'int',
),
'a: int'
'a: int',
),
(
PythonFunctionArgument(
'a',
PythonArgumentKind.POSITIONAL_ONLY,
'1',
'int'
'int',
),
'a: int = 1'
'a: int = 1',
),
(
PythonFunctionArgument(
'a',
PythonArgumentKind.KEYWORD_ONLY,
None,
None
None,
),
'a'
'a',
),
(
PythonFunctionArgument(
'a',
PythonArgumentKind.KEYWORD_ONLY,
'1',
None
None,
),
'a = 1'
'a = 1',
),
(
PythonFunctionArgument(
'a',
PythonArgumentKind.KEYWORD_ONLY,
None,
'int'
'int',
),
'a: int'
'a: int',
),
(
PythonFunctionArgument(
'a',
PythonArgumentKind.KEYWORD_ONLY,
'1',
'int'
'int',
),
'a: int = 1'
'a: int = 1',
),
(
PythonFunctionArgument(
'a',
PythonArgumentKind.VARARG,
None,
None
None,
),
'*a'
'*a',
),
(
PythonFunctionArgument(
'a',
PythonArgumentKind.VARARG,
None,
'int'
'int',
),
'*a: int'
'*a: int',
),
(
PythonFunctionArgument(
'a',
PythonArgumentKind.KWARGS,
None,
None
None,
),
'**a'
'**a',
),
(
PythonFunctionArgument(
'a',
PythonArgumentKind.KWARGS,
None,
'int'
'int',
),
'**a: int'
'**a: int',
),
])
def test_PythonFunctionArgument_signature_repr(argument, expected):
@@ -14,11 +14,11 @@
from src.jcloud_docsgen.core.python.definitions import (
PythonFunctionDefinition,
PythonClassDefinition
PythonClassDefinition,
)
from src.jcloud_docsgen.core.python.arguments import (
PythonFunctionArgument,
PythonArgumentKind
PythonArgumentKind,
)
from src.jcloud_docsgen.core.python.docstrings import PythonDocstring
from src.jcloud_docsgen.exceptions import InvalidPythonIdentifierError
@@ -32,9 +32,9 @@ import pytest
[],
None,
None,
[]
[],
),
'PythonClassDefinition(\'A\', [], None, None, [])'
'PythonClassDefinition(\'A\', [], None, None, [])',
),
(
PythonClassDefinition(
@@ -42,12 +42,12 @@ import pytest
[],
None,
PythonDocstring('Hello, World!'),
[]
[],
),
(
'PythonClassDefinition(\'A\', [], None, '
'PythonDocstring(\'Hello, World!\'), [])'
)
),
),
])
def test_PythonDefinition_string_representation(definition, expected):
@@ -67,7 +67,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier'
'invalid identifier',
),
(
'.',
@@ -76,7 +76,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: .'
'invalid identifier: .',
),
(
'#',
@@ -85,7 +85,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: #'
'invalid identifier: #',
),
(
'1a',
@@ -94,7 +94,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1a'
'invalid identifier: 1a',
),
(
'1_',
@@ -103,7 +103,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1_'
'invalid identifier: 1_',
),
(
'1,',
@@ -112,7 +112,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1,'
'invalid identifier: 1,',
),
(
',',
@@ -121,7 +121,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ,'
'invalid identifier: ,',
),
(
':',
@@ -130,7 +130,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: :'
'invalid identifier: :',
),
(
'-',
@@ -139,7 +139,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: -'
'invalid identifier: -',
),
(
';',
@@ -148,7 +148,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ;'
'invalid identifier: ;',
),
(
'|',
@@ -157,7 +157,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: |'
'invalid identifier: |',
),
(
'<',
@@ -166,7 +166,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: <'
'invalid identifier: <',
),
(
'>',
@@ -175,7 +175,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: >'
'invalid identifier: >',
),
(
'a,',
@@ -184,7 +184,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a,'
'invalid identifier: a,',
),
(
',a',
@@ -193,7 +193,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ,a'
'invalid identifier: ,a',
),
(
'a:',
@@ -202,7 +202,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a:'
'invalid identifier: a:',
),
(
':a',
@@ -211,7 +211,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: :a'
'invalid identifier: :a',
),
(
'a-',
@@ -220,7 +220,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a-'
'invalid identifier: a-',
),
(
'-a',
@@ -229,7 +229,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: -a'
'invalid identifier: -a',
),
(
'a;',
@@ -238,7 +238,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a;'
'invalid identifier: a;',
),
(
';a',
@@ -247,7 +247,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ;a'
'invalid identifier: ;a',
),
(
'a|',
@@ -256,7 +256,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a|'
'invalid identifier: a|',
),
(
'|a',
@@ -265,7 +265,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: |a'
'invalid identifier: |a',
),
(
'a<',
@@ -274,7 +274,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a<'
'invalid identifier: a<',
),
(
'<a',
@@ -283,7 +283,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: <a'
'invalid identifier: <a',
),
(
'a>',
@@ -292,7 +292,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a>'
'invalid identifier: a>',
),
(
'>a',
@@ -301,7 +301,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: >a'
'invalid identifier: >a',
),
(
'class',
@@ -310,7 +310,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: class'
'invalid identifier: class',
),
(
'def',
@@ -319,7 +319,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: def'
'invalid identifier: def',
),
(
'lambda',
@@ -328,7 +328,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: lambda'
'invalid identifier: lambda',
),
(
'None',
@@ -337,7 +337,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: None'
'invalid identifier: None',
),
(
'True',
@@ -346,9 +346,9 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: True'
'invalid identifier: True',
),
]
],
)
def test_PythonFunctionDefinition_exceptions(
name,
@@ -357,7 +357,7 @@ def test_PythonFunctionDefinition_exceptions(
doc,
decorators,
expected_exception,
expected_exception_message
expected_exception_message,
):
with pytest.raises(expected_exception) as exc_info:
PythonClassDefinition(name, args, returns, doc, decorators)
@@ -372,8 +372,7 @@ def test_PythonFunctionDefinition_exceptions(
':\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',
@@ -388,18 +387,18 @@ def test_PythonFunctionDefinition_exceptions(
'self',
PythonArgumentKind.NORMAL,
None,
None
None,
),
PythonFunctionArgument(
'value',
PythonArgumentKind.NORMAL,
None,
'object'
)
'object',
),
],
'None',
None,
[]
[],
),
PythonFunctionDefinition(
'value',
@@ -408,15 +407,15 @@ def test_PythonFunctionDefinition_exceptions(
'self',
PythonArgumentKind.NORMAL,
None,
None
)
None,
),
],
'object',
None,
['property']
)
]
)
['property'],
),
],
),
),
(
ast_node('class Class: ...'),
@@ -425,8 +424,8 @@ def test_PythonFunctionDefinition_exceptions(
[],
None,
[],
[]
)
[],
),
),
(
ast_node('class Class: \'\'\'docstring\'\'\''),
@@ -435,8 +434,8 @@ def test_PythonFunctionDefinition_exceptions(
[],
PythonDocstring('docstring'),
[],
[]
)
[],
),
),
(
ast_node('class Class:\n\tdef __init__(self): ...'),
@@ -453,15 +452,15 @@ def test_PythonFunctionDefinition_exceptions(
'self',
PythonArgumentKind.NORMAL,
None,
None
None,
)
],
None,
None,
[]
)
]
)
[],
),
],
),
),
(
ast_node('class Class:\n\t\'\'\'doc\'\'\'\n\tdef __init__(self): ...'),
@@ -478,15 +477,15 @@ def test_PythonFunctionDefinition_exceptions(
'self',
PythonArgumentKind.NORMAL,
None,
None
)
None,
),
],
None,
None,
[]
)
]
)
[],
),
],
),
),
])
def test_PythonDefinition_from_node(node, expected):
@@ -22,17 +22,17 @@ import pytest
PythonDefinition(
'a',
None,
[]
[],
),
'PythonDefinition(\'a\', None, [])'
'PythonDefinition(\'a\', None, [])',
),
(
PythonDefinition(
'a',
PythonDocstring('Hello, World!'),
[]
[],
),
'PythonDefinition(\'a\', PythonDocstring(\'Hello, World!\'), [])'
'PythonDefinition(\'a\', PythonDocstring(\'Hello, World!\'), [])',
),
])
def test_PythonDefinition_string_representation(definition, expected):
@@ -47,233 +47,233 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier'
'invalid identifier',
),
(
'.',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: .'
'invalid identifier: .',
),
(
'#',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: #'
'invalid identifier: #',
),
(
'1a',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1a'
'invalid identifier: 1a',
),
(
'1_',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1_'
'invalid identifier: 1_',
),
(
'1,',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1,'
'invalid identifier: 1,',
),
(
',',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ,'
'invalid identifier: ,',
),
(
':',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: :'
'invalid identifier: :',
),
(
'-',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: -'
'invalid identifier: -',
),
(
';',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ;'
'invalid identifier: ;',
),
(
'|',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: |'
'invalid identifier: |',
),
(
'<',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: <'
'invalid identifier: <',
),
(
'>',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: >'
'invalid identifier: >',
),
(
'a,',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a,'
'invalid identifier: a,',
),
(
',a',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ,a'
'invalid identifier: ,a',
),
(
'a:',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a:'
'invalid identifier: a:',
),
(
':a',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: :a'
'invalid identifier: :a',
),
(
'a-',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a-'
'invalid identifier: a-',
),
(
'-a',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: -a'
'invalid identifier: -a',
),
(
'a;',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a;'
'invalid identifier: a;',
),
(
';a',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ;a'
'invalid identifier: ;a',
),
(
'a|',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a|'
'invalid identifier: a|',
),
(
'|a',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: |a'
'invalid identifier: |a',
),
(
'a<',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a<'
'invalid identifier: a<',
),
(
'<a',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: <a'
'invalid identifier: <a',
),
(
'a>',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a>'
'invalid identifier: a>',
),
(
'>a',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: >a'
'invalid identifier: >a',
),
(
'class',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: class'
'invalid identifier: class',
),
(
'def',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: def'
'invalid identifier: def',
),
(
'lambda',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: lambda'
'invalid identifier: lambda',
),
(
'None',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: None'
'invalid identifier: None',
),
(
'True',
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: True'
'invalid identifier: True',
),
]
],
)
def test_PythonDefinition_exceptions(
name,
doc,
decorators,
expected_exception,
expected_exception_message
expected_exception_message,
):
with pytest.raises(expected_exception) as exc_info:
PythonDefinition(name, doc, decorators)
@@ -285,157 +285,157 @@ def test_PythonDefinition_exceptions(
PythonDefinition(
'a',
None,
[]
[],
),
PythonDefinition(
'a',
None,
[]
[],
),
True
True,
),
(
PythonDefinition(
'a',
PythonDocstring('doc'),
[]
[],
),
PythonDefinition(
'a',
PythonDocstring('doc'),
[]
[],
),
True
True,
),
(
PythonDefinition(
'a',
PythonDocstring('doc'),
['a']
['a'],
),
PythonDefinition(
'a',
PythonDocstring('doc'),
['a']
['a'],
),
True
True,
),
(
PythonDefinition(
'a',
PythonDocstring('doc'),
['a', 'b']
['a', 'b'],
),
PythonDefinition(
'a',
PythonDocstring('doc'),
['a', 'b']
['a', 'b'],
),
True
True,
),
(
PythonDefinition(
'a',
None,
[]
[],
),
PythonDefinition(
'b',
None,
[]
[],
),
False
False,
),
(
PythonDefinition(
'a',
PythonDocstring('doc'),
[]
[],
),
PythonDefinition(
'a',
None,
[]
[],
),
False
False,
),
(
PythonDefinition(
'a',
PythonDocstring('doc'),
[]
[],
),
PythonDefinition(
'a',
PythonDocstring('docs'),
[]
[],
),
False
False,
),
(
PythonDefinition(
'a',
None,
['a']
['a'],
),
PythonDefinition(
'a',
None,
['b']
['b'],
),
False
False,
),
(
PythonDefinition(
'a',
None,
['a']
['a'],
),
PythonDefinition(
'a',
None,
[]
[],
),
False
False,
),
(
PythonDefinition(
'a',
None,
['a']
['a'],
),
PythonDefinition(
'a',
None,
['a', 'b']
['a', 'b'],
),
False
False,
),
(
PythonDefinition(
'a',
None,
['b', 'a']
['b', 'a'],
),
PythonDefinition(
'a',
None,
['a', 'b']
['a', 'b'],
),
False
False,
),
(
PythonDefinition(
'a',
PythonDocstring('doc'),
[]
[],
),
PythonDefinition(
'b',
None,
['a', 'b']
['a', 'b'],
),
False
False,
),
])
def test_PythonDefinition___eq__(definition1, definition2, expected):
@@ -15,7 +15,7 @@
from src.jcloud_docsgen.core.python.definitions import PythonFunctionDefinition
from src.jcloud_docsgen.core.python.arguments import (
PythonFunctionArgument,
PythonArgumentKind
PythonArgumentKind,
)
from src.jcloud_docsgen.core.python.docstrings import PythonDocstring
from src.jcloud_docsgen.exceptions import InvalidPythonIdentifierError
@@ -29,9 +29,9 @@ import pytest
[],
None,
None,
[]
[],
),
'PythonFunctionDefinition(\'a\', [], None, None, [])'
'PythonFunctionDefinition(\'a\', [], None, None, [])',
),
(
PythonFunctionDefinition(
@@ -39,12 +39,12 @@ import pytest
[],
None,
PythonDocstring('Hello, World!'),
[]
[],
),
(
'PythonFunctionDefinition(\'a\', [], None,'
' PythonDocstring(\'Hello, World!\'), [])'
)
),
),
])
def test_PythonDefinition_string_representation(definition, expected):
@@ -64,7 +64,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier'
'invalid identifier',
),
(
'.',
@@ -73,7 +73,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: .'
'invalid identifier: .',
),
(
'#',
@@ -82,7 +82,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: #'
'invalid identifier: #',
),
(
'1a',
@@ -91,7 +91,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1a'
'invalid identifier: 1a',
),
(
'1_',
@@ -100,7 +100,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1_'
'invalid identifier: 1_',
),
(
'1,',
@@ -109,7 +109,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: 1,'
'invalid identifier: 1,',
),
(
',',
@@ -118,7 +118,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ,'
'invalid identifier: ,',
),
(
':',
@@ -127,7 +127,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: :'
'invalid identifier: :',
),
(
'-',
@@ -136,7 +136,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: -'
'invalid identifier: -',
),
(
';',
@@ -145,7 +145,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ;'
'invalid identifier: ;',
),
(
'|',
@@ -154,7 +154,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: |'
'invalid identifier: |',
),
(
'<',
@@ -163,7 +163,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: <'
'invalid identifier: <',
),
(
'>',
@@ -172,7 +172,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: >'
'invalid identifier: >',
),
(
'a,',
@@ -181,7 +181,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a,'
'invalid identifier: a,',
),
(
',a',
@@ -190,7 +190,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ,a'
'invalid identifier: ,a',
),
(
'a:',
@@ -199,7 +199,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a:'
'invalid identifier: a:',
),
(
':a',
@@ -208,7 +208,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: :a'
'invalid identifier: :a',
),
(
'a-',
@@ -217,7 +217,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a-'
'invalid identifier: a-',
),
(
'-a',
@@ -226,7 +226,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: -a'
'invalid identifier: -a',
),
(
'a;',
@@ -235,7 +235,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a;'
'invalid identifier: a;',
),
(
';a',
@@ -244,7 +244,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: ;a'
'invalid identifier: ;a',
),
(
'a|',
@@ -253,7 +253,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a|'
'invalid identifier: a|',
),
(
'|a',
@@ -262,7 +262,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: |a'
'invalid identifier: |a',
),
(
'a<',
@@ -271,7 +271,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a<'
'invalid identifier: a<',
),
(
'<a',
@@ -280,7 +280,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: <a'
'invalid identifier: <a',
),
(
'a>',
@@ -289,7 +289,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: a>'
'invalid identifier: a>',
),
(
'>a',
@@ -298,7 +298,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: >a'
'invalid identifier: >a',
),
(
'class',
@@ -307,7 +307,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: class'
'invalid identifier: class',
),
(
'def',
@@ -316,7 +316,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: def'
'invalid identifier: def',
),
(
'lambda',
@@ -325,7 +325,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: lambda'
'invalid identifier: lambda',
),
(
'None',
@@ -334,7 +334,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: None'
'invalid identifier: None',
),
(
'True',
@@ -343,7 +343,7 @@ def test_PythonDefinition_string_representation(definition, expected):
None,
[],
InvalidPythonIdentifierError,
'invalid identifier: True'
'invalid identifier: True',
),
])
def test_PythonFunctionDefinition_exceptions(
@@ -353,7 +353,7 @@ def test_PythonFunctionDefinition_exceptions(
doc,
decorators,
expected_exception,
expected_exception_message
expected_exception_message,
):
with pytest.raises(expected_exception) as exc_info:
PythonFunctionDefinition(name, args, returns, doc, decorators)
@@ -369,19 +369,19 @@ def test_PythonFunctionDefinition_exceptions(
'a',
PythonArgumentKind.NORMAL,
None,
'int'
'int',
),
PythonFunctionArgument(
'b',
PythonArgumentKind.NORMAL,
None,
'int'
'int',
),
],
'int',
None,
[]
)
[],
),
),
(
ast_node('@decorator\ndef add(a: int, b: int) -> int: return a + b'),
@@ -392,26 +392,26 @@ def test_PythonFunctionDefinition_exceptions(
'a',
PythonArgumentKind.NORMAL,
None,
'int'
'int',
),
PythonFunctionArgument(
'b',
PythonArgumentKind.NORMAL,
None,
'int'
'int',
),
],
'int',
None,
['decorator']
)
['decorator'],
),
),
(
ast_node(
(
'@decorator1\n@decorator2\ndef add(a'
': int, b: int) -> int: return a + b'
)
),
),
PythonFunctionDefinition(
'add',
@@ -420,19 +420,19 @@ def test_PythonFunctionDefinition_exceptions(
'a',
PythonArgumentKind.NORMAL,
None,
'int'
'int',
),
PythonFunctionArgument(
'b',
PythonArgumentKind.NORMAL,
None,
'int'
'int',
),
],
'int',
None,
['decorator1', 'decorator2']
)
['decorator1', 'decorator2'],
),
),
(
ast_node('def func(): ...'),
@@ -441,8 +441,8 @@ def test_PythonFunctionDefinition_exceptions(
[],
None,
None,
[]
)
[],
),
),
(
ast_node('@decorator\ndef func(): ...'),
@@ -451,8 +451,8 @@ def test_PythonFunctionDefinition_exceptions(
[],
None,
None,
['decorator']
)
['decorator'],
),
),
])
def test_PythonDefinition_from_node(node, expected):
@@ -14,12 +14,12 @@
from src.jcloud_docsgen.core.python.namespaces import (
PythonPackageNamespace,
PythonModuleNamespace
PythonModuleNamespace,
)
import pytest
from src.jcloud_docsgen.exceptions import (
NamespaceNotFoundError,
InvalidNamespaceError
InvalidNamespaceError,
)
class StrSubclass(str): ...
@@ -28,23 +28,23 @@ class StrSubclass(str): ...
(
PythonPackageNamespace(
'a',
[]
[],
),
'a'
'a',
),
(
PythonPackageNamespace(
'1',
[]
[],
),
'1'
'1',
),
(
PythonPackageNamespace(
StrSubclass('a'),
[]
[],
),
StrSubclass('a')
StrSubclass('a'),
),
])
def test_PythonPackageNamespace_name_attribute(namespace, expected_name):
@@ -52,7 +52,7 @@ def test_PythonPackageNamespace_name_attribute(namespace, expected_name):
namespace_b = PythonModuleNamespace('b')
namespace_a = PythonPackageNamespace('a', [
namespace_b
namespace_b,
])
namespace_c = PythonModuleNamespace('c')
namespace_k = PythonModuleNamespace('k')
@@ -68,47 +68,47 @@ namespace_d = PythonPackageNamespace('d', [namespace_e])
(
PythonPackageNamespace(
'name',
[namespace_a, namespace_c]
[namespace_a, namespace_c],
),
['c'],
namespace_c
namespace_c,
),
(
PythonPackageNamespace(
'name',
[namespace_a, namespace_c]
[namespace_a, namespace_c],
),
['a'],
namespace_a
namespace_a,
),
(
PythonPackageNamespace(
'name',
[namespace_a, namespace_c]
[namespace_a, namespace_c],
),
['a', 'b'],
namespace_b
namespace_b,
),
(
namespace_d,
['e', 'f', 'g', 'h', 'i'],
namespace_i
namespace_i,
),
(
namespace_d,
['e', 'f', 'g', 'h', 'i', 'j'],
namespace_j
namespace_j,
),
(
namespace_d,
['e', 'f', 'g', 'h', 'i', 'j', 'k'],
namespace_k
namespace_k,
),
])
def test_PythonPackageNamespace_namespace(
namespace: PythonPackageNamespace,
sub_namespaces,
expected
expected,
):
assert namespace.namespace(sub_namespaces) == expected
@@ -119,39 +119,39 @@ def test_PythonPackageNamespace_namespace(
namespace_a,
['c'],
NamespaceNotFoundError,
'no such namespace: c'
'no such namespace: c',
),
(
namespace_h,
['i', 'k'],
NamespaceNotFoundError,
'no such namespace: k'
'no such namespace: k',
),
(
namespace_a,
['b', ''],
InvalidNamespaceError,
'invalid namespace'
'invalid namespace',
),
(
namespace_a,
['', 'b'],
InvalidNamespaceError,
'invalid namespace'
'invalid namespace',
),
(
namespace_a,
['b', '', 'b'],
InvalidNamespaceError,
'invalid namespace'
'invalid namespace',
),
]
],
)
def test_PythonPackageNamespace_namespace_exceptions(
namespace,
sub_namespaces,
expected_exception,
expected_exception_msg
expected_exception_msg,
):
with pytest.raises(expected_exception) as exc_info:
namespace.namespace(sub_namespaces)
@@ -161,9 +161,9 @@ def test_PythonPackageNamespace_namespace_exceptions(
(
PythonPackageNamespace(
'a',
[PythonModuleNamespace('b')]
[PythonModuleNamespace('b')],
),
{'b': 'b'}
{'b': 'b'},
),
(
PythonPackageNamespace(
@@ -172,19 +172,19 @@ def test_PythonPackageNamespace_namespace_exceptions(
PythonModuleNamespace('b'),
PythonPackageNamespace(
'c',
[PythonModuleNamespace('d')]
)
]
[PythonModuleNamespace('d')],
),
],
),
{
'b': 'b',
'c': {'d': 'd'}
}
'c': {'d': 'd'},
},
),
(
PythonPackageNamespace('a', []),
{}
)
{},
),
])
def test_PythonPackageNamespace_sub_namespace_names(namespace, expected):
assert namespace.sub_namespace_names() == expected
@@ -193,13 +193,13 @@ def test_PythonPackageNamespace_sub_namespace_names(namespace, expected):
(
PythonPackageNamespace(
'a',
[PythonModuleNamespace('b')]
[PythonModuleNamespace('b')],
),
PythonPackageNamespace(
'a',
[PythonModuleNamespace('b')]
[PythonModuleNamespace('b')],
),
True
True,
),
(
PythonPackageNamespace(
@@ -208,9 +208,9 @@ def test_PythonPackageNamespace_sub_namespace_names(namespace, expected):
PythonModuleNamespace('b'),
PythonPackageNamespace(
'c',
[PythonModuleNamespace('d')]
)
]
[PythonModuleNamespace('d')],
),
],
),
PythonPackageNamespace(
'a',
@@ -218,21 +218,21 @@ def test_PythonPackageNamespace_sub_namespace_names(namespace, expected):
PythonModuleNamespace('b'),
PythonPackageNamespace(
'c',
[PythonModuleNamespace('d')]
)
]
[PythonModuleNamespace('d')],
),
],
),
True
True,
),
(
PythonPackageNamespace('a', []),
PythonPackageNamespace('a', []),
True
True,
),
(
PythonPackageNamespace('a', []),
PythonPackageNamespace('b', []),
False
False,
),
])
def test_PythonPackageNamespace___eq__(namespace1, namespace2, expected):
@@ -242,19 +242,19 @@ def test_PythonPackageNamespace___eq__(namespace1, namespace2, expected):
@pytest.mark.parametrize('namespace,expected', [
(
PythonPackageNamespace('a', []),
'PythonPackageNamespace(\'a\', [])'
'PythonPackageNamespace(\'a\', [])',
),
(
PythonPackageNamespace('1', []),
'PythonPackageNamespace(\'1\', [])'
'PythonPackageNamespace(\'1\', [])',
),
(
PythonPackageNamespace(StrSubclass('a'), []),
'PythonPackageNamespace(\'a\', [])'
'PythonPackageNamespace(\'a\', [])',
),
(
namespace_a,
'PythonPackageNamespace(\'a\', [PythonModuleNamespace(\'b\')])'
'PythonPackageNamespace(\'a\', [PythonModuleNamespace(\'b\')])',
),
(
namespace_d,
@@ -264,8 +264,8 @@ def test_PythonPackageNamespace___eq__(namespace1, namespace2, expected):
'geNamespace(\'g\', [PythonPackageNamespace(\'h\', [P'
'ythonPackageNamespace(\'i\', [PythonPackageNamespace'
'(\'j\', [PythonModuleNamespace(\'k\')])])])])])])])'
)
)
),
),
])
def test_PythonPackageNamespace_string_representation(namespace, expected):
assert repr(namespace) == expected
@@ -276,14 +276,14 @@ def test_PythonPackageNamespace_string_representation(namespace, expected):
PythonModuleNamespace('b'),
PythonPackageNamespace(
'a',
[PythonModuleNamespace('b')]
)
)
[PythonModuleNamespace('b')],
),
),
])
def test_PythonPackageNamespace___getitem__(
namespace,
new_namespace,
expected
expected,
):
namespace.add(new_namespace)
assert namespace == expected
@@ -34,33 +34,33 @@ def test_assert_that_is_instance(obj, class_or_tuple):
(
1,
str,
'expected \'str\', got \'int\''
'expected \'str\', got \'int\'',
),
(
1,
(str,),
'expected \'str\', got \'int\''
'expected \'str\', got \'int\'',
),
(
1,
str | float,
'expected either \'str\' or \'float\', got \'int\''
'expected either \'str\' or \'float\', got \'int\'',
),
(
1,
str | float | list,
'expected either \'str\', \'float\' or \'list\', got \'int\''
'expected either \'str\', \'float\' or \'list\', got \'int\'',
),
(
1,
TestType,
'expected \'NOT TestType\', got \'int\''
'expected \'NOT TestType\', got \'int\'',
),
])
def test_assert_that_is_instance_exceptions(
obj,
class_or_tuple,
expected_exception_msg
expected_exception_msg,
):
with pytest.raises(TypeError) as exc_info:
assert_that_is_instance(obj, class_or_tuple)
+1 -1
View File
@@ -52,7 +52,7 @@ import pytest
[1, 2, 3, 42, 'a', 23],
'and',
'\'',
'\'1\', \'2\', \'3\', \'42\', \'a\' and \'23\''
'\'1\', \'2\', \'3\', \'42\', \'a\' and \'23\'',
),
])
def test_human_readable_list(ls, final_separator, quotation_mark, expected):