def test_winning_team(): data = { 'scores:Alpha': 10, 'scores:Bravo': 20, } r = Round(**data) assert r.alpha_scores == 10 assert r.bravo_scores == 20 assert r.winning_team == 'bravo' data = { 'scores:Alpha': 20, 'scores:Bravo': 10, } r = Round(**data) assert r.alpha_scores == 20 assert r.bravo_scores == 10 assert r.winning_team == 'alpha' data = { 'scores:Alpha': 10, 'scores:Bravo': 10, } r = Round(**data) assert r.alpha_scores == 10 assert r.bravo_scores == 10 assert r.winning_team is None assert r.tie is True
def test_players(): assert Round().num_players == 0 data = { 'kills_player:1': 20, 'kills_player:2': 10, } r = Round(**data) assert r.num_players == 2
def test_timings(): data = {'started': 10, 'finished': 20} r = Round(**data) assert r.duration == 10 data = {'started': 20, 'finished': 10} r = Round(**data) assert r.duration == 0
def test_empty(): data = {'started': 10, 'finished': 20} r = Round(**data) assert r.empty is True data = { 'scores:Alpha': 10, } r = Round(**data) assert r.empty is False
def get_last_rounds(self, startat=0, incr=20): ''' given pagination, get list of most recent Round objects ''' round_ids = self.r.zrevrange(self.keys.round_log, startat, startat + incr) for round_id in round_ids: round_data = self.r.hgetall(self.keys.round_hash(round_id)) if round_data: round_data['round_id'] = round_id yield Round(**round_data).resolve_players(self)
def get_round_by_id(self, round_id): ''' Given a round ID, get back a round object with all info on it, or None ''' round_id = int(round_id) data = self.r.hgetall(self.keys.round_hash(round_id)) data['round_id'] = round_id if data: return Round(**data)
def new_round(self, map, date, logfile): self.round_id += 1 self.old_logfile_rounds[logfile] = self.round_id self.last_logfile = logfile new_round = Round(round_id=self.round_id, map=map, started=date) self.round_log[self.round_id] = new_round return self.round_id
def test_simple_fields(): data = { 'round_id': 10, 'kills': 30, 'map': 'ctf_Ash', 'flags': 'yes', 'scores:Alpha': 10, 'scores:Bravo': 20, } r = Round(**data) assert r.id == 10 assert r.kills == 30 assert r.map == 'ctf_Ash' assert r.flagmatch is True
def test_round_recover(): logfile = 'consolelog1.txt' round_manager = FakeRoundManager(old_logfile_rounds={ logfile: Round(map='ctf_IceBeam', round_id=5) }) events = [ EventScore('Foobar', 'Alpha', 0), EventRestart(0), EventBareLog('IceBeam by Zakath, Suow, Poop', 0), EventScore('Foobar', 'Alpha', 0), ] map_titles = { 'ctf_IceBeam': 'IceBeam by Zakath, Suow, Poop', } assert list(decorate_events(events, map_titles=map_titles, round_manager=round_manager, logfile=logfile)) == [ DecoratedEvent(EventScore('Foobar', 'Alpha', 0), 'ctf_IceBeam', 5), DecoratedEvent(EventScore('Foobar', 'Alpha', 0), 'ctf_IceBeam', 6), ] assert round_manager.finalized_rounds == {5}
def get_round(self, _round): ''' given a round id, get a Round object ''' info = self.r.hgetall(self.keys.round_hash(_round)) if not info: return None return Round(round_id=_round, **info).resolve_players(self)
def test_broken_data(): data = { 'scores:Alpha': 'foobar', } r = Round(**data) assert r.alpha_scores == 0