Skip to content

Commit cc55e08

Browse files
committed
release: Fix some docs typos
1 parent c5ad450 commit cc55e08

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,20 @@ Easily iterate over all states:
175175
Or over events:
176176

177177
```py
178-
>>> [t.name for t in sm.events]
178+
>>> [t.id for t in sm.events]
179179
['cycle']
180180

181181
```
182182

183-
Call an event by its name:
183+
Call an event by its id:
184184

185185
```py
186186
>>> sm.cycle()
187187
Don't move.
188188
'Running cycle from yellow to red'
189189

190190
```
191-
Or send an event with the event name:
191+
Or send an event with the event id:
192192

193193
```py
194194
>>> sm.send('cycle')

docs/transitions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ True
192192

193193
```
194194

195-
```{versionadded} 2.6.7
195+
```{versionadded} 2.4.0
196196
You can also explict declare an {ref}`Event` instance, this helps IDEs to know that the event is callable and also with transtation strings.
197197
```
198198

tests/test_events.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ class StartMachine(StateMachine):
5353
created = State(initial=True)
5454
started = State(final=True)
5555

56-
start = Event(created.to(started), name="Launch the machine")
56+
start = Event(created.to(started), name="Start the machine")
5757

5858
assert [e.id for e in StartMachine.events] == ["start"]
59-
assert [e.name for e in StartMachine.events] == ["Launch the machine"]
60-
assert StartMachine.start.name == "Launch the machine"
59+
assert [e.name for e in StartMachine.events] == ["Start the machine"]
60+
assert StartMachine.start.name == "Start the machine"
6161

6262
def test_derive_name_from_id(self):
6363
class StartMachine(StateMachine):
@@ -66,9 +66,26 @@ class StartMachine(StateMachine):
6666

6767
launch_the_machine = Event(created.to(started))
6868

69+
assert list(StartMachine.events) == ["launch_the_machine"]
6970
assert [e.id for e in StartMachine.events] == ["launch_the_machine"]
7071
assert [e.name for e in StartMachine.events] == ["Launch the machine"]
7172
assert StartMachine.launch_the_machine.name == "Launch the machine"
73+
assert str(StartMachine.launch_the_machine) == "launch_the_machine"
74+
assert StartMachine.launch_the_machine == StartMachine.launch_the_machine.id
75+
76+
def test_not_derive_name_from_id_if_not_event_class(self):
77+
class StartMachine(StateMachine):
78+
created = State(initial=True)
79+
started = State(final=True)
80+
81+
launch_the_machine = created.to(started)
82+
83+
assert list(StartMachine.events) == ["launch_the_machine"]
84+
assert [e.id for e in StartMachine.events] == ["launch_the_machine"]
85+
assert [e.name for e in StartMachine.events] == ["launch_the_machine"]
86+
assert StartMachine.launch_the_machine.name == "launch_the_machine"
87+
assert str(StartMachine.launch_the_machine) == "launch_the_machine"
88+
assert StartMachine.launch_the_machine == StartMachine.launch_the_machine.id
7289

7390
def test_raise_invalid_definition_if_event_name_cannot_be_derived(self):
7491
with pytest.raises(InvalidDefinition, match="has no id"):

0 commit comments

Comments
 (0)