def test04_pretty_repr(self): """Create a pretty repr for the new class""" from cppyy.gbl import Integer1 Integer1.__repr__ = lambda self: repr(self.m_data) assert str([Integer1(j) for j in range(10)]) == '[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]'
def test03_STL_containers(self): """Instantiate STL contaienrs with new class""" from cppyy.gbl import Integer1 from cppyy.gbl.std import vector v = vector[Integer1]() v += [Integer1(j) for j in range(10)]
def test02_python_introspection(self): """Introspection of newly created class/instances""" from cppyy.gbl import Integer1 i = Integer1(42) assert hasattr(i, 'm_data') assert not isinstance(i, int) assert isinstance(i, Integer1)
def test01_class_existence(self): """Existence and importability of created class""" import cppyy assert cppyy.gbl.Integer1 assert issubclass(cppyy.gbl.Integer1, object) from cppyy.gbl import Integer1 assert cppyy.gbl.Integer1 is Integer1 i = Integer1(42) assert isinstance(i, Integer1)
def test06_add_operator(self): """Add operator+""" import cppyy cppyy.cppdef(""" namespace Math { Integer2 operator+(const Integer2& left, const Integer1& right) { return left.m_data + right.m_data; } }""") from cppyy.gbl import Integer1 from cppyy.gbl.Math import Integer2 i = Integer1(42) i2 = Integer2(13) k = i2 + i assert int(k) == i2.m_data + i.m_data