def test_serialization(self):
        for s in self.SERIALIZATION_FIXTURES:
            self.assertEqual(repr(CreatureState.from_string(s, 0)), s,
                             'Invalid deserialize & serialize transformation')

        for _ in range(5):
            cr = CreatureStateFactory(controlling_player=0)
            self.assertEqual(CreatureState.from_string(repr(cr), 0), cr)
    def from_string(cls, string):
        match = re.match(cls._FROM_STRING_PATTERN, string)
        if not match:
            raise ValueError('Invalid string: %r' % string)
        params = match.groupdict()

        battleground_state = BattlegroundState()
        for player in (0, 1):
            string = params['player%d_creatures' % player].strip()
            if not string:
                continue
            for creature_string in string.split(cls._CREATURE_SEPARATOR):
                creature_state = CreatureState.from_string(creature_string,
                                                           player)
                battleground_state.add_creature(creature_state)
        return battleground_state
Example #3
0
    def from_string(cls, string):
        match = re.match(cls._FROM_STRING_PATTERN, string)
        if not match:
            raise ValueError('Invalid string: %r' % string)
        params = match.groupdict()

        battleground_state = BattlegroundState()
        for player in (0, 1):
            string = params['player%d_creatures' % player].strip()
            if not string:
                continue
            for creature_string in string.split(cls._CREATURE_SEPARATOR):
                creature_state = CreatureState.from_string(
                    creature_string, player)
                battleground_state.add_creature(creature_state)
        return battleground_state