Skip to content

Commit

Permalink
Fix intro doc replace
Browse files Browse the repository at this point in the history
  • Loading branch information
aaltat committed Mar 19, 2024
1 parent d419934 commit 0bbfc06
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
11 changes: 9 additions & 2 deletions atest/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}

}
}
5 changes: 5 additions & 0 deletions src/robotlibcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand All @@ -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]))
Expand Down
1 change: 1 addition & 0 deletions utest/test_robotlibcore.test_dir_dyn_lib.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions utest/test_robotlibcore.test_dir_hubrid_lib.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions utest/test_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."

0 comments on commit 0bbfc06

Please sign in to comment.