Skip to content

Commit

Permalink
Rolling back PR pybind#2340 change to tests/test_pytypes.py (only thi…
Browse files Browse the repository at this point in the history
…s one file).

The two other files changed with PR pybind#2340 are not affected by this partial rollback.

This partial rollback enables cherry-picking a commit from PR pybind#2380.
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Aug 12, 2020
1 parent f83a24b commit 17bd8b1
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions tests/test_pytypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,29 +188,23 @@ def func(self, x, *args):

def test_constructors():
"""C++ default and converting constructors are equivalent to type calls in Python"""
types = [bytes, str, bool, int, float, tuple, list, dict, set]
types = [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",
"float": "+1e3",
"tuple": range(3),
"list": range(3),
"dict": [("two", 2), ("one", 1), ("three", 3)],
"set": [4, 4, 5, 6, 6, 6],
"memoryview": b'abc'
str: 42,
bool: "Not empty",
int: "42",
float: "+1e3",
tuple: range(3),
list: range(3),
dict: [("two", 2), ("one", 1), ("three", 3)],
set: [4, 4, 5, 6, 6, 6],
memoryview: b'abc'
}
inputs = {k: v for k, v in data.items()}
expected = {k: eval(k)(v) for k, v in data.items()}
inputs = {k.__name__: v for k, v in data.items()}
expected = {k.__name__: k(v) for k, v in data.items()}

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

0 comments on commit 17bd8b1

Please sign in to comment.