From 26fde24a41319f1e59cddec2caee3636e8dd422d Mon Sep 17 00:00:00 2001 From: Ryan Porter Date: Sun, 9 May 2021 17:20:30 -0700 Subject: [PATCH] Make Plug.asChar and Plug.setChar expect ordinal ints --- src/MPlug.inl | 8 ++++---- tests/test_MPlug.py | 26 ++++++-------------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/MPlug.inl b/src/MPlug.inl index fcd331d..7474a8f 100644 --- a/src/MPlug.inl +++ b/src/MPlug.inl @@ -28,10 +28,10 @@ plug.def(py::init<>()) return self.asBool(); }, R"pbdoc(Retrieves the plug's value, as a boolean.)pbdoc") - .def("asChar", [](MPlug & self) -> char { + .def("asChar", [](MPlug & self) -> int { plug::assert_not_null(self); - return self.asChar(); + return (self.asChar()); }, R"pbdoc(Retrieves the plug's value, as a single-byte integer.)pbdoc") .def("asDouble", [](MPlug & self) -> double { @@ -447,10 +447,10 @@ Note that the behavior of connectedTo() is identical to destinationsWithConversi self.setBool(value); }, R"pbdoc(Sets the plug's value as a boolean.)pbdoc") - .def("setChar", [](MPlug & self, char value) { + .def("setChar", [](MPlug & self, int value) { plug::assert_not_null(self); - self.setChar(value); + self.setChar(char(value)); }, R"pbdoc(Sets the plug's value as a single-byte integer.)pbdoc") .def("setDouble", [](MPlug & self, double value) { diff --git a/tests/test_MPlug.py b/tests/test_MPlug.py index f0fd77b..bb1a408 100644 --- a/tests/test_MPlug.py +++ b/tests/test_MPlug.py @@ -387,7 +387,7 @@ def test_asType_methods(): for (method_name, value, add_attr_kwargs, set_attr_kwargs) in [ ('asBool', True, {'at': 'bool'}, {}), - ('asChar', (65, 'A'), {'at': 'char'}, {}), + ('asChar', ord('A'), {'at': 'char'}, {}), ('asDouble', 1.0, {'at': 'double'}, {}), ('asFloat', 1.0, {'at': 'float'}, {}), ('asInt', 5, {'at': 'long'}, {}), @@ -407,26 +407,19 @@ def test_asType_methods(): def check_asType_method(method_name, value, add_attr_kwargs, set_attr_kwargs): """Test for MPlug::as* bindings.""" - - # 'asChar' expects an int but returns a char in Python - if isinstance(value, tuple): - in_value, out_value = value - else: - in_value = value - out_value = value node = cmds.createNode('network') attr = p(node, 'attr') cmds.addAttr(node, ln='attr', **add_attr_kwargs) - cmds.setAttr(attr, in_value, **set_attr_kwargs) + cmds.setAttr(attr, value, **set_attr_kwargs) plug = cmdc.SelectionList().add(attr).getPlug(0) method = getattr(plug, method_name) - expected = out_value + expected = value actual = method() error_message = ( @@ -463,7 +456,7 @@ def test_setType_methods(): for (method_name, value, add_attr_kwargs) in [ ('setBool', True, {'at': 'bool'}), - ('setChar', ('A', 65), {'at': 'char'}), + ('setChar', ord('A'), {'at': 'char'}), ('setDouble', 1.0, {'at': 'double'}), ('setFloat', 1.0, {'at': 'float'}), ('setInt', 5, {'at': 'long'}), @@ -485,13 +478,6 @@ def test_setType_methods(): def check_setType_method(method_name, value, add_attr_kwargs): """Test for MPlug::set* bindings.""" - # 'asChar' expects an int but returns a char in Python - if isinstance(value, tuple): - in_value, out_value = value - else: - in_value = value - out_value = value - node = cmds.createNode('network') attr = p(node, 'attr') @@ -501,9 +487,9 @@ def check_setType_method(method_name, value, add_attr_kwargs): plug = cmdc.SelectionList().add(attr).getPlug(0) method = getattr(plug, method_name) - method(in_value) + method(value) - expected = out_value + expected = value actual = cmds.getAttr(attr) error_message = (