diff --git a/atest/translation.json b/atest/translation.json index af5efd1..36795c5 100644 --- a/atest/translation.json +++ b/atest/translation.json @@ -6,6 +6,13 @@ "name_changed": { "name": "name_changed_again", "doc": "This is also replaced.\n\nnew line." + }, + "__init__": { + "name": "__init__", + "doc": "Replaces init docs with this one." + }, + "__intro__": { + "name": "__intro__", + "doc": "New __intro__ documentation is here." } - -} \ No newline at end of file +} diff --git a/src/robotlibcore.py b/src/robotlibcore.py index 8fa8f56..b42f8e6 100644 --- a/src/robotlibcore.py +++ b/src/robotlibcore.py @@ -70,6 +70,7 @@ def __init__(self, library_components: List, translation: Optional[Path] = None) def add_library_components(self, library_components: List, translation: Optional[dict] = None): translation = translation if translation else {} self.keywords_spec["__init__"] = KeywordBuilder.build(self.__init__, translation) # type: ignore + self.__replace_intro_doc(translation) for component in library_components: for name, func in self.__get_members(component): if callable(func) and hasattr(func, "robot_name"): @@ -86,6 +87,10 @@ def __get_keyword_name(self, func: Callable, name: str, translation: dict): return translation[name]["name"] return func.robot_name or name + def __replace_intro_doc(self, translation: dict): + if "__intro__" in translation: + self.__doc__ = translation["__intro__"].get("doc", "") + def __set_library_listeners(self, library_components: list): listeners = self.__get_manually_registered_listeners() listeners.extend(self.__get_component_listeners([self, *library_components])) diff --git a/utest/test_robotlibcore.test_dir_dyn_lib.approved.txt b/utest/test_robotlibcore.test_dir_dyn_lib.approved.txt index 9a8ef25..d4bb728 100644 --- a/utest/test_robotlibcore.test_dir_dyn_lib.approved.txt +++ b/utest/test_robotlibcore.test_dir_dyn_lib.approved.txt @@ -9,6 +9,7 @@ "_HybridCore__get_manually_registered_listeners", "_HybridCore__get_members", "_HybridCore__get_members_from_instance", + "_HybridCore__replace_intro_doc", "_HybridCore__set_library_listeners", "_other_name_here", "add_library_components", diff --git a/utest/test_robotlibcore.test_dir_hubrid_lib.approved.txt b/utest/test_robotlibcore.test_dir_hubrid_lib.approved.txt index 8579980..4de4be5 100644 --- a/utest/test_robotlibcore.test_dir_hubrid_lib.approved.txt +++ b/utest/test_robotlibcore.test_dir_hubrid_lib.approved.txt @@ -6,6 +6,7 @@ "_HybridCore__get_manually_registered_listeners", "_HybridCore__get_members", "_HybridCore__get_members_from_instance", + "_HybridCore__replace_intro_doc", "_HybridCore__set_library_listeners", "_other_name_here", "add_library_components", diff --git a/utest/test_translations.py b/utest/test_translations.py index 20c3dc6..a482a52 100644 --- a/utest/test_translations.py +++ b/utest/test_translations.py @@ -27,3 +27,10 @@ def test_translations_docs(lib: SmallLibrary): assert kw.documentation == "This is new doc" kw = keywords["name_changed_again"] assert kw.documentation == "This is also replaced.\n\nnew line." + +def test_init_and_lib_docs(lib: SmallLibrary): + keywords = lib.keywords_spec + init = keywords["__init__"] + assert init.documentation == "Replaces init docs with this one." + doc = lib.get_keyword_documentation("__intro__") + assert doc == "New __intro__ documentation is here."