Skip to content

Commit

Permalink
Make Plug.asChar and Plug.setChar expect ordinal ints
Browse files Browse the repository at this point in the history
  • Loading branch information
yantor3d committed May 10, 2021
1 parent 9a6c7fd commit 26fde24
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/MPlug.inl
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
26 changes: 6 additions & 20 deletions tests/test_MPlug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'}, {}),
Expand All @@ -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 = (
Expand Down Expand Up @@ -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'}),
Expand All @@ -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')
Expand All @@ -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 = (
Expand Down

0 comments on commit 26fde24

Please sign in to comment.