Skip to content

Commit

Permalink
Merge pull request #95 from pymeasure/fix-open-rpc
Browse files Browse the repository at this point in the history
Fix open rpc
  • Loading branch information
BenediktBurger authored Aug 20, 2024
2 parents e7a1872 + 6209ce2 commit 30b307b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 6 additions & 1 deletion pyleco/json_utils/rpc_server_definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ def discover(self) -> dict[str, Any]:
continue
method_dict = {"name": name}
if method.__doc__:
method_dict["description"] = method.__doc__
lines = method.__doc__.split("\n")
method_dict["summary"] = lines[0]
if lines[1:]:
method_dict["description"] = " ".join(
line.strip() for line in lines[1:] if line
).strip()
methods.append(method_dict)
result["methods"] = methods
return result
15 changes: 13 additions & 2 deletions tests/json_utils/test_rpc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ def side_effect_method(arg=None):


def fail():
"""Fails always."""
"""Fail always.
This method fails always.
And has a description.
"""
raise NotImplementedError


Expand Down Expand Up @@ -164,7 +168,14 @@ def test_side_effect_method(self, methods: list):
def test_fail(self, methods: list):
m = methods[2]
assert m["name"] == "fail"
assert m["description"] == fail.__doc__
assert m["summary"] == "Fail always."
assert m.get("description") == "This method fails always. And has a description."

def test_simple_description(self, methods: list):
m = methods[3]
assert m["name"] == "simple"
assert m["summary"] == "A method without parameters."
assert m.get("description") is None

def test_rpc_discover_not_listed(self, methods: list):
for m in methods:
Expand Down

0 comments on commit 30b307b

Please sign in to comment.