1. Pypy
  2. Untitled project
  3. pypy

Commits

wlav  committed 99c1280

ability to read-back TTree branches that are of bool type

  • Participants
  • Parent commits 8b4ea08
  • Branches reflex-support

Comments (0)

Files changed (2)

File pypy/module/cppyy/capi/cint_capi.py

View file
         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))

File pypy/module/cppyy/test/test_cint.py

View file
         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
         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
         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