Skip to content

Commit f895483

Browse files
changes with updates printing policy
1 parent 2c2b128 commit f895483

File tree

6 files changed

+41
-21
lines changed

6 files changed

+41
-21
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: 6 additions & 6 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)' in Concrete.array_method.__doc__
257+
assert 'void Concrete::array_method(double * ad, int size)' in Concrete.array_method.__doc__
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,9 +698,9 @@ 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 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 cppyy.gbl.__dict__
704704

705705
assert mul[int] (1, 1) == 1
706706
assert 'multiply<int>' in cppyy.gbl.__dict__

test/test_fragile.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,11 @@ def test10_documentation(self):
193193
# likewise there are still minor differences in descriptiveness of messages
194194
assert "fragile::D::overload()" in str(e)
195195
assert "TypeError: takes at most 0 arguments (1 given)" in str(e)
196-
assert "fragile::D::overload(fragile::no_such_class*)" in str(e)
196+
assert "fragile::D::overload(fragile::no_such_class *)" in str(e)
197197
#assert "no converter available for 'fragile::no_such_class*'" in str(e)
198198
assert "void fragile::D::overload(char, int i = 0)" in str(e)
199199
#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)
200+
assert "void fragile::D::overload(int, fragile::no_such_class * p = 0)" in str(e)
201201
#assert "int/long conversion expects an integer object" in str(e)
202202

203203
j = fragile.J()
@@ -243,9 +243,9 @@ def test11_dir(self):
243243
244244
namespace Cppyy {
245245
246-
typedef size_t TCppScope_t;
246+
typedef void* TCppScope_t;
247247
248-
CPPYY_IMPORT TCppScope_t GetScope(const std::string& scope_name);
248+
CPPYY_IMPORT TCppScope_t GetScope(const std::string& scope_name, TCppScope_t parent_scope = nullptr);
249249
CPPYY_IMPORT void GetAllCppNames(TCppScope_t scope, std::set<std::string>& cppnames);
250250
251251
}""")
@@ -399,7 +399,7 @@ def test15_const_in_name(self):
399399
assert cppyy.gbl.myvar3
400400
assert cppyy.gbl.myvar4
401401

402-
@mark.xfail
402+
@mark.xfail(run=False, reason="Crashes sometimes; might have been caused by https://github.com/compiler-research/CPyCppyy/pull/109")
403403
def test16_opaque_handle(self):
404404
"""Support use of opaque handles"""
405405

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' # XXX: may need to custom printing instead of depending on clang (for default template args)
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)