From 826c8d2a3d7892e4e977f03cd41d7ecd65449f43 Mon Sep 17 00:00:00 2001 From: paairs Date: Fri, 17 Apr 2026 14:05:49 +0300 Subject: [PATCH] Fix: replace nose with pytest for Python 3.12 compatibility --- .gitignore | 1 + tests/base_unittest.py | 6 ++--- tests/pypokerengine/api/emulator_test.py | 12 ++++------ tests/pypokerengine/api/game_test.py | 8 +++---- .../engine/dealer_message_integration_test.py | 1 - .../engine/game_evaluator_test.py | 1 - tests/pypokerengine/engine/player_test.py | 24 +++++++++---------- tests/pypokerengine/engine/table_test.py | 6 ++--- .../utils/game_state_utils_test.py | 18 +++++++------- 9 files changed, 36 insertions(+), 41 deletions(-) diff --git a/.gitignore b/.gitignore index a110392..d06d1d7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ dist build docs/site/* +.venv/ diff --git a/tests/base_unittest.py b/tests/base_unittest.py index 0be503a..8671cc0 100644 --- a/tests/base_unittest.py +++ b/tests/base_unittest.py @@ -1,6 +1,5 @@ import unittest -from mock import Mock -from nose.tools import * +from unittest.mock import Mock class BaseUnitTest(unittest.TestCase): @@ -14,5 +13,4 @@ def true(self, target): return self.assertTrue(target) def false(self, target): - return self.assertFalse(target) - + return self.assertFalse(target) \ No newline at end of file diff --git a/tests/pypokerengine/api/emulator_test.py b/tests/pypokerengine/api/emulator_test.py index 718272b..844c480 100644 --- a/tests/pypokerengine/api/emulator_test.py +++ b/tests/pypokerengine/api/emulator_test.py @@ -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,\ @@ -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) @@ -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): diff --git a/tests/pypokerengine/api/game_test.py b/tests/pypokerengine/api/game_test.py index 65462c5..a835367 100644 --- a/tests/pypokerengine/api/game_test.py +++ b/tests/pypokerengine/api/game_test.py @@ -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 @@ -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") diff --git a/tests/pypokerengine/engine/dealer_message_integration_test.py b/tests/pypokerengine/engine/dealer_message_integration_test.py index 010e839..9a19b33 100644 --- a/tests/pypokerengine/engine/dealer_message_integration_test.py +++ b/tests/pypokerengine/engine/dealer_message_integration_test.py @@ -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): diff --git a/tests/pypokerengine/engine/game_evaluator_test.py b/tests/pypokerengine/engine/game_evaluator_test.py index a95e2d1..761731f 100644 --- a/tests/pypokerengine/engine/game_evaluator_test.py +++ b/tests/pypokerengine/engine/game_evaluator_test.py @@ -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): diff --git a/tests/pypokerengine/engine/player_test.py b/tests/pypokerengine/engine/player_test.py index d765de6..59576a3 100644 --- a/tests/pypokerengine/engine/player_test.py +++ b/tests/pypokerengine/engine/player_test.py @@ -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): @@ -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)]) @@ -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) @@ -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]) diff --git a/tests/pypokerengine/engine/table_test.py b/tests/pypokerengine/engine/table_test.py index b0086d6..52b162e 100644 --- a/tests/pypokerengine/engine/table_test.py +++ b/tests/pypokerengine/engine/table_test.py @@ -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 @@ -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() diff --git a/tests/pypokerengine/utils/game_state_utils_test.py b/tests/pypokerengine/utils/game_state_utils_test.py index 16a3891..8096b54 100644 --- a/tests/pypokerengine/utils/game_state_utils_test.py +++ b/tests/pypokerengine/utils/game_state_utils_test.py @@ -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,\ @@ -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)