Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
dist
build
docs/site/*
.venv/
6 changes: 2 additions & 4 deletions tests/base_unittest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import unittest
from mock import Mock
from nose.tools import *
from unittest.mock import Mock

class BaseUnitTest(unittest.TestCase):

Expand All @@ -14,5 +13,4 @@ def true(self, target):
return self.assertTrue(target)

def false(self, target):
return self.assertFalse(target)

return self.assertFalse(target)
12 changes: 5 additions & 7 deletions tests/pypokerengine/api/emulator_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import OrderedDict
from functools import reduce

from nose.tools import raises
import pytest
from tests.base_unittest import BaseUnitTest
from pypokerengine.api.emulator import Emulator, Event
from pypokerengine.utils.game_state_utils import restore_game_state, attach_hole_card,\
Expand Down Expand Up @@ -32,9 +32,9 @@ def test_register_and_fetch_player(self):
self.eq(p1, self.emu.fetch_player("uuid-1"))
self.eq(p2, self.emu.fetch_player("uuid-2"))

@raises(TypeError)
def test_register_invalid_player(self):
self.emu.register_player("uuid", "hoge")
with pytest.raises(TypeError):
self.emu.register_player("uuid", "hoge")

def test_blind_structure(self):
game_state = restore_game_state(TwoPlayerSample.round_state)
Expand Down Expand Up @@ -146,18 +146,16 @@ def test_apply_action_start_next_round(self):
self.eq(100, game_state["table"].seats.players[0].stack)
self.eq(70, game_state["table"].seats.players[1].stack)

@raises(Exception)
def test_apply_action_when_game_finished(self):
game_state = restore_game_state(TwoPlayerSample.round_state)
game_state = attach_hole_card_from_deck(game_state, "tojrbxmkuzrarnniosuhct")
game_state = attach_hole_card_from_deck(game_state, "pwtwlmfciymjdoljkhagxa")
self.emu.set_game_rule(2, 3, 5, 0)
p1, p2 = FoldMan(), FoldMan()
self.emu.register_player("tojrbxmkuzrarnniosuhct", FoldMan())
self.emu.register_player("pwtwlmfciymjdoljkhagxa", FoldMan())

game_state, events = self.emu.apply_action(game_state, "fold")
self.emu.apply_action(game_state, "fold")
with pytest.raises(Exception):
self.emu.apply_action(game_state, "fold")


def test_run_until_round_finish(self):
Expand Down
8 changes: 4 additions & 4 deletions tests/pypokerengine/api/game_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pypokerengine.api.game as G

from nose.tools import raises
import pytest
from tests.base_unittest import BaseUnitTest
from examples.players.fold_man import FoldMan

Expand Down Expand Up @@ -51,8 +51,8 @@ def test_start_poker_validation_when_one_player(self):
result = G.start_poker(config)
self.assertIn("only 1 player", str(e.exception))

@raises(TypeError)
def test_register_player_when_invalid(self):
config = G.setup_config(1, 100, 10)
config.register_player("p1", "dummy")
with pytest.raises(TypeError):
config = G.setup_config(1, 100, 10)
config.register_player("p1", "dummy")

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from pypokerengine.engine.message_builder import MessageBuilder
from pypokerengine.engine.dealer import MessageHandler
from pypokerengine.players import BasePokerPlayer
from nose.tools import *

class MessageIntegrationTest(BaseUnitTest):

Expand Down
1 change: 0 additions & 1 deletion tests/pypokerengine/engine/game_evaluator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pypokerengine.engine.pay_info import PayInfo
from pypokerengine.engine.table import Table
from pypokerengine.engine.game_evaluator import GameEvaluator
from nose.tools import *

class GameEvaluatorTest(BaseUnitTest):

Expand Down
24 changes: 12 additions & 12 deletions tests/pypokerengine/engine/player_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import pytest
from tests.base_unittest import BaseUnitTest
from pypokerengine.engine.card import Card
from pypokerengine.engine.player import Player
from pypokerengine.engine.poker_constants import PokerConstants as Const
from nose.tools import *

class PlayerTest(BaseUnitTest):

Expand All @@ -15,18 +15,18 @@ def test_add_holecard(self):
self.true(cards[0] in self.player.hole_card)
self.true(cards[1] in self.player.hole_card)

@raises(ValueError)
def test_add_single_hole_card(self):
self.player.add_holecard([Card.from_id(1)])
with pytest.raises(ValueError):
self.player.add_holecard([Card.from_id(1)])

@raises(ValueError)
def test_add_too_many_hole_card(self):
self.player.add_holecard([Card.from_id(cid) for cid in range(1,4)])
with pytest.raises(ValueError):
self.player.add_holecard([Card.from_id(cid) for cid in range(1,4)])

@raises(ValueError)
def test_add_hole_card_twice(self):
self.player.add_holecard([Card.from_id(cid) for cid in range(1,3)])
self.player.add_holecard([Card.from_id(cid) for cid in range(1,3)])
with pytest.raises(ValueError):
self.player.add_holecard([Card.from_id(cid) for cid in range(1,3)])
self.player.add_holecard([Card.from_id(cid) for cid in range(1,3)])

def test_clear_holecard(self):
self.player.add_holecard([Card.from_id(cid) for cid in range(1,3)])
Expand All @@ -41,9 +41,9 @@ def test_collect_bet(self):
self.player.collect_bet(10)
self.eq(90, self.player.stack)

@raises(ValueError)
def test_collect_too_much_bet(self):
self.player.collect_bet(200)
with pytest.raises(ValueError):
self.player.collect_bet(200)

def test_is_active(self):
self.player.pay_info.update_by_pay(10)
Expand Down Expand Up @@ -128,9 +128,9 @@ def test_add_ante_history(self):
self.eq("ANTE", action["action"])
self.eq(10, action["amount"])

@raises(AssertionError)
def test_add_empty_ante_history(self):
self.player.add_action_history(Const.Action.ANTE, 0)
with pytest.raises(AssertionError):
self.player.add_action_history(Const.Action.ANTE, 0)

def test_save_street_action_histories(self):
self.assertIsNone(self.player.round_action_histories[Const.Street.PREFLOP])
Expand Down
6 changes: 3 additions & 3 deletions tests/pypokerengine/engine/table_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from tests.base_unittest import BaseUnitTest
from nose.tools import *

from pypokerengine.engine.card import Card
from pypokerengine.engine.pay_info import PayInfo
Expand Down Expand Up @@ -43,9 +43,9 @@ def test_reset_player_status(self):
self.eq(0, len(self.player.action_histories))
self.eq(PayInfo.PAY_TILL_END, self.player.pay_info.status)

@raises(ValueError)
def test_community_card_exceed_size(self):
self.table.add_community_card(Card.from_id(1))
with pytest.raises(ValueError):
self.table.add_community_card(Card.from_id(1))

def test_shift_dealer_btn_skip(self):
table = self.__setup_players_with_table()
Expand Down
18 changes: 9 additions & 9 deletions tests/pypokerengine/utils/game_state_utils_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from nose.tools import raises
import pytest
from tests.base_unittest import BaseUnitTest
from pypokerengine.utils.game_state_utils import restore_game_state,\
attach_hole_card, replace_community_card,\
Expand Down Expand Up @@ -50,17 +50,17 @@ def test_attach_hole_card(self):
self.eq(hole2, players[1].hole_card)
self.eq([0,0], [len(p.hole_card) for p in game_state["table"].seats.players])

@raises(Exception)
def test_attach_hole_card_when_uuid_is_wrong(self):
game_state = restore_game_state(TwoPlayerSample.round_state)
attach_hole_card(game_state, "hoge", "dummy_hole")
with pytest.raises(Exception):
game_state = restore_game_state(TwoPlayerSample.round_state)
attach_hole_card(game_state, "hoge", "dummy_hole")

@raises(Exception)
def test_attach_hole_card_when_same_uuid_players_exist(self):
game_state = restore_game_state(TwoPlayerSample.round_state)
p1, p2 = game_state["table"].seats.players[:2]
p2.uuid = p1.uuid
attach_hole_card(game_state, p1.uuid, "dummy_hole")
with pytest.raises(Exception):
game_state = restore_game_state(TwoPlayerSample.round_state)
p1, p2 = game_state["table"].seats.players[:2]
p2.uuid = p1.uuid
attach_hole_card(game_state, p1.uuid, "dummy_hole")

def test_replace_community_card(self):
game_state = restore_game_state(TwoPlayerSample.round_state)
Expand Down