def test_array(self): import cppyy from cppyy.gbl import Concrete from array import array c = Concrete() c.array_method(array('d', [1., 2., 3., 4.]), 4) raises(IndexError, c.m_data.__getitem__, 4)
def test_default_arguments(self): import cppyy from cppyy.gbl import Concrete c = Concrete() assert c.m_int == 42 c = Concrete(13) assert c.m_int == 13
def test_ref(self): import cppyy from cppyy.gbl import Concrete from ctypes import c_uint c = Concrete() u = c_uint(0) c.uint_ref_assign(u, 42) assert u.value == 42
def test_casting(self): import cppyy from cppyy.gbl import Abstract, Concrete c = Concrete() assert 'Abstract' in Concrete.show_autocast.__doc__ d = c.show_autocast() assert type(d) == cppyy.gbl.Concrete from cppyy import addressof, bind_object e = bind_object(addressof(d), Abstract) assert type(e) == cppyy.gbl.Abstract
def test_static_data_members(self): import cppyy from cppyy.gbl import Concrete assert Concrete.s_int == 321 Concrete().s_int = 123 assert Concrete.s_int == 123
def test_data_members(self): import cppyy from cppyy.gbl import Concrete c = Concrete() assert c.m_int == 42 raises(TypeError, setattr, c, 'm_const_int', 71)
def test_abstract_class(self): import cppyy from cppyy.gbl import Abstract, Concrete raises(TypeError, Abstract) assert issubclass(Concrete, Abstract) c = Concrete() assert isinstance(c, Abstract)
def test_keyword_arguments(self): import cppyy from cppyy.gbl import Concrete c = Concrete(n=17) assert c.m_int == 17 caught = False try: c = Concrete(m=18) # unknown keyword except TypeError as e: assert 'unexpected keyword argument' in str(e) caught = True assert caught == True kwds = {'n': 18} c = Concrete(**kwds) assert c.m_int == 18
def test_operator_conversions(self): import cppyy from cppyy.gbl import Concrete assert str(Concrete()) == 'Hello operator const char*!'
def test_memory(self): import cppyy from cppyy.gbl import Concrete c = Concrete() assert c.__python_owns__ == True