Esempio n. 1
0
 def test_irc_game(self):
     config = Config().data
     game = Game()
     bob = Player('Bob', '~bobbo')
     jim = Player('Jim', '~jimbo')
     joe = Player('Joe', '~joebo')
     cahirc.Cahirc.say.reset_mock()
     self.assertEqual([], cahirc.Cahirc.say.mock_calls)
     p = CmdParser(game)
     msg = FakeIRCmsg('start', user=bob)
     p.parse(msg)
     game.command(p)
     self.assertEqual(2, len(cahirc.Cahirc.say.mock_calls))
     msg = FakeIRCmsg('join', user=jim)
     p.parse(msg)
     game.command(p)
     self.assertEqual(3, len(cahirc.Cahirc.say.mock_calls))
     msg = FakeIRCmsg('join', user=joe)
     p.parse(msg)
     game.command(p)
     self.assertTrue(
         re.search(config['text']['en']['round_start'],
                   str(cahirc.Cahirc.say.mock_calls[0])))
     round_annc = config['text']['en']['round_announcement'].format(
         round_num=1, czar='Bob')
     round_call = call(round_annc)
     self.assertEqual(str(round_call), str(cahirc.Cahirc.say.mock_calls[4]))
Esempio n. 2
0
 def test_player_start_cant_join(self):
     game = Game()
     p = CmdParser(game)
     bob = Player('Bob', '~bobbo')
     msg = FakeIRCmsg('start')
     p.parse(msg)
     game.command(p)
     msg = FakeIRCmsg('join')
     p.parse(msg)
     game.command(p)
     self.assertEqual(1, len(game.players))
Esempio n. 3
0
 def test_game_join_joining_works(self):
     game = Game()
     bob = Player('Bob', '~bobbo')
     p = CmdParser(game)
     msg = FakeIRCmsg('start')
     p.parse(msg)
     game.command(p)
     jim = Player('Jim', '~bobbo')
     msg = FakeIRCmsg('join', user=jim)
     p.parse(msg)
     game.command(p)
     self.assertEqual([str(bob), str(jim)], [str(p) for p in game.players])
Esempio n. 4
0
 def test_cards_command_works_with_no_cards(self):
     game = Game()
     bob = Player('Bob', '~bobbo')
     p = CmdParser(game)
     msg = FakeIRCmsg('start')
     p.parse(msg)
     game.command(p)
     msg = FakeIRCmsg('cards')
     p.parse(msg)
     game.command(p)
     self.assertEqual(call("Game hasn't started yet"),
                      cahirc.Cahirc.say.mock_calls[-1])
Esempio n. 5
0
 def test_status_wait_players(self):
     text = self.config['text']['en']['status']['wait_players']
     text = text.format(num=2)
     expected = call(text)
     game = Game()
     p = CmdParser(game)
     msg = FakeIRCmsg('start')
     p.parse(msg)
     game.command(p)
     msg = FakeIRCmsg('status')
     p.parse(msg)
     game.command(p)
     self.assertEqual(expected, cahirc.Cahirc.say.mock_calls[-1])
Esempio n. 6
0
 def test_double_join_complains(self):
     cahirc.Cahirc.say.reset_mock()
     game = Game()
     p = CmdParser(game)
     msg = FakeIRCmsg('start')
     p.parse(msg)
     game.command(p)
     msg = FakeIRCmsg('join')
     p.parse(msg)
     game.command(p)
     config = Config()
     self.assertTrue(
         re.search(config.data['text']['en']['double_join'],
                   str(cahirc.Cahirc.say.mock_calls[-1])))
Esempio n. 7
0
 def test_status_in_private(self):
     config = Config().data
     game = start_game()
     player1 = game.players[1]
     player2 = game.players[2]
     p = CmdParser(game)
     msg = FakeIRCmsg('play 1', user=player1)
     p.parse(msg)
     game.command(p)
     msg = FakeIRCmsg('status', user=player2, source='privmsg')
     p.parse(msg)
     game.command(p)
     question = game.question.formattedvalue
     players = gameclass.playerlist_format([player2.nick])
     self.assertEqual(player2.nick, game.irc.destination)
Esempio n. 8
0
 def test_pick_alias_ignored_before_game_start(self):
     bob = Player('Bob', '~bobbo')
     msg = FakeIRCmsg('pick 1', user=bob)
     self.p.parse(msg)
     self.game.command(self.p)
     text = Config().data['text']['en']
     self.assertEqual(0, len(cahirc.Cahirc.say.mock_calls))
Esempio n. 9
0
 def test_pick_works_as_winner(self):
     self.game.status = 'wait_czar'
     cmdstring = 'pick 1'
     msg = FakeIRCmsg(cmdstring)
     self.p.parse(msg)
     self.assertEqual('winner', self.p.command)
     self.assertEqual([1], self.p.args)
Esempio n. 10
0
 def test_pick_works_as_play(self):
     self.game.status = 'wait_answers'
     cmdstring = 'pick 1'
     msg = FakeIRCmsg(cmdstring)
     self.p.parse(msg)
     self.assertEqual('play', self.p.command)
     self.assertEqual([1], self.p.args)
Esempio n. 11
0
 def test_commander_runs_start_command(self):
     game = Game()
     msg = FakeIRCmsg('start')  # bob is the default player
     p = CmdParser(game)
     p.parse(msg)
     game.command(p)
     self.assertEqual('wait_players', game.status)
Esempio n. 12
0
 def test_status_wait_answers(self):
     bob = Player('Bob', '~bobbo')
     jim = Player('Jim', '~jimbo')
     joe = Player('Joe', '~joebo')
     game = Game()
     game.start()  #status should how be wait_answers
     game.add_player(bob)
     game.add_player(jim)
     game.add_player(joe)
     p = CmdParser(game)
     msg = FakeIRCmsg('play 1', user=jim)
     p.parse(msg)
     game.command(p)
     question = game.question.formattedvalue
     players = gameclass.playerlist_format([joe.nick])
     text = self.config['text']['en']['status']['wait_answers']
     text = text.format(players=players, question=question)
     expected = call(text)
     game.state(bob, [])
     self.assertEqual(
         str(expected),
         str(cahirc.Cahirc.say.mock_calls[-1]),
         msg=
         'This test fails regularly since the order of the player list is not deterministic'
     )
Esempio n. 13
0
 def test_status_command_does_anything(self):
     game = Game()
     p = CmdParser(game)
     msg = FakeIRCmsg('status')
     p.parse(msg)
     game.command(p)
     self.assertNotEqual([], cahirc.Cahirc.say.mock_calls)
Esempio n. 14
0
 def test_game_start_joining_works(self):
     game = Game()
     bob = Player('Bob', '~bobbo')
     p = CmdParser(game)
     msg = FakeIRCmsg('start')
     p.parse(msg)
     game.command(p)
     self.assertEqual(str(bob), str(game.players[0]))
Esempio n. 15
0
 def test_player_starts_and_is_registered(self):
     game = Game()
     bob = Player('Bob', '~bobbo')
     msg = FakeIRCmsg('start')
     p = CmdParser(game)
     p.parse(msg)
     game.command(p)
     self.assertEqual(str(bob), str(game.players[0]))
Esempio n. 16
0
 def test_shame_works_as_score(self):
     cmdstring = 'shame'
     msg = FakeIRCmsg(cmdstring)
     self.p.parse(msg)
     self.assertEqual('score', self.p.command)
     self.game.status = 'wait_czar'
     self.p.parse(msg)
     self.assertEqual('score', self.p.command)
Esempio n. 17
0
 def test_game_three_join_starts(self):
     game = Game()
     bob = Player('Bob', '~bobbo')
     p = CmdParser(game)
     msg = FakeIRCmsg('start')
     p.parse(msg)
     game.command(p)
     jim = Player('Jim', '~bobbo')
     msg = FakeIRCmsg('join', user=jim)
     p.parse(msg)
     p.player = jim
     game.command(p)
     joe = Player('Joe', '~bobbo')
     msg = FakeIRCmsg('join', user=joe)
     p.parse(msg)
     game.command(p)
     self.assertEqual('wait_answers', game.status)
Esempio n. 18
0
 def test_game_start_says_game_start(self):
     config = Config()
     game = Game()
     bob = Player('Bob', '~bobbo')
     p = CmdParser(game)
     msg = FakeIRCmsg('start')
     p.parse(msg)
     game.command(p)
     self.assertEqual(2, len(cahirc.Cahirc.say.mock_calls))
Esempio n. 19
0
 def test_irc_msg_obj(self):
     game = Game()
     bob = Player('Bob', '~bobbo')
     game.add_player(bob)
     msg = FakeIRCmsg('hello')
     self.assertEqual(msg.nick, 'Bob')
     self.assertEqual(msg.user, '~bobbo')
     self.assertEqual(msg.msg, 'hello')
     self.assertEqual(msg.source, 'privmsg')
Esempio n. 20
0
 def test_game_three_join_starts(self):
     game = Game()
     bob = Player('Bob', '~bobbo')
     p = CmdParser(game)
     msg = FakeIRCmsg('start')
     p.parse(msg)
     game.command(p)
     jim = Player('Jim', '~jimbo')
     msg = FakeIRCmsg('join', user=jim)
     p.parse(msg)
     game.command(p)
     joe = Player('Joe', '~joebo')
     msg = FakeIRCmsg('join', user=joe)
     p.parse(msg)
     game.command(p)
     self.assertEqual(10, len(game.players[0].show_hand()))
     self.assertEqual(10, len(game.players[1].show_hand()))
     self.assertEqual(10, len(game.players[2].show_hand()))
Esempio n. 21
0
 def test_game_start_text_says_game_start(self):
     config = Config()
     text = config.data['text']['en']['round_start']
     game = Game()
     bob = Player('Bob', '~bobbo')
     p = CmdParser(game)
     msg = FakeIRCmsg('start')
     p.parse(msg)
     game.command(p)
     self.assertEqual('call("{}")'.format(text),
                      str(cahirc.Cahirc.say.mock_calls[0]))
Esempio n. 22
0
 def test_cards_replays_question(self):
     config = Config().data
     game = start_game()
     player = game.players[1]
     p = CmdParser(game)
     msg = FakeIRCmsg('cards', user=player)
     p.parse(msg)
     game.command(p)
     question = game.question.formattedvalue
     annc = config['text']['en']['question_announcement']
     annc = annc.format(card=question)
     expected = call(annc)
     self.assertEqual(str(expected), str(cahirc.Cahirc.say.mock_calls[-2]))
Esempio n. 23
0
 def test_multi_argument_command(self):
     bob = Player('Bob', '~bobbo')
     self.game.add_player(bob)
     self.game.load_cards()
     self.game.deck.shuffle()
     self.game.deal_all_players(10)
     self.game.status = 'wait_answers'
     cmdstring = 'play 3 4 5'
     msg = FakeIRCmsg(cmdstring, user=bob)
     self.p.parse(msg)
     self.assertEqual('play', self.p.command)
     self.assertEqual(3, len(self.p.args))
     self.assertEqual([str, str, str], [type(i) for i in self.p.args])
Esempio n. 24
0
 def test_dealing_inorder_cards_works(self):
     bob = Player('Bob', '~bobbo')
     joe = Player('Joe', '~bobbo')
     jim = Player('Jim', '~bobbo')
     self.game.start()
     self.game.add_player(bob)
     self.game.add_player(joe)
     self.game.add_player(jim)
     jimcards = jim.show_hand()[1:4]
     cmdstring = 'play 1 2 3'
     msg = FakeIRCmsg(cmdstring, user=jim)
     self.p.parse(msg)
     self.game.command(self.p)
     self.assertEqual(jimcards, self.game.answers[jim]['cards'])
Esempio n. 25
0
 def test_list_command_works(self):
     config = Config().data
     game = start_game()
     player = game.players[1]
     msg = FakeIRCmsg('list', user=player)
     p = CmdParser(game)
     p.parse(msg)
     game.command(p)
     playerlist = [player.nick for player in game.players]
     players = gameclass.playerlist_format(playerlist)
     annc = config['text']['en']['player_list']
     annc = annc.format(players=players)
     expected = call(annc)
     self.assertEqual(str(expected), str(cahirc.Cahirc.say.mock_calls[-1]))
Esempio n. 26
0
 def test_commander_runs_play_command(self):
     hand_size = Config().data['hand_size']
     game = Game()
     p = CmdParser(game)
     bob = Player('Bob', '~bobbo')
     jim = Player('Jim', '~jimbo')
     joe = Player('Joe', '~joemg')
     msg = FakeIRCmsg('play 1', user=jim)
     game.start()
     game.add_player(bob)
     game.add_player(jim)
     game.add_player(joe)
     p.parse(msg)
     game.command(p)
     self.assertEqual(hand_size - 1, len(jim.show_hand()))
Esempio n. 27
0
 def test_cards_command_works(self):
     config = Config().data
     game = start_game()
     player = game.players[1]
     p = CmdParser(game)
     msg = FakeIRCmsg('cards', user=player)
     p.parse(msg)
     game.command(p)
     hand = player.show_hand()
     annc = config['text']['en']['player_hand']
     handstring = ''
     i = 0
     for card in hand:
         handstring += '[{}] {} '.format(i, card)
         i += 1
     expected = call(annc.format(cards=handstring))
     self.assertIn(str(expected), str(cahirc.Cahirc.say.mock_calls[-1]))
     self.assertEqual(player.nick, game.irc.destination)
Esempio n. 28
0
 def test_aliases_work_at_all(self):
     bob = Player('Bob', '~bobbo')
     joe = Player('Joe', '~bobbo')
     jim = Player('Jim', '~bobbo')
     self.game.start()
     self.game.add_player(bob)
     self.game.add_player(joe)
     self.game.add_player(jim)
     config = Config().data
     player = self.game.players[1]
     msg = FakeIRCmsg('players', user=player)
     p = CmdParser(self.game)
     p.parse(msg)
     self.game.command(p)
     playerlist = [player.nick for player in self.game.players]
     players = gameclass.playerlist_format(playerlist)
     annc = config['text']['en']['player_list']
     annc = annc.format(players=players)
     expected = call(annc)
     self.assertEqual(str(expected), str(cahirc.Cahirc.say.mock_calls[-1]))
Esempio n. 29
0
 def test_commands_wo_args_ignored_w_args(self):
     cmdstring = 'shame about the weather'
     msg = FakeIRCmsg(cmdstring)
     self.p.parse(msg)
     self.assertIsNone(self.p.command)
Esempio n. 30
0
 def test_cmd_no_args(self):
     cmdstring = 'pick yourself up'
     msg = FakeIRCmsg(cmdstring)
     self.p.parse(msg)
     self.assertEqual(None, self.p.command)
     self.assertEqual([], self.p.args)