Skip to content

Commit b1503dc

Browse files
committed
Fix intro doc replace
1 parent d419934 commit b1503dc

5 files changed

+23
-2
lines changed

atest/translation.json

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
"name_changed": {
77
"name": "name_changed_again",
88
"doc": "This is also replaced.\n\nnew line."
9+
},
10+
"__init__": {
11+
"name": "__init__",
12+
"doc": "Replaces init docs with this one."
13+
},
14+
"__intro__": {
15+
"name": "__intro__",
16+
"doc": "New __intro__ documentation is here."
917
}
10-
11-
}
18+
}

src/robotlibcore.py

+5
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def __init__(self, library_components: List, translation: Optional[Path] = None)
7070
def add_library_components(self, library_components: List, translation: Optional[dict] = None):
7171
translation = translation if translation else {}
7272
self.keywords_spec["__init__"] = KeywordBuilder.build(self.__init__, translation) # type: ignore
73+
self.__replace_intro_doc(translation)
7374
for component in library_components:
7475
for name, func in self.__get_members(component):
7576
if callable(func) and hasattr(func, "robot_name"):
@@ -86,6 +87,10 @@ def __get_keyword_name(self, func: Callable, name: str, translation: dict):
8687
return translation[name]["name"]
8788
return func.robot_name or name
8889

90+
def __replace_intro_doc(self, translation: dict):
91+
if "__intro__" in translation:
92+
self.__doc__ = translation["__intro__"].get("doc", "")
93+
8994
def __set_library_listeners(self, library_components: list):
9095
listeners = self.__get_manually_registered_listeners()
9196
listeners.extend(self.__get_component_listeners([self, *library_components]))

utest/test_robotlibcore.test_dir_dyn_lib.approved.txt

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"_HybridCore__get_manually_registered_listeners",
1010
"_HybridCore__get_members",
1111
"_HybridCore__get_members_from_instance",
12+
"_HybridCore__replace_intro_doc",
1213
"_HybridCore__set_library_listeners",
1314
"_other_name_here",
1415
"add_library_components",

utest/test_robotlibcore.test_dir_hubrid_lib.approved.txt

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"_HybridCore__get_manually_registered_listeners",
77
"_HybridCore__get_members",
88
"_HybridCore__get_members_from_instance",
9+
"_HybridCore__replace_intro_doc",
910
"_HybridCore__set_library_listeners",
1011
"_other_name_here",
1112
"add_library_components",

utest/test_translations.py

+7
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ def test_translations_docs(lib: SmallLibrary):
2727
assert kw.documentation == "This is new doc"
2828
kw = keywords["name_changed_again"]
2929
assert kw.documentation == "This is also replaced.\n\nnew line."
30+
31+
def test_init_and_lib_docs(lib: SmallLibrary):
32+
keywords = lib.keywords_spec
33+
init = keywords["__init__"]
34+
assert init.documentation == "Replaces init docs with this one."
35+
doc = lib.get_keyword_documentation("__intro__")
36+
assert doc == "New __intro__ documentation is here."

0 commit comments

Comments
 (0)