with self.assertRaises(TypeError):
Vt._ReturnDictionary(bad2)
+ def test_WrappedTypesComparable(self):
+ """
+ Makes sure that values wrapped in a value wrapper are still
+ equality-comparable.
+ """
+ t1 = Vt.Token("hello")
+ t2 = Vt.Token("hello")
+ t3 = Vt.Token("world")
+ f1 = Vt.Float(1.0)
+ f2 = Vt.Float(1.0)
+ d1 = Vt.Double(1.0)
+
+ self.assertEqual(t1, t2)
+ self.assertNotEqual(t1, t3)
+ self.assertNotEqual(t1, f1)
+ self.assertEqual(f1, f2)
+ self.assertNotEqual(f1, d1)
+
if __name__ == '__main__':
unittest.main()
template <typename T> explicit Vt_ValueWrapper(T val) : _val(val) {}
VtValue const &GetValue() const { return _val; }
+
+ bool operator==(const Vt_ValueWrapper &other) {
+ return _val == other._val;
+ }
+
+ bool operator!=(const Vt_ValueWrapper &other) {
+ return _val != other._val;
+ }
+
+ std::string GetAsString() {
+ return TfStringPrintf(
+ "%s(%s)", _val.GetTypeName().c_str(), TfStringify(_val).c_str());
+ }
private:
VtValue _val;
Vt_ValueFromPython();
Vt_ValueWrapperFromPython();
- class_<Vt_ValueWrapper>("_ValueWrapper", no_init);
+ class_<Vt_ValueWrapper>("_ValueWrapper", no_init)
+ .def(self == self)
+ .def(self != self)
+ .def("__str__", &Vt_ValueWrapper::GetAsString)
+ .def("__repr__", &Vt_ValueWrapper::GetAsString)
+ ;
static char const *funcDocString = "%s(value) -> _ValueWrapper\n\n"
"value : %s\n\n"