Skip to content

Commit

Permalink
changes for moving the load_reflection_info API to the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
wlav committed Aug 5, 2017
1 parent 5dbe7b4 commit f09dab9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 42 deletions.
9 changes: 4 additions & 5 deletions python/cppyy/_pypy_cppyy.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
'gbl',
'addressof',
'bind_object',
'load_reflection_info',
]


# first load the dependency libraries of the backend, then
# pull in the built-in low-level cppyy
c = loader.load_cpp_backend()
Expand All @@ -25,10 +23,11 @@
setattr(_thismodule, name, getattr(_backend, name))
del name, sys

# add _backend itself to exports
__all__.append('_backend')

def load_reflection_info(name):
sc = _backend.gbl.gSystem.Load(name)
if sc == -1:
raise RuntimeError("missing reflection library "+name)

# add other exports to all
__all__.append('load_reflection_info')
__all__.append('_backend')
2 changes: 1 addition & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ifeq ($(PLATFORM),Darwin)
endif

%Dict.so: %_rflx.cpp %.cxx
g++ $(cppflags) -shared -o $@ $^
$(CXX) $(cppflags) -shared -o $@ $^

%_rflx.cpp: %.h %.xml
genreflex $< --selection=$*.xml --rootmap=$*Dict.rootmap --rootmap-lib=$*Dict.so
Expand Down
46 changes: 20 additions & 26 deletions test/test_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ def setup_class(cls):
cls.datatypes = cppyy.load_reflection_info(cls.test_dct)
cls.N = cppyy.gbl.N

def test01_load_reflection_cache(self):
"""Loading reflection info twice should result in the same object"""
import cppyy
lib2 = cppyy.load_reflection_info(self.test_dct)
assert self.datatypes is lib2

def test02_instance_data_read_access(self):
def test01_instance_data_read_access(self):
"""Read access to instance public data and verify values"""

import cppyy
Expand Down Expand Up @@ -110,7 +104,7 @@ def test02_instance_data_read_access(self):

c.__destruct__()

def test03_instance_data_write_access(self):
def test02_instance_data_write_access(self):
"""Test write access to instance public data and verify values"""

import cppyy
Expand Down Expand Up @@ -197,7 +191,7 @@ def test03_instance_data_write_access(self):

c.__destruct__()

def test04_array_passing(self):
def test03_array_passing(self):
"""Test passing of array arguments"""

import cppyy, array, sys
Expand Down Expand Up @@ -235,7 +229,7 @@ def test04_array_passing(self):

c.__destruct__()

def test05_class_read_access(self):
def test04_class_read_access(self):
"""Test read access to class public data and verify values"""

import cppyy, sys
Expand Down Expand Up @@ -276,7 +270,7 @@ def test05_class_read_access(self):

c.__destruct__()

def test06_class_data_write_access(self):
def test05_class_data_write_access(self):
"""Test write access to class public data and verify values"""

import cppyy, sys
Expand Down Expand Up @@ -340,7 +334,7 @@ def test06_class_data_write_access(self):

c.__destruct__()

def test07_range_access(self):
def test06_range_access(self):
"""Test the ranges of integer types"""

import cppyy, sys
Expand All @@ -356,7 +350,7 @@ def test07_range_access(self):

c.__destruct__()

def test08_type_conversions(self):
def test07_type_conversions(self):
"""Test conversions between builtin types"""

import cppyy, sys
Expand All @@ -374,7 +368,7 @@ def test08_type_conversions(self):

c.__destruct__()

def test09_global_builtin_type(self):
def test08_global_builtin_type(self):
"""Test access to a global builtin type"""

import cppyy
Expand All @@ -390,7 +384,7 @@ def test09_global_builtin_type(self):
assert gbl.get_global_int() == 22
assert gbl.g_int == 22

def test10_global_ptr(self):
def test09_global_ptr(self):
"""Test access of global objects through a pointer"""

import cppyy
Expand Down Expand Up @@ -421,7 +415,7 @@ def test10_global_ptr(self):
assert gbl.g_pod.m_int == 43
assert gbl.g_pod.m_double == 2.14

def test11_enum(self):
def test10_enum(self):
"""Test access to enums"""

import cppyy
Expand Down Expand Up @@ -469,7 +463,7 @@ def test11_enum(self):
assert gbl.kBanana == 29
assert gbl.kCitrus == 34

def test12_string_passing(self):
def test11_string_passing(self):
"""Test passing/returning of a const char*"""

import cppyy
Expand All @@ -479,7 +473,7 @@ def test12_string_passing(self):
assert c.get_valid_string('aap') == 'aap'
#assert c.get_invalid_string() == ''

def test13_copy_contructor(self):
def test12_copy_contructor(self):
"""Test copy constructor"""

import cppyy
Expand All @@ -495,7 +489,7 @@ def test13_copy_contructor(self):
for i in range(4):
assert t1[i] == t3[i]

def test14_object_returns(self):
def test13_object_returns(self):
"""Test access to and return of PODs"""

import cppyy
Expand All @@ -522,7 +516,7 @@ def test14_object_returns(self):
assert c.get_pod_ptrref().m_int == 666
assert c.get_pod_ptrref().m_double == 3.14

def test15_object_arguments(self):
def test14_object_arguments(self):
"""Test setting and returning of a POD through arguments"""

import cppyy
Expand Down Expand Up @@ -590,7 +584,7 @@ def test15_object_arguments(self):
assert p.m_int == 888
assert p.m_double == 3.14

def test16_nullptr_passing(self):
def test15_nullptr_passing(self):
"""Integer 0 ('NULL') and None allowed to pass through instance*"""

import cppyy
Expand All @@ -605,7 +599,7 @@ def test16_nullptr_passing(self):
assert not c.m_ppod
assert not c.get_pod_ptr()

def test17_respect_privacy(self):
def test16_respect_privacy(self):
"""Test that privacy settings are respected"""

import cppyy
Expand All @@ -618,7 +612,7 @@ def test17_respect_privacy(self):

c.__destruct__()

def test18_object_and_pointer_comparisons(self):
def test17_object_and_pointer_comparisons(self):
"""Verify object and pointer comparisons"""

import cppyy
Expand Down Expand Up @@ -655,7 +649,7 @@ def test18_object_and_pointer_comparisons(self):
assert l3 != l5
assert l5 != l3

def test19_object_validity(self):
def test18_object_validity(self):
"""Test object validity checking"""

from cppyy import gbl
Expand All @@ -669,7 +663,7 @@ def test19_object_validity(self):

assert not d2

def test20_buffer_reshaping(self):
def test19_buffer_reshaping(self):
"""Test usage of buffer sizing"""

import cppyy
Expand All @@ -690,7 +684,7 @@ def test20_buffer_reshaping(self):
for i in range(self.N):
assert arr[i] == l[i]

def test21_voidp(self):
def test20_voidp(self):
"""Test usage of void* data"""

import cppyy
Expand Down
18 changes: 8 additions & 10 deletions test/test_pythonify.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,16 @@ def test04_constructing_and_calling(self):
"""Test object and method calls."""
import cppyy
example01_class = cppyy.gbl.example01
#assert example01_class.getCount() == 0
assert example01_class.getCount() == 0
instance = example01_class(7)
#assert example01_class.getCount() == 1
assert example01_class.getCount() == 1
res = instance.addDataToInt(4)
return
assert res == 11
res = instance.addDataToInt(-4)
assert res == 3
instance.__destruct__()
assert example01_class.getCount() == 0
raises(ReferenceError, 'instance.addDataToInt(4)')
return

instance = example01_class(7)
instance2 = example01_class(8)
Expand All @@ -91,18 +89,17 @@ def test04_constructing_and_calling(self):
instance2.__destruct__()
assert example01_class.getCount() == 0

t = self.example01
instance = example01_class(13)
res = instance.addDataToDouble(16)
assert round(res-29, 8) == 0.
instance.__destruct__()
instance = example01_class(-13)
res = instance.addDataToDouble(16)
assert round(res-3, 8) == 0.
instance.__destruct__()


t = self.example01
instance = example01_class(42)
assert example01_class.getCount() == 1

res = instance.addDataToAtoi("13")
assert res == 55
Expand Down Expand Up @@ -322,16 +319,17 @@ def test15_installable_function(self):

cppyy.gbl.example01.fresh = cppyy.gbl.installableAddOneToInt

e = cppyy.gbl.example01(0)
e = cppyy.gbl.example01(0)
assert 2 == e.fresh(1)
assert 3 == e.fresh(2)


def test16_subclassing(self):
"""A sub-class on the python side should have that class as type"""

raise Exception("currently crashes ...")
import cppyy, gc
gc.collect()

import cppyy
example01 = cppyy.gbl.example01

assert example01.getCount() == 0
Expand Down

0 comments on commit f09dab9

Please sign in to comment.