-
-
Notifications
You must be signed in to change notification settings - Fork 265
Expand file tree
/
Copy pathtest_events.py
More file actions
57 lines (40 loc) · 1.54 KB
/
Copy pathtest_events.py
File metadata and controls
57 lines (40 loc) · 1.54 KB
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
import pytest
from rocketpy.simulation.events import Event
def test_verify_trigger_accepts_only_kwargs():
def trigger(**kwargs) -> bool:
return True
def action(**kwargs):
return None
event = Event(trigger=trigger, action=action, name="test")
assert event.trigger is trigger
def test_verify_trigger_rejects_missing_kwargs():
def trigger(a, b) -> bool:
return True
def action(**kwargs):
return None
with pytest.raises(
ValueError,
match=r"The Trigger function of the test event must accept only keyword arguments. def trigger\(\*\*kwargs\) -> bool:",
):
Event(trigger=trigger, action=action, name="test")
def test_verify_trigger_rejects_args_with_kwargs():
def trigger(a, b, **kwargs) -> bool:
return True
def action(**kwargs):
return None
with pytest.raises(
ValueError,
match=r"The Trigger function of the test event must accept only keyword arguments. def trigger\(\*\*kwargs\) -> bool:",
):
Event(trigger=trigger, action=action, name="test")
def test_verify_trigger_rejects_triggers_without_bool_return_annotation():
def trigger(**kwargs):
return True
def action(**kwargs):
return None
with pytest.raises(
ValueError,
match="The Trigger function of the test event must return a boolean value and must be annotated with '-> bool' for type checking.\n"
+ r"def trigger\(\*\*kwargs\) -> bool\:",
):
Event(trigger=trigger, action=action, name="test")