def test_bet_new_player(self): tim = timba.timba() # id 666 isn't in data minqlx_fake.countdown_game() new_player = minqlx_fake.Player(666, '*Cthugha*') minqlx_fake.call_command('!timba blue 1000', new_player) self.assertEqual({666: make_bet('blue', 1000)}, tim.get_current_bets())
def test_handles_player_loaded(self): olor = oloraculo.oloraculo() self.assertEqual(set(), olor.get_stats().get_player_ids('ad')) player = minqlx_fake.Player(123456, 'sarge') minqlx_fake.load_player(player) self.assertEqual({123456}, olor.get_stats().get_player_ids('ad')) self.assertEqual([0, 0], olor.get_stats().get_winloss('ad', 123456)) self.assertEqual([0, 0], olor.get_stats().get_killdeath('ad', 123456))
def test_bets_one_winner(self): tim = timba.timba() minqlx_fake.countdown_game() new_player = minqlx_fake.Player(666, '*Cthugha*') minqlx_fake.Plugin.players_list.append(new_player) minqlx_fake.call_command('!timba blue 1000', PLAYER_ID_MAP[10]) minqlx_fake.call_command('!timba r 200', PLAYER_ID_MAP[11]) minqlx_fake.call_command('!timba 4000 red', new_player) # blue won. pot is 5200 self.run_game([10, 11], [12, 13], 7, 15) self.assertEqual({10: 5200, 11: 1800, 666: 1000}, tim.get_credits())
def test_handles_game_end(self): tim = timba.timba() minqlx_fake.countdown_game() new_player = minqlx_fake.Player(666, '*Cthugha*') minqlx_fake.Plugin.players_list.append(new_player) minqlx_fake.call_command('!timba blue 1000', PLAYER_ID_MAP[10]) minqlx_fake.call_command('!timba red 200', PLAYER_ID_MAP[11]) minqlx_fake.call_command('!timba blue 10', PLAYER_ID_MAP[12]) minqlx_fake.call_command('!timba red 5000', PLAYER_ID_MAP[13]) minqlx_fake.call_command('!timba red 4000', new_player) # blue won self.run_game([10, 11], [12, 13], 7, 15) self.assertInMessages('cthulhu : 1000 on blue') self.assertInMessages('nyarlathotep : 10 on blue') self.assertInMessages('shub niggurath : -200 on red') self.assertInMessages('zoth-ommog : -5000 on red') self.assertInMessages('cthugha : -4000 on red')
import minqlx_fake import sys import unittest from unittest.mock import mock_open from unittest.mock import patch from unittest.mock import MagicMock sys.modules['minqlx'] = minqlx_fake import lagparatodos PLAYER_ID_MAP = { 10: minqlx_fake.Player(10, ']v[ - cthulhu', ip='1.2.3.4', ping=666), 11: minqlx_fake.Player(11, '==shub niggurath==', ip='1.2.3.5', ping=10), 12: minqlx_fake.Player(12, 'Nyarlathotep', ip='1.2.3.6', ping=1000), 13: minqlx_fake.Player(13, 'Zoth-Ommog', ip='1.2.3.7', ping=0), } class TestLagParaTodos(unittest.TestCase): def setUp(self): minqlx_fake.reset() # add ips and pings def assertMessages(self, txt): self.assertInMessages(txt) self.assertEqual(1, len(minqlx_fake.Plugin.messages)) def assertInMessages(self, txt): self.assertTrue( [line for line in minqlx_fake.Plugin.messages if txt in line],
import copy import datetime import json import minqlx_fake import sys import unittest from unittest.mock import mock_open from unittest.mock import patch from unittest.mock import MagicMock sys.modules['minqlx'] = minqlx_fake import timba PLAYER_ID_MAP = { 10: minqlx_fake.Player(10, ']v[ - cthulhu'), 11: minqlx_fake.Player(11, '==shub niggurath=='), 12: minqlx_fake.Player(12, 'Nyarlathotep'), 13: minqlx_fake.Player(13, 'Zoth-Ommog'), } CREDITS_DATA = {10: 1000, 11: 2000} CREDITS_JSON = json.dumps(CREDITS_DATA) def make_bet(team, amount): return {'team': team, 'amount': amount} class TestTimba(unittest.TestCase): fake_time = 1000
def test_loads_stats_invalid_json(self): olor = oloraculo.oloraculo() self.assertEqual(set(), olor.get_stats().get_player_ids('ad')) # still usable minqlx_fake.load_player(minqlx_fake.Player(123456, 'sarge')) self.assertEqual({123456}, olor.get_stats().get_player_ids('ad'))
sys.modules['trueskill'] = trueskill_fake import oloraculo # {type:{id:[mu,sigma,w,l,k,d],...},...} RATINGS = { 'ad': { 12: [1, 0, 2, 1, 200, 100], 34: [2, 0, 1, 4, 100, 900], 56: [3, 0, 3, 2, 300, 200], 78: [4, 0, 1, 8, 100, 900], }, } RATINGS_JSON = json.dumps(RATINGS) PLAYER_ID_MAP = { 12: minqlx_fake.Player(12, 'john'), 34: minqlx_fake.Player(34, 'paul'), 56: minqlx_fake.Player(56, 'george'), 78: minqlx_fake.Player(78, 'ringo'), } class TestOloraculo(unittest.TestCase): def setUp(self): minqlx_fake.reset() def assertSavedJson(self, expected, mocked_open): file_handle = mocked_open.return_value.__enter__.return_value first_write = file_handle.write.call_args_list[0] write_arguments = first_write[0]
import copy import datetime import json import minqlx_fake import sys import unittest from unittest.mock import mock_open from unittest.mock import patch from unittest.mock import MagicMock sys.modules['minqlx'] = minqlx_fake import funes PLAYER_ID_MAP = { 10: minqlx_fake.Player(10, ']v[ - mandiok'), 11: minqlx_fake.Player(11, 'fundi!'), 12: minqlx_fake.Player(12, '==toro=='), 13: minqlx_fake.Player(13, 'p-lu-k'), 14: minqlx_fake.Player(14, 'Renga'), 15: minqlx_fake.Player(15, 'coco'), 16: minqlx_fake.Player(16, ']v[ - blues'), 17: minqlx_fake.Player(17, 'juanpi'), 90: minqlx_fake.Player(90, '...cthulhu...'), } HISTORY_DATA = [ ['2018-10', 'ad', [10, 11, 12], [13, 14, 15], 17, 16], ['2018-10', 'ad', [11, 13, 14], [10, 12, 15], 15, 8], ['2018-10', 'ad', [10, 12, 15], [11, 13, 14], 15, 8], ['2018-10', 'ad', [10, 12, 15], [11, 13, 14], 15, 12],