| import unittest |
| from baim.actions import Action, Kind, Decision |
| from baim.authority import Authority, Rejected |
| from baim.state import State |
|
|
|
|
| class ActionTests(unittest.TestCase): |
| def test_round_trip_escaping(self): |
| action = Action(Kind.TYPE, ('e1', 'quotes " newline\nUnicode नमस्ते')) |
| self.assertEqual(Action.parse(action.encode()), action) |
|
|
| def test_reject_bad_wire(self): |
| for wire in ['C["e1", "extra"]', 'Q[]', 'W[true]', 'W[-1]', 'W[2001]', |
| 'F{}', 'T["e1"]', 'C["e1"] trailing', 'S[0,99999]']: |
| with self.subTest(wire=wire), self.assertRaises(ValueError): |
| Action.parse(wire) |
|
|
| def test_task_replacement_and_replay(self): |
| authority = Authority() |
| authority.replace('First') |
| state = State('doc', 1, 'http://localhost', ()) |
| ticket = authority.ticket(state) |
| authority.consume() |
| with self.assertRaises(Rejected): |
| authority.validate(ticket, state) |
| ticket = authority.ticket(state) |
| authority.replace('Second') |
| with self.assertRaises(Rejected): |
| authority.validate(ticket, state) |
|
|
| def test_confidence_is_not_fabricated(self): |
| self.assertIsNone(Decision(None, Action(Kind.FINISH)).action_confidence) |
| with self.assertRaises(ValueError): |
| Decision(None, Action(Kind.FINISH), float('nan')) |
|
|