def test_from_json_bad_action(self): """Raises ParsingError if the valid JSON doesn't represent a valid GameAction. """ with self.assertRaises(GameActionError): a = GameAction.from_json('{"action": -1, "args": [true]}') with self.assertRaises(GameActionError): a = GameAction.from_json('{"action": 0, "args": []}') with self.assertRaises(GameActionError): a = GameAction.from_json('{"action": 0, "args": [true, false]}')
def test_from_bad_json(self): """Failure to convert bad JSON raises ValueError. """ a_json = '{"act]]]}' # not valid JSON with self.assertRaises(ParsingError): a = GameAction.from_json(a_json)
def test_from_json(self): """Convert JSON dictionary to GameAction. """ a_json = '{"action": 0, "args": [true]}' a = GameAction.from_json(a_json) self.assertEqual(a.action, message.THINKERORLEAD) self.assertEqual(a.args, [True])