forked from pybind/python_example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_foo.py
More file actions
29 lines (21 loc) · 708 Bytes
/
test_foo.py
File metadata and controls
29 lines (21 loc) · 708 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import python_example as m
def test_baz():
b = m.Baz()
assert len(b.ints) == 0
# Using std::vector<int> type caster, appending to b.ints fails to mutate b.ints
b.ints.append(42)
assert len(b.ints) == 1
def test_bar():
b = m.Bar()
assert len(b.foos) == 0
f = m.Foo()
f.x = 42
assert f.x == 42
# Using std::vector<Foo> bindings, appendings to b.foos correctly mutates b.foos
b.foos.append(f)
assert len(b.foos) == 1
assert b.foos[0].x == 42
# Mutating an element returned by a std::vector<Foo> succeeds with pybind11,
# but fail with nanobind (due to different default return policies)
b.foos[0].x = 100
assert b.foos[0].x == 100