def test_serialization(self): """Test repr and from_string methods together.""" for s in self.SERIALIZATION_FIXTURES: self.assertEqual(repr(BattlegroundState.from_string(s)), s, 'Invalid deserialize & serialize transformation') for _ in range(10): state = BattlegroundStateFactory.build_with_creatures(9) s = repr(state) self.assertEqual(repr(BattlegroundState.from_string(s)), s, 'Invalid deserialize & serialize transformation')
def test_serialization(self): """Test repr and from_string methods together.""" for s in self.SERIALIZATION_FIXTURES: self.assertEqual(repr(BattlegroundState.from_string(s)), s, 'Invalid deserialize & serialize transformation') for _ in range(10): state = BattlegroundStateFactory.build_with_creatures(9) s = repr(state) self.assertEqual(repr(BattlegroundState.from_string(s)), s, 'Invalid deserialize & serialize transformation')
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() game_state = GameState() game_state._life1 = int(params['life1']) game_state._life2 = int(params['life2']) game_state.active_player = int(params['active_player']) game_state.phase = int(params['phase']) game_state.battleground = \ BattlegroundState.from_string(params['battleground']) return game_state
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() game_state = GameState() game_state._life1 = int(params['life1']) game_state._life2 = int(params['life2']) game_state.active_player = int(params['active_player']) game_state.phase = int(params['phase']) game_state.battleground = \ BattlegroundState.from_string(params['battleground']) return game_state