forked from kljohann/genpybind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproperties_test.py
53 lines (44 loc) · 1.36 KB
/
properties_test.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# SPDX-FileCopyrightText: 2024 Johann Klähn <[email protected]>
#
# SPDX-License-Identifier: MIT
import properties as m
import pytest
def test_regular_property():
inst = m.Example()
assert not hasattr(inst, "getValue")
assert not hasattr(inst, "setValue")
assert inst.value == 0
inst.value = 5
assert inst.value == 5
assert inst.value_ == 5
def test_readonly_property():
inst = m.Example()
assert not hasattr(inst, "getReadonly")
assert inst.readonly is True
with pytest.raises(AttributeError, match="can't set attribute|has no setter"):
inst.readonly = False
@pytest.mark.xfail(reason="default argument cannot be propagated to pybind11")
def test_same_method_for_both():
inst = m.Example()
assert not hasattr(inst, "strange")
assert inst.combined == 0
inst.combined = 4
assert inst.combined == 4
assert inst.combined_ == 4
def test_multiple_names():
inst = m.Example()
assert not hasattr(inst, "getMulti")
assert not hasattr(inst, "setMulti")
assert inst.multi_1 == 0
assert inst.multi_2 == 0
inst.multi_1 = 1
assert inst.multi_1 == 1
assert inst.multi_2 == 1
assert inst.multi_ == 1
inst.multi_2 = 2
assert inst.multi_1 == 2
assert inst.multi_2 == 2
assert inst.multi_ == 2
inst.multi_ = 3
assert inst.multi_1 == 3
assert inst.multi_2 == 3