Exemple #1
0
 def test_getMem_onConstAttr_raisesWriteMemoryError(self, ctype, addrspace):
     const_ctype = ctype.with_attr('const').bind(addrspace)
     cobj = cdm.CProxy(const_ctype, 0)
     with pytest.raises(core.WriteProtectError):
         cobj.mem = b'x'
Exemple #2
0
 def cobj_of_val(self, val):
     static_val_ctype = Mock(convert_from_c_repr=Mock(return_value=val),
                             __addrspace__=Mock(),
                             side_effect=self.cobj_of_val,
                             has_attr=Mock(return_value=False))
     return cdm.CProxy(static_val_ctype, 0)
Exemple #3
0
 def test_getMem_onConstAttr_setsReadonlyFlag(self, ctype, addrspace):
     const_ctype = ctype.with_attr('const').bind(addrspace)
     cobj = cdm.CProxy(const_ctype, 0)
     assert cobj.mem.readonly
Exemple #4
0
 def test_getVal_returnsConvertedCRepr(self, ctype, addrspace):
     ctype.convert_from_c_repr = convert_from_c_repr = Mock()
     cproxy = cdm.CProxy(ctype.bind(addrspace), 0)
     assert cproxy.val is convert_from_c_repr.return_value
     convert_from_c_repr.assert_called_once_with(addrspace.content[:1])
Exemple #5
0
 def cobj(self, ctype, addrspace):
     bound_ctype = ctype.bind(addrspace)
     adr = addrspace.alloc_memory(10)
     return cdm.CProxy(bound_ctype, adr)
Exemple #6
0
 def test_init_onManagedMemoryBlocks(self, ctype, addrspace):
     adr = addrspace.alloc_memory(10)
     bound_ctype = ctype.bind(addrspace)
     cproxy = cdm.CProxy(bound_ctype, adr)
Exemple #7
0
 def test_init_setsAttributes(self, ctype, addrspace):
     adr = addrspace.alloc_memory(10)
     bound_ctype = ctype.bind(addrspace)
     cproxy = cdm.CProxy(bound_ctype, adr)
     assert cproxy.ctype is bound_ctype
     assert cproxy.__address__ == adr