Skip to content

Commit

Permalink
Adding test_constructors test for bytes, on top of cherry-picked comm…
Browse files Browse the repository at this point in the history
…it from PR pybind#2380.
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Aug 12, 2020
1 parent 86b421e commit 412c2a3
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/test_pytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,17 @@ def func(self, x, *args):

def test_constructors():
"""C++ default and converting constructors are equivalent to type calls in Python"""
types = [str, bool, int, float, tuple, list, dict, set]
types = [bytes, str, bool, int, float, tuple, list, dict, set]
expected = {t.__name__: t() for t in types}
if str is bytes: # Python 2.
# Note that bytes.__name__ == 'str' in Python 2.
# pybind11::str is unicode even under Python 2.
expected["bytes"] = bytes()
expected["str"] = u"" # flake8 complains about unicode().
assert m.default_constructors() == expected

data = {
bytes: b'41', # Currently no supported or working conversions.
str: 42,
bool: "Not empty",
int: "42",
Expand All @@ -209,7 +212,9 @@ def test_constructors():
inputs = {k.__name__: v for k, v in data.items()}
expected = {k.__name__: k(v) for k, v in data.items()}
if str is bytes: # Similar to the above. See comments above.
inputs["bytes"] = b'41'
inputs["str"] = 42
expected["bytes"] = b'41'
expected["str"] = u"42"

assert m.converting_constructors(inputs) == expected
Expand Down

0 comments on commit 412c2a3

Please sign in to comment.