Author: Wim Lavrijsen <[email protected]>
Branch: reflex-support
Changeset: r59940:99c1280ae1cd
Date: 2013-01-10 17:21 -0800
http://bitbucket.org/pypy/pypy/changeset/99c1280ae1cd/
Log: ability to read-back TTree branches that are of bool type
diff --git a/pypy/module/cppyy/capi/cint_capi.py
b/pypy/module/cppyy/capi/cint_capi.py
--- a/pypy/module/cppyy/capi/cint_capi.py
+++ b/pypy/module/cppyy/capi/cint_capi.py
@@ -213,6 +213,7 @@
w_typename = space.call_method(w_leaf, "GetTypeName" )
from pypy.module.cppyy import capi
typename = capi.c_resolve_name(space.str_w(w_typename))
+ if typename == 'bool': typename = '_Bool'
w_address = space.call_method(w_leaf, "GetValuePointer")
from pypy.module._cffi_backend import cdataobj, newtype
cdata = cdataobj.W_CData(space, address,
newtype.new_primitive_type(space, typename))
diff --git a/pypy/module/cppyy/test/test_cint.py
b/pypy/module/cppyy/test/test_cint.py
--- a/pypy/module/cppyy/test/test_cint.py
+++ b/pypy/module/cppyy/test/test_cint.py
@@ -318,7 +318,7 @@
assert i == self.N
def test07_write_builtin(self):
- """Test writing of a builtins"""
+ """Test writing of builtins"""
from cppyy import gbl # bootstraps, only needed for tests
from cppyy.gbl import TFile, TTree
@@ -329,21 +329,25 @@
mytree._python_owns = False
import array
- a = array.array('i', [0])
- b = array.array('d', [0.])
+ ba = array.array('c', [chr(0)])
+ ia = array.array('i', [0])
+ da = array.array('d', [0.])
- mytree.Branch("myi", a, "myi/I")
- mytree.Branch("myd", b, "myd/D")
+ mytree.Branch("my_bool", ba, "my_bool/O")
+ mytree.Branch("my_int", ia, "my_int/I")
+ mytree.Branch("my_double", da, "my_double/D")
for i in range(self.N):
- a[0] = i+1 # make sure value is different from
default (0)
- b[0] = (i+1)/2. # id. 0.
+ # make sure value is different from default (0)
+ ba[0] = i%2 and chr(0) or chr(1)
+ ia[0] = i+1
+ da[0] = (i+1)/2.
mytree.Fill()
f.Write()
f.Close()
def test08_read_builtin(self):
- """Test reading of a single branched TTree with an
std::vector<double>"""
+ """Test reading of builtins"""
from cppyy import gbl
from cppyy.gbl import TFile
@@ -351,10 +355,13 @@
f = TFile(self.fname)
mytree = f.Get(self.tname)
+ raises(AttributeError, getattr, mytree, "does_not_exist")
+
i = 1
for event in mytree:
- assert event.myi == i
- assert event.myd == i/2.
+ assert event.my_bool == (i-1)%2 and 0 or 1
+ assert event.my_int == i
+ assert event.my_double == i/2.
i += 1
assert (i-1) == self.N
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit