]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr: add a test case for the ReturnValueAdapter
authorJohn Mulligan <jmulligan@redhat.com>
Sat, 9 Apr 2022 18:47:01 +0000 (14:47 -0400)
committerAdam King <adking@redhat.com>
Sat, 21 May 2022 23:21:01 +0000 (19:21 -0400)
Signed-off-by: John Mulligan <jmulligan@redhat.com>
(cherry picked from commit 29d8be428c7aa0125ab5c6636cd4b8712e60f71b)

src/pybind/mgr/tests/test_object_format.py

index 1d551d4f7865239ade0c30b91d32ff4a0ea8f717..5a1a4b5a227ca82e3bd8cb51f28aec7676383418 100644 (file)
@@ -103,3 +103,28 @@ def test_format_yaml(obj: Any, compatible: bool, yaml_val: str):
         ).format_yaml()
         == yaml_val
     )
+
+
+class Retty:
+    def __init__(self, v) -> None:
+        self.value = v
+
+    def mgr_return_value(self) -> int:
+        return self.value
+
+
+@pytest.mark.parametrize(
+    "obj, ret",
+    [
+        ({}, 0),
+        ({"fish": "sticks"}, 0),
+        (-55, 0),
+        (Retty(0), 0),
+        (Retty(-55), -55),
+    ],
+)
+def test_return_value(obj: Any, ret: int):
+    rva = object_format.ReturnValueAdapter(obj)
+    # a ReturnValueAdapter instance meets the ReturnValueProvider protocol.
+    assert object_format._is_return_value_provider(rva)
+    assert rva.mgr_return_value() == ret