예제 #1
0
    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]}')
예제 #2
0
    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]}')
예제 #3
0
    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)
예제 #4
0
    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)
예제 #5
0
    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])
예제 #6
0
    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])