当前位置: 首页>>代码示例>>Python>>正文


Python Table.join方法代码示例

本文整理汇总了Python中table.Table.join方法的典型用法代码示例。如果您正苦于以下问题:Python Table.join方法的具体用法?Python Table.join怎么用?Python Table.join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在table.Table的用法示例。


在下文中一共展示了Table.join方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_join

# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import join [as 别名]
def test_join():
	students = Table("students.json")
	classes = Table("classes.json")

	result = [
		{u'c.class_id': 2, u'class_id': 2, u'paid': False, 	u'c.name': u'italian', 	u'id': 1, 	u'name': u'Steve'}, 
		{u'c.class_id': 2, u'class_id': 2, u'paid': True, 	u'c.name': u'italian', 	u'id': 2, 	u'name': u'Caroline'}, 
		{u'c.class_id': 1, u'class_id': 1, u'paid': True, 	u'c.name': u'french', 	u'id': 3, 	u'name': u'Frank'}, 
		{u'c.class_id': 3, u'class_id': 3, u'paid': False, 	u'c.name': u'spanish', 	u'id': 4, 	u'name': u'Jacinta'}, 
		{u'c.class_id': 2, u'class_id': 2, u'paid': True, 	u'c.name': u'italian', 	u'id': 5, 	u'name': u'Rupert'}, 
		{u'c.class_id': 1, u'class_id': 1, u'paid': True, 	u'c.name': u'french', 	u'id': 6, 	u'name': u'Guiseppe'}, 
		{u'c.class_id': 3, u'class_id': 3, u'paid': False, 	u'c.name': u'spanish', 	u'id': 7, 	u'name': u'Penny'}, 
		{u'c.class_id': 3, u'class_id': 3, u'paid': False, 	u'c.name': u'spanish', 	u'id': 8, 	u'name': u'Maria'}, 
		{u'c.class_id': 3, u'class_id': 3, u'paid': False, 	u'c.name': u'spanish', 	u'id': 9, 	u'name': u'Prudence'}, 
		{u'c.class_id': 3, u'class_id': 3, u'paid': False, 	u'c.name': u'spanish', 	u'id': 10, 	u'name': u'Ferdinand'}
	]
	assert students.join(classes, "class_id", "c")(False) == result
开发者ID:freneticmonkey,项目名称:table,代码行数:19,代码来源:test_table.py

示例2: TestPlayer

# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import join [as 别名]
class TestPlayer(unittest.TestCase):

    def setUp(self):
        self.player = Player("player1", 100)
        self.player2 = Player("player2", 100)
        self.player.action = True
        self.table = Table(6, 1, 2, [50, 100])
        self.table.join(1, self.player, 100)
        self.table.join(2, self.player2, 100)
        pot1 = Pot([self.player, self.player2], 100)
        pot2 = Pot([self.player, self.player2], 100)
        self.table.pots = [pot1, pot2]

    def test_bet(self):
        """Does bet subtract from stack and add to equity"""
        self.player.bet(20)
        self.assertEqual(80, self.player.stack)
        self.assertEqual(20, self.player.equity)
        self.assertFalse(self.player.action)

    def test_bet_negative_int_fails(self):
        """Do we throw an error when bet is a negative number?"""
        with self.assertRaises(Exception) as context:
            self.player.bet(-50)
        self.assertIn("Bets can not be negative", str(context.exception))

    def test_call(self):
        """Can we ensure that the bettor at least matches the minimum bet??"""
        self.table.current_bet = 20
        with self.assertRaises(Exception) as context:
            self.player.bet(10)
        self.assertIn("Must match the current bet", str(context.exception))

    def test_all_in(self):
        """ Can a player go all in, even for less than min bet? """
        self.table.current_bet = 20
        self.player.stack = 10
        self.player.bet(10)
        self.assertTrue(self.player.equity == 10)
        self.assertTrue(self.table.pots[-1].side_pots[0] == 10)

    def test_min_raise(self):
        """ Can we ensure that players cant raise less than the min? """
        with self.assertRaises(Exception) as context:
            self.player.bet(1)
        self.assertIn("Minimum raise is 2", str(context.exception))

    def test_max_bet_is_all_in(self):
        """ Can we ensure that players cant bet/raise more than their stack? """
        with self.assertRaises(Exception) as context:
            self.player.bet(200)
        self.assertIn("You can only bet what you have on the table!!", str(context.exception))

    def test_bet_increment_adjusted(self):
        """ Can we set/adjust the bet increment appropriately? """
        self.player.bet(50)
        self.assertEqual(self.table.bet_increment, 50)

    def test_call_action(self):
        """ Can we call action time appropriately """
        self.player._call_action()
        self.assertTrue(self.player2.action)

    def test_fold(self):
        """ Can we fold a player out? """
        self.player.fold()
        self.assertNotIn(self.player, self.table.pots[0].players)
        self.assertNotIn(self.player, self.table.pots[1].players)
开发者ID:mrbubba,项目名称:PokerReduxe,代码行数:70,代码来源:test_player.py

示例3: TestAnalyze

# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import join [as 别名]
class TestAnalyze(unittest.TestCase):
    def setUp(self):

        self.player1 = Player("player1", 100)
        self.player2 = Player("player2", 100)
        self.player3 = Player("player3", 100)
        self.player4 = Player("player4", 100)
        self.player5 = Player("player5", 100)
        self.player6 = Player("player6", 100)
        self.player7 = Player("player7", 100)
        self.player8 = Player("player8", 100)
        self.player9 = Player("player9", 100)

        self.table = Table(9, 1, 2, [50, 100])

        self.table.join(1, self.player1, 100)
        self.table.join(2, self.player2, 100)
        self.table.join(3, self.player3, 100)
        self.table.join(4, self.player4, 100)
        self.table.join(5, self.player5, 100)
        self.table.join(6, self.player6, 100)
        self.table.join(7, self.player7, 100)
        self.table.join(8, self.player8, 100)
        self.table.join(9, self.player9, 100)

        cards = [13, 'h', 14, 'h', 5, 'h', 5, 's', 5, 'h', 10, 'c', 3, 'h', 4,
                 'h', 13, 's', 14, 's', 14, 's', 5, 's', 12, 's',
                 11, 's', 14, 's', 2, 'd', 4, 'h', 2, 'h']

        # Set player order; happy path
        for k, v in self.table.seats.items():
            self.table.player_order.append(v)

        x = 0
        for player in self.table.player_order:
            value = cards[x]
            x += 1
            suit = cards[x]
            x += 1
            card0 = Card("name", value, suit)
            value = cards[x]
            x += 1
            suit = cards[x]
            x += 1
            card1 = Card("name", value, suit)
            player.hole_cards.append(card0)
            player.hole_cards.append(card1)

        table_cards = [12, 'h', 11, 'h', 10, 'h', 5, 'c', 5, 'd']
        x = 0
        while len(self.table.community_cards) != 5:
            value = table_cards[x]
            x += 1
            suit = table_cards[x]
            x += 1
            card = Card("name", value, suit)
            self.table.community_cards.append(card)
        pot = Pot(self.table.player_order, 100)

        self.table.pots.append(pot)

    def test_setup(self):
        """ Do we join the hole cards with the community cards? """
        analyze.setup(self.table)
        self.assertEqual(7, len(self.player1.hole_cards))
        self.assertEqual(7, len(self.player2.hole_cards))

    def test_order(self):
        """ Can we order the hands in a proper order, left to right """
        pot = analyze.setup(self.table)
        analyze.order(pot)
        for player in pot.players:
            for i in range(6):
                v1 = player.hole_cards[i].value
                v2 = player.hole_cards[i + 1].value
                self.assertTrue(v2 <= v1)

    def test_flush(self):
        """ Can we find a flush in the players' hands """
        pot = analyze.setup(self.table)
        analyze.order(pot)
        analyze.flush(pot)
        expected3 = [5, 12, 11, 10, 4, 3]
        expected8 = [5, 12, 11, 10, 4, 2]
        self.assertEqual(expected3, pot.players[3].hand)
        self.assertEqual(expected8, pot.players[8].hand)

    def test_flush_returns_card_values(self):
        """ For all none flush hands do we return card
        values instead of card objects """
        pot = analyze.setup(self.table)
        analyze.order(pot)
        analyze.flush(pot)
        analyze.convert_to_card_value(pot)
        for player in pot.players:
            if not player.hand:
                for card in player.hole_cards:
                    self.assertIsInstance(card, int)

    def test_straight(self):
#.........这里部分代码省略.........
开发者ID:mrbubba,项目名称:PokerReduxe,代码行数:103,代码来源:test_analyze.py

示例4: TestApp

# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import join [as 别名]
class TestApp(unittest.TestCase):
    def setUp(self):
        self.player1 = Player("player1", 100)
        self.player2 = Player("player2", 100)
        self.player3 = Player("player3", 100)
        self.player4 = Player("player4", 100)
        self.player5 = Player("player5", 100)
        self.player6 = Player("player6", 100)

        self.table = Table(6, 1, 2, [50, 100])

        self.table.join(1, self.player1, 100)
        self.table.join(2, self.player2, 100)
        self.table.join(3, self.player3, 100)
        self.table.join(4, self.player4, 100)
        self.table.join(5, self.player5, 100)
        self.table.join(6, self.player6, 100)

        # Set player order; happy path
        for k, v in self.table.seats.items():
            self.table.player_order.append(v)

        pot = Pot(self.table.player_order, 0)

        self.table.pots.append(pot)

    def test_get_active_players(self):
        """ Can we grab a list of active players? """
        six_players = app.get_active_players(self.table)
        self.player1.active = False
        five_players = app.get_active_players(self.table)
        self.assertEqual(6, len(six_players))
        self.assertEqual(5, len(five_players))

    def test_remove_broke_player(self):
        """ Can we remove players with zero chips left in stack """
        self.player1.stack = 0
        five_players = app.get_active_players(self.table)
        self.assertEqual(5, len(five_players))

    def test_set_button(self):
        """ Can we randomly set the button? """
        call1 = app.set_button(self.table)[:]
        call2 = app.set_button(self.table)[:]
        call3 = app.set_button(self.table)[:]
        call4 = app.set_button(self.table)[:]
        call5 = app.set_button(self.table)[:]

        self.assertFalse(call1 == call2 == call3 == call4 == call5)

    def test_move_button(self):
        """ Can we properly increment through the player order? """
        expected = self.table.player_order[:]
        x = expected.pop(0)
        expected.append(x)
        app.move_button(self.table)
        self.assertEqual(expected, self.table.player_order)

    def test_remove_inactive_from_hand(self):
        """ Can we remove an inactive player from a hand """
        self.player4.active = False
        app.move_button(self.table)
        self.assertEqual(len(self.table.player_order), 5)

    def test_add_player_to_hand(self):
        """ Can we add a new player to hand appropriately """
        expected = self.table.player_order[:]
        x = expected.pop(0)
        expected.append(x)
        x = expected.pop(0)
        expected.append(x)
        self.player4.active = False
        app.move_button(self.table)
        self.player4.active = True
        app.move_button(self.table)
        self.assertEqual(len(self.table.player_order), 6)
        self.assertEqual(expected, self.table.player_order)

    def test_bb_mia(self):
        """ Can we prepend sb position to None if bb goes mia """
        self.table.player_order[1].active = False
        app.move_button(self.table)
        self.assertEqual(self.table.player_order[0], None)
        expected = self.table.player_order[:]
        expected.pop(0)
        app.move_button(self.table)
        self.assertEqual(expected, self.table.player_order)

    def test_set_missed_bb(self):
        """ Can we set missed bb to True """
        self.player3.active = False
        app.move_button(self.table)
        self.assertTrue(self.player3.missed_bb)

    def test_set_missed_sb(self):
        """ Can we set missed sb to True """
        self.player2.active = False
        self.player2.acted = True
        app.move_button(self.table)
        self.assertTrue(self.player2.missed_sb)
#.........这里部分代码省略.........
开发者ID:mrbubba,项目名称:PokerReduxe,代码行数:103,代码来源:test_app.py

示例5: TestTable

# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import join [as 别名]
class TestTable(unittest.TestCase):
    """ Do we have a working table object? """

    def setUp(self):
        self.player1 = Player("player1", 100)
        self.player2 = Player("player2", 100)

        self.table = Table(6, 1, 2, [50, 100])

    def test_seats_dict(self):
        """ Is seats dict properly created on instantiation """
        self.assertEqual(len(self.table.seats), 6)

    def test_seats_dict_exception(self):
        """ Do we throw an error when too many seats """
        with self.assertRaises(ValueError):
            Table(12, 1, 2, [50, 10])

    def test_join_table(self):
        """Can a player join our table??"""
        self.table.join(1, self.player1, 100)
        self.assertTrue(self.table.seats[1].name == self.player1.name)

    def test_join_taken_seat(self):
        """Can a player take an already filled spot??  We hope not!!"""
        self.table.seats[1] = self.player1
        with self.assertRaises(ValueError):
            self.table.join(1, self.player2, 100)
        self.assertTrue(self.table.seats[1].name == self.player1.name)

    def test_player_can_only_have_one_seat_at_the_table(self):
        """A player should only occupy one seat per table."""
        self.table.join(1, self.player1, 100)
        with self.assertRaises(ValueError):
            self.table.join(2, self.player1, 100)
        self.assertTrue(self.table.seats[2] == None)

    def test_player_table_attribute_set(self):
        """can we set player.table to this table?"""
        self.table.join(1, self.player1, 100)
        self.assertTrue(self.player1.table == self.table)

    def test_set_player_buyin(self):
        """can set players stack with buy in"""
        self.table.join(1, self.player1, 100)
        self.assertEqual(self.player1.stack, 100)

    def test_set_buyin_range(self):
        """Can we restrict players to the table buyin range?"""
        with self.assertRaises(ValueError):
            self.table.join(1, self.player1, 110)
        self.assertTrue(self.table.seats[1] == None)

    def test_quit(self):
        """ Can a player quit the game? """
        self.table.join(1, self.player1, 100)
        self.table.quit(self.player1)
        self.assertTrue(self.table.seats[1] == None)
        self.assertTrue(self.player1.table == None)
        self.assertEqual(self.player1.stack, 0)

    def test_no_change_to_occupied_seat(self):
        """ Can we prevent a player from sitting in an occupied seat? """
        self.table.join(1, self.player1, 100)
        self.table.join(2, self.player2, 100)
        with self.assertRaises(Exception) as context:
            self.table.change_seat(self.player1, 2)
        self.assertIn("This seat is occupied!!", str(context.exception))

    def test_change_seat_range(self):
        """ Does the seat in question exist? """
        self.table.join(1, self.player1, 100)
        self.table.join(2, self.player2, 100)
        with self.assertRaises(Exception) as context:
            self.table.change_seat(self.player1, 13)
        self.assertIn("This seat doesn't exist!!", str(context.exception))

    def test_change_seat(self):
        """ Can a player change to an open seat? """
        self.table.join(1, self.player1, 100)
        self.table.join(2, self.player2, 100)
        self.table.change_seat(self.player1, 3)
        self.assertEqual(self.player1, self.table.seats[3])
开发者ID:mrbubba,项目名称:PokerReduxe,代码行数:85,代码来源:test_table.py

示例6:

# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import join [as 别名]
from table import Table

if __name__ == '__main__':
    parts = Table.read('parts.txt')
    print parts
    suppliers = Table.read('suppliers.txt')
    print suppliers
    spj = Table.read('spj.txt')
    print spj
    projects = Table.read('projects.txt')
    print projects
    print Table.join(parts,spj)
    print Table.join(suppliers,spj)
    print Table.join(projects,spj)

    print parts.fields
    print parts.select('pno','p2')
    print parts.project('pname','color')
    print parts.project('color')

    suppliers.write('supp2.txt')
    del suppliers
    suppliers = Table.read('supp2.txt')
    print suppliers

    projects.store()
    del projects
    projects = Table.restore('projects.db')
    print projects

    projects.remove('city','Athens')
开发者ID:ccstevenson,项目名称:PythonScripts,代码行数:33,代码来源:test.py

示例7: test_compound

# 需要导入模块: from table import Table [as 别名]
# 或者: from table.Table import join [as 别名]
def test_compound():
	students = Table("students.json")
	classes = Table("classes.json")

	assert students.join(classes,'class_id','c').eq('paid',True).distinct('c.name').count()(False) == 2
开发者ID:freneticmonkey,项目名称:table,代码行数:7,代码来源:test_table.py


注:本文中的table.Table.join方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。