forked from kljohann/genpybind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparameters_test.py
81 lines (60 loc) · 2.81 KB
/
parameters_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
74
75
76
77
78
79
80
81
# SPDX-FileCopyrightText: 2024 Johann Klähn <[email protected]>
#
# SPDX-License-Identifier: MIT
import parameters as m
import pytest
def test_parameter_names_are_part_of_signature():
assert (
"are: bool, part: int, of: int, the_signature: float"
in m.parameter_names.__doc__
)
assert ": bool, not_a: bool, : bool, problem: bool" in m.missing_names.__doc__
assert "also: bool, here: bool" in m.Example.__init__.__doc__
assert "it: bool, works: bool" in m.Example.method.__doc__
def test_keyword_arguments_can_be_used_in_call():
assert m.return_second(2, second=5) == 5
assert m.return_second(second=4, first=1) == 4
def test_cannot_pass_none_to_required_arguments():
valid = m.Example()
inst = m.TakesPointers()
for inst in [m, m.TakesPointers()]:
inst.accepts_none(None)
inst.accepts_none(valid)
inst.required(valid)
with pytest.raises(TypeError, match="incompatible function arguments"):
inst.required(None)
inst.required_second(valid, valid)
inst.required_second(None, valid)
with pytest.raises(TypeError, match="incompatible function arguments"):
inst.required_second(None, None)
inst.required_both(valid, valid)
with pytest.raises(TypeError, match="incompatible function arguments"):
inst.required_both(None, None)
with pytest.raises(TypeError, match="incompatible function arguments"):
inst.required_both(valid, None)
with pytest.raises(TypeError, match="incompatible function arguments"):
inst.required_both(None, valid)
def test_overloading_works():
for inst in [m, m.TakesDouble()]:
assert inst.overload_is_double(123) is False
assert inst.overload_is_double(1234.5) is True
def test_conversion_is_enabled_by_default():
for inst in [m, m.TakesDouble()]:
assert inst.normal(123) == 123.0
assert inst.normal(1234.5) == 1234.5
def test_noconvert_prevents_implicit_conversion():
for inst in [m, m.TakesDouble()]:
assert inst.noconvert(5.0) == 5.0
with pytest.raises(TypeError, match="incompatible function arguments"):
inst.noconvert(5)
assert inst.noconvert_second(5.0, 2.5) == 7.5
assert inst.noconvert_second(5, 2.5) == 7.5
with pytest.raises(TypeError, match="incompatible function arguments"):
inst.noconvert_second(5.5, 2)
assert inst.noconvert_both(5.0, 2.5) == 7.5
with pytest.raises(TypeError, match="incompatible function arguments"):
inst.noconvert_both(5, 2)
with pytest.raises(TypeError, match="incompatible function arguments"):
inst.noconvert_both(5, 2.5)
with pytest.raises(TypeError, match="incompatible function arguments"):
inst.noconvert_both(5.5, 2)