From d58ce020f8654e1acd7c76ecf2c3f529be331e03 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Sat, 9 Apr 2022 14:47:01 -0400 Subject: [PATCH] pybind/mgr: add a test case for the ReturnValueAdapter Signed-off-by: John Mulligan (cherry picked from commit 29d8be428c7aa0125ab5c6636cd4b8712e60f71b) --- src/pybind/mgr/tests/test_object_format.py | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/pybind/mgr/tests/test_object_format.py b/src/pybind/mgr/tests/test_object_format.py index 1d551d4f78652..5a1a4b5a227ca 100644 --- a/src/pybind/mgr/tests/test_object_format.py +++ b/src/pybind/mgr/tests/test_object_format.py @@ -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 -- 2.39.5