Skip to content

Commit

Permalink
Test for special cases for __repr__/__str__ returning C++ stringy types
Browse files Browse the repository at this point in the history
  • Loading branch information
wlav committed Mar 30, 2022
1 parent 7b412d1 commit 06ff59f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ master: 2.4.0
-------------

* Support for globally overloaded ordering operators
* Special cases for __repr__/__str__ returning C++ stringy types
* Fix lookup of templates of function with template args


Expand Down
36 changes: 36 additions & 0 deletions test/test_stltypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,42 @@ def EQ(result, init, methodname, *args):
assert s.rfind('c') < 0
assert s.rfind('c') == s.npos

def test10_string_in_repr_and_str_bytes(self):
"""Special cases for __str__/__repr__"""

import cppyy

cppyy.cppdef(r"""\
namespace ReprAndStr {
struct Test1 {
const char* __repr__() const { return "Test1"; }
const char* __str__() const { return "Test1"; }
};
struct Test2 {
std::string __repr__() const { return "Test2"; }
std::string __str__() const { return "Test2"; }
};
struct Test3 {
std::wstring __repr__() const { return L"Test3"; }
std::wstring __str__() const { return L"Test3"; }
};
}""")

ns = cppyy.gbl.ReprAndStr

assert str (ns.Test1()) == "Test1"
assert repr(ns.Test1()) == "Test1"

assert str (ns.Test2()) == "Test2"
assert repr(ns.Test2()) == "Test2"

assert str (ns.Test3()) == "Test3"
assert repr(ns.Test3()) == "Test3"


class TestSTLLIST:
def setup_class(cls):
cls.test_dct = test_dct
Expand Down

0 comments on commit 06ff59f

Please sign in to comment.