-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'maintenance/assert-in-test'
- Loading branch information
Showing
7 changed files
with
111 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,71 @@ | ||
import unittest | ||
|
||
from magicbus.base import Graph | ||
|
||
|
||
class GraphTests(unittest.TestCase): | ||
# EXIT_ERROR | ||
# | | ||
# V | ||
# START -----------> EXIT ------> EXITED | ||
# / | A / A | ||
# V | \ / | | ||
# START_ERROR RUN | IDLE STOP_ERROR | ||
# | \ | A | ||
# | V V / | ||
# +----------------> STOP | ||
TRANSITIONS = { | ||
'START': ('RUN', 'STOP', 'EXIT'), | ||
'RUN': 'STOP', | ||
'START_ERROR': 'STOP', | ||
'STOP': 'IDLE', | ||
'IDLE': ('START', 'EXIT'), | ||
'STOP_ERROR': 'EXIT', | ||
'EXIT': 'EXITED', | ||
'EXIT_ERROR': 'EXITED', | ||
} | ||
|
||
|
||
NEXT = { | ||
('EXIT', 'EXITED'): 'EXITED', | ||
('EXIT_ERROR', 'EXITED'): 'EXITED', | ||
('IDLE', 'EXITED'): 'EXIT', | ||
('IDLE', 'EXIT'): 'EXIT', | ||
('IDLE', 'RUN'): 'START', | ||
('IDLE', 'START'): 'START', | ||
('IDLE', 'STOP'): 'START', | ||
('RUN', 'EXITED'): 'STOP', | ||
('RUN', 'EXIT'): 'STOP', | ||
('RUN', 'IDLE'): 'STOP', | ||
('RUN', 'START'): 'STOP', | ||
('RUN', 'STOP'): 'STOP', | ||
('START', 'EXITED'): 'EXIT', | ||
('START', 'EXIT'): 'EXIT', | ||
('START', 'IDLE'): 'STOP', | ||
('START', 'RUN'): 'RUN', | ||
('START', 'STOP'): 'STOP', | ||
('START_ERROR', 'EXITED'): 'STOP', | ||
('START_ERROR', 'EXIT'): 'STOP', | ||
('START_ERROR', 'IDLE'): 'STOP', | ||
('START_ERROR', 'RUN'): 'STOP', | ||
('START_ERROR', 'START'): 'STOP', | ||
('START_ERROR', 'STOP'): 'STOP', | ||
('STOP', 'EXITED'): 'IDLE', | ||
('STOP', 'EXIT'): 'IDLE', | ||
('STOP', 'IDLE'): 'IDLE', | ||
('STOP', 'RUN'): 'IDLE', | ||
('STOP', 'START'): 'IDLE', | ||
('STOP_ERROR', 'EXITED'): 'EXIT', | ||
('STOP_ERROR', 'EXIT'): 'EXIT', | ||
} | ||
|
||
maxDiff = None | ||
|
||
# EXIT_ERROR | ||
# | | ||
# V | ||
# START -----------> EXIT ------> EXITED | ||
# / | A / A | ||
# V | \ / | | ||
# START_ERROR RUN | IDLE STOP_ERROR | ||
# | \ | A | ||
# | V V / | ||
# +----------------> STOP | ||
transitions = { | ||
'START': ('RUN', 'STOP', 'EXIT'), | ||
'RUN': 'STOP', | ||
'START_ERROR': 'STOP', | ||
'STOP': 'IDLE', | ||
'IDLE': ('START', 'EXIT'), | ||
'STOP_ERROR': 'EXIT', | ||
'EXIT': 'EXITED', | ||
'EXIT_ERROR': 'EXITED', | ||
} | ||
STATES = set(['START', 'RUN', 'STOP', 'IDLE', 'EXIT', 'EXITED', | ||
'START_ERROR', 'STOP_ERROR', 'EXIT_ERROR']) | ||
|
||
next = { | ||
('EXIT', 'EXITED'): 'EXITED', | ||
('EXIT_ERROR', 'EXITED'): 'EXITED', | ||
('IDLE', 'EXITED'): 'EXIT', | ||
('IDLE', 'EXIT'): 'EXIT', | ||
('IDLE', 'RUN'): 'START', | ||
('IDLE', 'START'): 'START', | ||
('IDLE', 'STOP'): 'START', | ||
('RUN', 'EXITED'): 'STOP', | ||
('RUN', 'EXIT'): 'STOP', | ||
('RUN', 'IDLE'): 'STOP', | ||
('RUN', 'START'): 'STOP', | ||
('RUN', 'STOP'): 'STOP', | ||
('START', 'EXITED'): 'EXIT', | ||
('START', 'EXIT'): 'EXIT', | ||
('START', 'IDLE'): 'STOP', | ||
('START', 'RUN'): 'RUN', | ||
('START', 'STOP'): 'STOP', | ||
('START_ERROR', 'EXITED'): 'STOP', | ||
('START_ERROR', 'EXIT'): 'STOP', | ||
('START_ERROR', 'IDLE'): 'STOP', | ||
('START_ERROR', 'RUN'): 'STOP', | ||
('START_ERROR', 'START'): 'STOP', | ||
('START_ERROR', 'STOP'): 'STOP', | ||
('STOP', 'EXITED'): 'IDLE', | ||
('STOP', 'EXIT'): 'IDLE', | ||
('STOP', 'IDLE'): 'IDLE', | ||
('STOP', 'RUN'): 'IDLE', | ||
('STOP', 'START'): 'IDLE', | ||
('STOP_ERROR', 'EXITED'): 'EXIT', | ||
('STOP_ERROR', 'EXIT'): 'EXIT', | ||
} | ||
|
||
states = set(['START', 'RUN', 'STOP', 'IDLE', 'EXIT', 'EXITED', | ||
'START_ERROR', 'STOP_ERROR', 'EXIT_ERROR']) | ||
def test_shortest_path(): | ||
g = Graph.from_edges(TRANSITIONS) | ||
assert g == NEXT | ||
|
||
def test_shortest_path(self): | ||
g = Graph.from_edges(self.transitions) | ||
self.assertEqual(g, self.next) | ||
|
||
def test_states(self): | ||
g = Graph(self.next) | ||
self.assertEqual(g.states, self.states) | ||
def test_states(): | ||
g = Graph(NEXT) | ||
assert g.states == STATES |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.