forked from kljohann/genpybind-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariables_test.py
73 lines (61 loc) · 2.39 KB
/
variables_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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import pytest
import pyvariables as m
TAGDECLS = [m.SomeStruct, m.SomeClass]
@pytest.mark.parametrize("tagdecl", TAGDECLS)
def test_static_field(tagdecl):
assert tagdecl.static_field == 1
tagdecl.static_field = -1
assert tagdecl.static_field == -1
@pytest.mark.parametrize("tagdecl", TAGDECLS)
def test_static_const_field(tagdecl):
assert tagdecl.static_const_field == 2
with pytest.raises(AttributeError, match="can't set attribute"):
tagdecl.static_const_field = -1
@pytest.mark.parametrize("tagdecl", TAGDECLS)
def test_static_constexpr_field(tagdecl):
assert tagdecl.static_constexpr_field == 3
with pytest.raises(AttributeError, match="can't set attribute"):
tagdecl.static_constexpr_field = -1
@pytest.mark.parametrize("tagdecl", TAGDECLS)
def test_static_readonly_field(tagdecl):
assert tagdecl.static_readonly_field == 4
with pytest.raises(AttributeError, match="can't set attribute"):
tagdecl.static_readonly_field = -1
@pytest.mark.parametrize("tagdecl", TAGDECLS)
def test_static_writable_false_field(tagdecl):
assert tagdecl.static_writable_false_field == 5
with pytest.raises(AttributeError, match="can't set attribute"):
tagdecl.static_writable_false_field = -1
@pytest.mark.parametrize("tagdecl", TAGDECLS)
def test_field(tagdecl):
obj = tagdecl()
assert obj.field == 1
obj.field = -1
assert obj.field == -1
@pytest.mark.parametrize("tagdecl", TAGDECLS)
def test_const_field(tagdecl):
obj = tagdecl()
assert obj.const_field == 2
with pytest.raises(AttributeError, match="can't set attribute"):
obj.const_field = -1
@pytest.mark.parametrize("tagdecl", TAGDECLS)
def test_readonly_field(tagdecl):
obj = tagdecl()
assert obj.readonly_field == 4
with pytest.raises(AttributeError, match="can't set attribute"):
obj.readonly_field = -1
@pytest.mark.parametrize("tagdecl", TAGDECLS)
def test_writable_false_field(tagdecl):
obj = tagdecl()
assert obj.writable_false_field == 5
with pytest.raises(AttributeError, match="can't set attribute"):
obj.writable_false_field = -1
def test_global_variables():
assert m.var == 1
m.var = -1
assert m.var == -1
assert m.const_var == 2
@pytest.mark.xfail(reason="not enforceable")
def test_global_const_variable_is_readonly():
with pytest.raises(AttributeError, match="can't set attribute"):
m.const_var = -1