test_verify.py (666B)
1 # standard imports 2 import unittest 3 4 # local imports 5 from shep import State 6 from shep.error import ( 7 StateTransitionInvalid, 8 ) 9 10 11 def mock_verify(state, key, from_state, to_state): 12 if from_state == state.FOO: 13 if to_state == state.BAR: 14 return 'bar cannot follow foo' 15 16 17 class TestState(unittest.TestCase): 18 19 def test_verify(self): 20 states = State(2, verifier=mock_verify) 21 states.add('foo') 22 states.add('bar') 23 states.put('xyzzy') 24 states.next('xyzzy') 25 with self.assertRaises(StateTransitionInvalid): 26 states.next('xyzzy') 27 28 29 30 if __name__ == '__main__': 31 unittest.main()