diff --git a/atest/config_pyproject/example_pyproject.toml b/atest/config_pyproject/example_pyproject.toml new file mode 100644 index 0000000..cfbed80 --- /dev/null +++ b/atest/config_pyproject/example_pyproject.toml @@ -0,0 +1,32 @@ +[tool.testdoc] +title = "New title of HTML document" +name = "New name of root suite element" +doc = "New doc text of root suite element" +sourceprefix = "gitlab::https://gitlab.com/myrepo/repo_path" +include = ["TagA", "TagB"] +exclude = ["TagC"] +hide_tags = true +hide_test_doc = true +hide_suite_doc = true +hide_source = true +hide_keywords = true +style = "blue" +verbose_mode = false + +[tool.testdoc.metadata] +Author = "Your-Name" +Version = "1.0.0" +Source = "AnySourceAsMetaData" + +[tool.testdoc.colors] +# Use predefined theme: +default = "blue" +# or custom colors: +background = "#000028" +inner_color = "#000028" +button_active_color = "#193966" +button_hover_color = "#193966" +border_color = "#CCCCCC" +text_color = "#CCCCCC" +title_color = "#00ffb9" +robot_icon = "#00ffb9" diff --git a/pyproject.toml b/pyproject.toml index 01c1074..bd2165f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "robotframework-testdoc" -version = "0.1.7" +version = "0.1.8" description = "A CLI Tool to generate a Test Documentation for your RobotFramework Test Scripts." readme = "README.md" requires-python = ">=3.7" @@ -25,4 +25,4 @@ testdoc = "testdoc.cli:main" line-length = 150 lint.select = ["E", "F"] # Pyflakes & pycodestyle lint.ignore = ["E722"] -exclude = ["build", "dist"] \ No newline at end of file +exclude = ["build", "dist"] diff --git a/src/testdoc/cli.py b/src/testdoc/cli.py index 5f63b9d..213b326 100644 --- a/src/testdoc/cli.py +++ b/src/testdoc/cli.py @@ -47,14 +47,15 @@ def main( Welcome to robotframework-testdoc - the new test documentation generator for your Robot Framework tests! """ color = "green" - click.echo(click.style(""" + entrypoint_msg = """ ████████╗███████╗███████╗████████╗██████╗ ███████╗███████╗ ╚══██╔══╝██╔════╝██╔════╝╚══██╔══╝██ ██╗██ ██║██╔════╝ ██║ █████╗ ███████╗ ██║ ██ ██║██ ██║██║ ██║ ██╔══╝ ╚════██║ ██║ ██ ██║██ ██║██║ ██║ ███████╗███████║ ██║ ██████╔╝███████║███████╗ ╚═╝ ╚══════╝╚══════╝ ╚═╝ ╚═════╝ ╚══════╝ ╚═════╝ - """, fg=color) + """ + click.echo(click.style(entrypoint_msg, fg=color) ) args_instance = CommandLineArguments() diff --git a/src/testdoc/helper/cliargs.py b/src/testdoc/helper/cliargs.py index f7cd379..af7f092 100644 --- a/src/testdoc/helper/cliargs.py +++ b/src/testdoc/helper/cliargs.py @@ -1,6 +1,7 @@ from dataclasses import dataclass, field -from typing import List +from typing import Any, List import tomli +import os @dataclass class CommandLineArgumentsData: @@ -32,13 +33,52 @@ def __new__(cls): cls.data = CommandLineArgumentsData() return cls._instance + ### + ### Load configuration file + ### def load_from_config_file(self, file_path: str): with open(file_path, "rb") as f: config = tomli.load(f) + _is_pyproject = self._is_pyproject_config(file_path) + if _is_pyproject: + self._handle_pyproject_config(config) + else: + self._handle_custom_config(config) + + ### + ### Read pyproject.toml + ### + def _handle_pyproject_config(self, config: dict[str, Any]): + testdoc_config = config.get("tool", {}).get("testdoc", {}) + + if "colors" in testdoc_config: + self.data.colors = testdoc_config["colors"] + + if "metadata" in testdoc_config: + if hasattr(self.data, "metadata"): + setattr(self.data, "metadata", testdoc_config["metadata"]) + + for key, value in testdoc_config.items(): + if key in ("colors", "metadata"): + continue + if hasattr(self.data, key): + setattr(self.data, key, value) + + ### + ### Read custom.toml + ### + def _handle_custom_config(self, config: dict[str, Any]): if "colors" in config: self.data.colors = config["colors"] for key, value in config.items(): if hasattr(self.data, key): - setattr(self.data, key, value) \ No newline at end of file + setattr(self.data, key, value) + + ##################################################################################### + + def _is_pyproject_config(self, file_path) -> bool: + return os.path.basename(file_path) == "pyproject.toml" + + ##################################################################################### \ No newline at end of file diff --git a/src/testdoc/parser/testcaseparser.py b/src/testdoc/parser/testcaseparser.py index 1ce0c05..870019d 100644 --- a/src/testdoc/parser/testcaseparser.py +++ b/src/testdoc/parser/testcaseparser.py @@ -1,4 +1,5 @@ from robot.api import TestSuite +from robot.errors import DataError from ..helper.cliargs import CommandLineArguments class TestCaseParser(): @@ -25,8 +26,11 @@ def parse_test(self, # Consider tags via officially provided robot api def consider_tags(self, suite: TestSuite) -> TestSuite: - if len(self.args.include) > 0: - suite.configure(include_tags=self.args.include) - if len(self.args.exclude) > 0: - suite.configure(exclude_tags=self.args.exclude) - return suite \ No newline at end of file + try: + if len(self.args.include) > 0: + suite.configure(include_tags=self.args.include) + if len(self.args.exclude) > 0: + suite.configure(exclude_tags=self.args.exclude) + return suite + except DataError as e: + raise DataError(e.message) \ No newline at end of file