Skip to content

Commit 55935ae

Browse files
changes with updates printing policy
1 parent c48f958 commit 55935ae

File tree

6 files changed

+45
-24
lines changed

6 files changed

+45
-24
lines changed

python/cppyy/_typemap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,4 @@ def voidp_init(self, arg=0):
104104
import cppyy, ctypes
105105
if arg == cppyy.nullptr: arg = 0
106106
ctypes.c_void_p.__init__(self, arg)
107-
tm['void*'] = _create_mapper(ctypes.c_void_p, {'__init__' : voidp_init})
107+
tm['void *'] = _create_mapper(ctypes.c_void_p, {'__init__' : voidp_init})

test/test_doc_features.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class Abstract2 {
131131
132132
template<class A, class B, class C = A>
133133
C multiply(A a, B b) {
134-
return C{a*b};
134+
return static_cast<C>(a * b);
135135
}
136136
137137
//-----
@@ -253,8 +253,8 @@ def test_keyword_arguments(self):
253253
def test_doc_strings(self):
254254
import cppyy
255255
from cppyy.gbl import Concrete
256-
assert 'void Concrete::array_method(int* ad, int size)' in Concrete.array_method.__doc__
257-
assert 'void Concrete::array_method(double* ad, int size)' in Concrete.array_method.__doc__
256+
assert 'void Concrete::array_method(int * ad, int size)'.replace(" ", "") in Concrete.array_method.__doc__.replace(" ", "")
257+
assert 'void Concrete::array_method(double * ad, int size)'.replace(" ", "") in Concrete.array_method.__doc__.replace(" ", "")
258258

259259
def test_enums(self):
260260
import cppyy
@@ -682,7 +682,7 @@ def test08_shared_ptr(self):
682682
assert type(Zoo.free_lion).__name__ == 'Lion'
683683

684684
smart_lion = Zoo.free_lion.__smartptr__()
685-
assert type(smart_lion).__name__ in ['shared_ptr<Zoo::Lion>', 'std::shared_ptr<Zoo::Lion>']
685+
assert type(smart_lion).__name__ in ['shared_ptr<Zoo::Lion>', 'std::shared_ptr<Zoo::Lion>', 'shared_ptr<Lion>', 'std::shared_ptr<Lion>']
686686

687687
assert Zoo.identify_animal(Zoo.free_lion) == "the animal is a lion"
688688
assert Zoo.identify_animal_smart(Zoo.free_lion) == "the animal is a lion"
@@ -698,14 +698,14 @@ def test09_templated_function(self):
698698
assert 'multiply' in cppyy.gbl.__dict__
699699

700700
assert mul(1, 2) == 2
701-
assert 'multiply<int,int,int>' in cppyy.gbl.__dict__
701+
assert 'multiply<int,int,int>' in map(lambda x: x.replace(" ", ""), cppyy.gbl.__dict__)
702702
assert mul(1., 5) == 5.
703-
assert 'multiply<double,int,double>' in cppyy.gbl.__dict__
703+
assert 'multiply<double,int,double>' in map(lambda x: x.replace(" ", ""), cppyy.gbl.__dict__)
704704

705705
assert mul[int] (1, 1) == 1
706-
assert 'multiply<int>' in cppyy.gbl.__dict__
706+
assert 'multiply<int>' in map(lambda x: x.replace(" ", ""), cppyy.gbl.__dict__)
707707
assert mul[int, int](1, 1) == 1
708-
assert 'multiply<int,int>' in cppyy.gbl.__dict__
708+
assert 'multiply<int,int>' in map(lambda x: x.replace(" ", ""), cppyy.gbl.__dict__)
709709

710710
# make sure cached values are actually looked up
711711
old = getattr(cppyy.gbl, 'multiply<int,int>')

test/test_fragile.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,14 @@ def test10_documentation(self):
191191
except TypeError as e:
192192
# TODO: pypy-c does not indicate which argument failed to convert, CPython does
193193
# likewise there are still minor differences in descriptiveness of messages
194-
assert "fragile::D::overload()" in str(e)
194+
err_msg = str(e).replace(" ", "")
195+
assert "fragile::D::overload()" in err_msg
195196
assert "TypeError: takes at most 0 arguments (1 given)" in str(e)
196-
assert "fragile::D::overload(fragile::no_such_class*)" in str(e)
197+
assert "fragile::D::overload(fragile::no_such_class*)" in err_msg
197198
#assert "no converter available for 'fragile::no_such_class*'" in str(e)
198-
assert "void fragile::D::overload(char, int i = 0)" in str(e)
199+
assert "void fragile::D::overload(char, int i = 0)".replace(" ", "") in err_msg
199200
#assert "char or small int type expected" in str(e)
200-
assert "void fragile::D::overload(int, fragile::no_such_class* p = 0)" in str(e)
201+
assert "void fragile::D::overload(int, fragile::no_such_class * p = 0)".replace(" ", "") in err_msg
201202
#assert "int/long conversion expects an integer object" in str(e)
202203

203204
j = fragile.J()
@@ -243,9 +244,9 @@ def test11_dir(self):
243244
244245
namespace Cppyy {
245246
246-
typedef size_t TCppScope_t;
247+
typedef void* TCppScope_t;
247248
248-
CPPYY_IMPORT TCppScope_t GetScope(const std::string& scope_name);
249+
CPPYY_IMPORT TCppScope_t GetScope(const std::string& scope_name, TCppScope_t parent_scope = nullptr);
249250
CPPYY_IMPORT void GetAllCppNames(TCppScope_t scope, std::set<std::string>& cppnames);
250251
251252
}""")

test/test_pythonization.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,24 @@ def pythonizor(klass, name):
5555

5656
assert cppyy.gbl.pyzables.SomeDummy2.test == 3
5757

58+
cppyy.cppdef("""
59+
namespace pyzables {
60+
class TObjString {
61+
public:
62+
std::string s;
63+
TObjString(std::string ss) : s(ss) {}
64+
size_t Sizeof() { return s.size() + 1; }
65+
};
66+
}
67+
""")
68+
5869
def root_pythonizor(klass, name):
59-
if name == 'CppyyLegacy::TObjString':
70+
if name == 'pyzables::TObjString':
6071
klass.__len__ = klass.Sizeof
6172

6273
cppyy.py.add_pythonization(root_pythonizor)
6374

64-
assert len(cppyy.gbl.CppyyLegacy.TObjString("aap")) == 4 # include '\0'
75+
assert len(cppyy.gbl.pyzables.TObjString("aap")) == 4 # include '\0'
6576

6677
def test01_size_mapping(self):
6778
"""Use composites to map GetSize() onto buffer returns"""

test/test_regression.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,24 @@ def test02_dir(self):
5454

5555
import cppyy, pydoc
5656

57-
assert not '__abstractmethods__' in dir(cppyy.gbl.cling.runtime.gCling)
58-
assert '__class__' in dir(cppyy.gbl.cling.runtime.gCling)
57+
cppyy.cppdef("""
58+
namespace docs {
59+
struct MyDocs {
60+
void fn() {}
61+
} s;
62+
MyDocs *ptrDocs = &s;
63+
}
64+
""")
65+
66+
assert not '__abstractmethods__' in dir(cppyy.gbl.docs.ptrDocs)
67+
assert '__class__' in dir(cppyy.gbl.docs.ptrDocs)
5968

6069
self.__class__.helpout = []
61-
pydoc.doc(cppyy.gbl.cling.runtime.gCling)
70+
pydoc.doc(cppyy.gbl.docs.ptrDocs)
6271
helptext = ''.join(self.__class__.helpout)
63-
assert 'TInterpreter' in helptext
72+
assert 'MyDocs' in helptext
6473
assert 'CPPInstance' in helptext
65-
assert 'AddIncludePath' in helptext
74+
assert 'fn' in helptext
6675

6776
cppyy.cppdef("namespace cppyy_regression_test { void iii() {}; }")
6877

test/test_templates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1190,13 +1190,13 @@ def test01_using(self):
11901190
assert 'in_type' in dir(tct[int, dum, 4])
11911191

11921192
assert in_type.__name__ == 'in_type'
1193-
assert in_type.__cpp_name__ == 'TemplatedTypedefs::DerivedWithUsing<int,TemplatedTypedefs::SomeDummy,4>::in_type'
1193+
assert in_type.__cpp_name__ == 'TemplatedTypedefs::DerivedWithUsing<int, TemplatedTypedefs::SomeDummy, 4>::in_type'
11941194

11951195
in_type_tt = tct[int, dum, 4].in_type_tt
11961196
assert 'in_type_tt' in dir(tct[int, dum, 4])
11971197

11981198
assert in_type_tt.__name__ == 'in_type_tt'
1199-
assert in_type_tt.__cpp_name__ == 'TemplatedTypedefs::DerivedWithUsing<int,TemplatedTypedefs::SomeDummy,4>::in_type_tt'
1199+
assert in_type_tt.__cpp_name__ == 'TemplatedTypedefs::DerivedWithUsing<int, TemplatedTypedefs::SomeDummy, 4>::in_type_tt'
12001200

12011201
@mark.xfail
12021202
def test02_mapped_type_as_internal(self):

0 commit comments

Comments
 (0)