Skip to content

Commit

Permalink
Merge branch 'main' into feature/next_rubber
Browse files Browse the repository at this point in the history
Signed-off-by: Segelzwerg <25705862+Segelzwerg@users.noreply.github.com>

# Conflicts:
#	tests/whist_core/session/test_table.py
#	whist_core/session/table.py
  • Loading branch information
Segelzwerg committed Nov 8, 2022
2 parents 535e967 + 6a10d74 commit 90cd96f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
6 changes: 5 additions & 1 deletion tests/whist_core/session/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from tests.whist_core.base_test_case import BaseTestCase
from whist_core.error.table_error import TeamFullError, TableFullError, TableNotReadyError, \
TableNotStartedError, PlayerNotJoinedError
TableNotStartedError, PlayerNotJoinedError, TableSettingsError
from whist_core.game.errors import RubberNotDoneError
from whist_core.game.rubber import Rubber
from whist_core.session.matcher import RandomMatcher, RoundRobinMatcher
Expand All @@ -15,6 +15,10 @@ def setUp(self) -> None:
super().setUp()
self.table = Table(name='test table', min_player=1, max_player=4)

def test_min_max_validation(self):
with self.assertRaises(TableSettingsError):
_ = Table(name='faulty table', min_player=3, max_player=2)

def test_ready(self):
self.table.join(self.player)
self.table.player_ready(self.player)
Expand Down
6 changes: 6 additions & 0 deletions whist_core/error/table_error.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
"""Errors regarding table logic."""


class TableSettingsError(Exception):
"""
Thrown if the table is not setup correctly.
"""


class TableFullError(Exception):
"""
Thrown if the table is already full.
Expand Down
16 changes: 15 additions & 1 deletion whist_core/session/table.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"""DAO of session."""
from pydantic import root_validator

from whist_core.error.table_error import TableFullError, TeamFullError, TableNotReadyError, \
TableNotStartedError
TableNotStartedError, TableSettingsError
from whist_core.game.errors import RubberNotDoneError
from whist_core.game.rubber import Rubber
from whist_core.session.matcher import Matcher, RoundRobinMatcher
Expand All @@ -20,6 +21,19 @@ class Table(Session):
rubbers: list[Rubber] = []
matcher: Matcher = RoundRobinMatcher()

# pylint: disable=no-self-argument
@root_validator(pre=True)
def validate_min_is_lower_max_player(cls, values):
"""
Checks if the min_player is less or equal than max_player.
:param values:
:return:
"""
if values.get('min_player') > values.get('max_player'):
raise TableSettingsError('The amount of minimum player must not be higher than the '
'maximum amount.')
return values

# pylint: disable=too-few-public-methods
class Config:
"""
Expand Down

0 comments on commit 90cd96f

Please sign in to comment.