コード例 #1
0
    def test_correct_input_remove_street_command_parses_sucessfully(self):

        parser = CmdParser()

        i1 = r'r "Davenport Road"'
        command = parser.parse(i1)
        self.assertEqual(command.name, 'remove street')
        self.assertEqual(command.street, 'Davenport Road')

        i2 = r' r "Davenport Road"'
        command = parser.parse(i2)
        self.assertEqual(command.name, 'remove street')
        self.assertEqual(command.street, 'Davenport Road')

        i3 = r'  r "Davenport Road" '
        command = parser.parse(i3)
        self.assertEqual(command.name, 'remove street')
        self.assertEqual(command.street, 'Davenport Road')
コード例 #2
0
    def test_scenario2(self):
        i1 = r'a "up and across st" (0,0) (10,10)'
        i2 = r'a "StreetB" (0,10)(10,0)'
        i3 = 'g'

        parser = CmdParser()
        db = {}

        c1 = parser.parse(i1)
        c2 = parser.parse(i2)

        c1.execute(db)
        c2.execute(db)

        c3 = parser.parse(i3)
        has_out, out = c3.execute(db)
        if has_out:
            print out

        self.assertTrue(True)
コード例 #3
0
ファイル: test.py プロジェクト: IanJSeattle/pycardbot
 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]))
コード例 #4
0
ファイル: test.py プロジェクト: IanJSeattle/pycardbot
 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]))
コード例 #5
0
    def test_scenario4(self):
        i1 = r'a "Amphitheatre Prkw" (2,-1)(2,2) (5,5) (5,6) (3,8)'
        i2 = r'c "amphitheatre PRKW" (0,0)(4,0)'
        i3 = r'a "One Infinite Loop" (3,0)(5,0)'
        i4 = r'g'

        parser = CmdParser()
        db = {}

        c1 = parser.parse(i1)
        c2 = parser.parse(i2)
        c3 = parser.parse(i3)
        c4 = parser.parse(i4)

        c1.execute(db)
        c2.execute(db)
        c3.execute(db)
        has_out, out = c4.execute(db)
        if has_out:
            print out

        self.assertTrue(True)
コード例 #6
0
    def test_scenario3(self):
        i1 = r'a "Weber Street" (2,-1) (2,2) (5,5) (5,6) (3,8)'
        i2 = r'a "King Street S" (3,2) (4,8)'
        i3 = r'a "Davenport Road" (0,0) (5,8)'
        i4 = r'g'

        parser = CmdParser()
        db = {}

        c1 = parser.parse(i1)
        c2 = parser.parse(i2)
        c3 = parser.parse(i3)
        c4 = parser.parse(i4)

        c1.execute(db)
        c2.execute(db)
        c3.execute(db)
        has_out, out = c4.execute(db)
        if has_out:
            print out

        self.assertTrue(True)
コード例 #7
0
    def test_correct_input_addupdate_street_command_parses_successfully(self):
        """ Tests that valid input for the 'Add street' command is parsed correctly """

        parser = CmdParser()

        i11 = r'a "Weber Street" (2,-1) (2,2) (5,5) (5,6) (3,8)'
        command = parser.parse(i11)
        i11segments = [
            Segment2d(Point2d(2, -1), Point2d(2, 2)),
            Segment2d(Point2d(2, 2), Point2d(5, 5)),
            Segment2d(Point2d(5, 5), Point2d(5, 6)),
            Segment2d(Point2d(5, 6), Point2d(3, 8))
        ]

        self.assertEqual(command.name, 'add street')
        self.assertEqual(command.street, 'Weber Street')
        self.assertItemsEqual(self.db[command.street], command.points)

        i12 = r' a "Weber Street" (2,-1) (2,2) (5,5) (5,6) (3,8)'
        command = parser.parse(i12)
        self.assertEqual(command.name, 'add street')
        self.assertEqual(command.street, 'Weber Street')
        self.assertItemsEqual(self.db[command.street], command.points)

        i13 = r'  a "Weber Street" (2,-1) (2,2) (5,5) (5,6) (3,8) '
        command = parser.parse(i13)
        self.assertEqual(command.name, 'add street')
        self.assertEqual(command.street, 'Weber Street')
        self.assertItemsEqual(self.db[command.street], command.points)

        i21 = r'c "Weber Street" (4,2) (4,8)'
        command = parser.parse(i21)
        self.assertEqual(command.name, 'update street')
        self.assertEqual(command.street, 'Weber Street')
        self.assertItemsEqual([Point2d(4, 2), Point2d(4, 8)], command.points)

        i22 = r' c "Weber Street" (4,2) (4,8)'
        command = parser.parse(i22)
        self.assertEqual(command.name, 'update street')
        self.assertEqual(command.street, 'Weber Street')
        self.assertItemsEqual([Point2d(4, 2), Point2d(4, 8)], command.points)

        i23 = r'  c "Weber Street" (4,2) (4,8) '
        command = parser.parse(i23)
        self.assertEqual(command.name, 'update street')
        self.assertEqual(command.street, 'Weber Street')
        self.assertItemsEqual([Point2d(4, 2), Point2d(4, 8)], command.points)
コード例 #8
0
ファイル: test.py プロジェクト: IanJSeattle/pycardbot
 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)
コード例 #9
0
ファイル: test.py プロジェクト: IanJSeattle/pycardbot
 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()))
コード例 #10
0
ファイル: test.py プロジェクト: IanJSeattle/pycardbot
class ParserTest(unittest.TestCase):
    def setUp(self):
        self.game = Game()
        self.p = CmdParser(self.game)
        cahirc.Cahirc.say.reset_mock()

    def test_basic_command_works(self):
        game = Game()
        cmdstring = 'start'
        msg = FakeIRCmsg(cmdstring)
        self.p.parse(msg)
        self.assertEqual(cmdstring, self.p.command)

    def test_one_argument_command_works(self):
        cmdstring = 'winner 1'
        msg = FakeIRCmsg(cmdstring)
        self.p.parse(msg)
        self.assertEqual('winner', self.p.command)
        self.assertEqual([1], self.p.args)

    # note weird hacky thing: there were lots of tests that depend upon
    # play returning a number, but play actually needs to return cards.
    # so, there are two different behaviors going here: the play cmd,
    # without a player, just returns numbers.  with a player, it
    # expands out to cards.  we will only use the player version in
    # real life, but the numbers version is handy for testing.

    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])

    def test_one_arg_with_garbage(self):
        cmdstring = 'winner 1 because we rock'
        msg = FakeIRCmsg(cmdstring)
        self.p.parse(msg)
        self.assertEqual('winner', self.p.command)
        self.assertEqual([1], self.p.args)

    def test_multi_arg_with_garbage(self):
        cmdstring = 'play 1 2 3 because ew'
        msg = FakeIRCmsg(cmdstring)
        self.p.parse(msg)
        self.assertEqual('play', self.p.command)
        self.assertEqual([1, 2, 3], self.p.args)

    def test_random_string(self):
        cmdstring = 'why is the sky blue?'
        msg = FakeIRCmsg(cmdstring)
        self.p.parse(msg)
        self.assertEqual(None, self.p.command)
        self.assertEqual([], self.p.args)

    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)

    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)

    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)

    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)

    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)

    def test_dealing_a_card_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)
        jimcard = jim.show_hand()[1]
        cmdstring = 'play 1'
        msg = FakeIRCmsg(cmdstring, user=jim)
        self.p.parse(msg)
        self.game.command(self.p)
        self.assertEqual([jimcard], self.game.answers[jim]['cards'])

    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'])

    def test_dealing_wackorder_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 = []
        jimcards.append(jim.show_hand()[3])
        jimcards.append(jim.show_hand()[1])
        jimcards.append(jim.show_hand()[7])
        cmdstring = 'play 3 1 7'
        msg = FakeIRCmsg(cmdstring, user=jim)
        self.p.parse(msg)
        self.game.command(self.p)
        self.assertEqual(jimcards, self.game.answers[jim]['cards'])

    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]))

    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))
コード例 #11
0
ファイル: test.py プロジェクト: IanJSeattle/pycardbot
def run_command(game, command, user=None):
    p = CmdParser(game)
    msg = FakeIRCmsg(command, user=user)
    p.parse(msg)
    game.command(p)