Skip to content

Commit 6066a83

Browse files
committed
Replace tournament phase with enum
1 parent 78b355d commit 6066a83

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

docs/api.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ Enumerations are provided for various values in order to avoid depending on stri
5959
:members:
6060
:undoc-members:
6161

62+
.. autoclass:: TournamentPhase
63+
:members:
64+
:undoc-members:
65+
6266
.. autoclass:: TransferType
6367
:members:
6468
:undoc-members:

tests/tests_tournament.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import unittest
33

44
from tests.tests_tibiapy import TestCommons
5-
from tibiapy import InvalidContent, ListedTournament, PvpType, RuleSet, ScoreSet, Tournament, TournamentLeaderboard
5+
from tibiapy import InvalidContent, ListedTournament, PvpType, RuleSet, ScoreSet, Tournament, TournamentLeaderboard, \
6+
TournamentPhase
67

78
FILE_TOURNAMENT_SIGN_UP = "tournaments/tibiacom_sign_up.txt"
89
FILE_TOURNAMENT_ARCHIVE = "tournaments/tibiacom_archive.txt"
@@ -21,7 +22,7 @@ def test_tournament_from_content(self):
2122
content = self._load_resource(FILE_TOURNAMENT_SIGN_UP)
2223
tournament = Tournament.from_content(content)
2324
self.assertEqual(tournament.title, "TRIUMPH")
24-
self.assertEqual("sign up", tournament.phase)
25+
self.assertEqual(TournamentPhase.SIGN_UP, tournament.phase)
2526
self.assertIsInstance(tournament.start_date, datetime.datetime)
2627
self.assertIsInstance(tournament.end_date, datetime.datetime)
2728
self.assertEqual(6, len(tournament.worlds))
@@ -81,7 +82,7 @@ def test_tournament_from_content_archived(self):
8182
content = self._load_resource(FILE_TOURNAMENT_ARCHIVE)
8283
tournament = Tournament.from_content(content)
8384
self.assertEqual(tournament.title, "GLORY")
84-
self.assertEqual("ended", tournament.phase)
85+
self.assertEqual(TournamentPhase.ENDED, tournament.phase)
8586
self.assertIsInstance(tournament.start_date, datetime.datetime)
8687
self.assertIsInstance(tournament.end_date, datetime.datetime)
8788
self.assertEqual(6, len(tournament.worlds))

tibiapy/enums.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
'PvpType',
1212
'Sex',
1313
'TournamentWorldType',
14+
'TournamentPhase',
1415
'TransferType',
1516
'Vocation',
1617
'VocationFilter',
@@ -67,9 +68,7 @@ class HouseStatus(BaseEnum):
6768

6869

6970
class HouseType(BaseEnum):
70-
"""
71-
The types of house available.
72-
"""
71+
"""The types of house available."""
7372
HOUSE = "house"
7473
GUILDHALL = "guildhall"
7574

@@ -111,6 +110,13 @@ class TournamentWorldType(BaseEnum):
111110
RESTRICTED = "Restricted Store"
112111

113112

113+
class TournamentPhase(BaseEnum):
114+
"""The possible tournament phases."""
115+
SIGN_UP = "sign up"
116+
RUNNING = "running"
117+
ENDED = "ended"
118+
119+
114120
class TransferType(BaseEnum):
115121
"""The possible special transfer restrictions a world may have."""
116122
REGULAR = "regular" #: No special transfer restrictions

tibiapy/tournament.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import bs4
77

8-
from tibiapy import abc, InvalidContent, PvpType, Vocation
8+
from tibiapy import abc, InvalidContent, PvpType, TournamentPhase, Vocation
99
from tibiapy.utils import get_tibia_url, parse_integer, parse_tibia_datetime, parse_tibia_full_date, \
1010
parse_tibiacom_content, split_list, \
1111
try_enum
@@ -280,7 +280,7 @@ class Tournament(abc.BaseTournament):
280280
An internal number used to get direct access to a specific tournament in the archive.
281281
282282
This will only be present when viewing an archived tournament, otherwise it will default to 0.
283-
phase: :class:`str`
283+
phase: :class:`TournamentPhase`
284284
The current phase of the tournament.
285285
start_date: :class:`datetime.datetime`
286286
The start date of the tournament.
@@ -312,7 +312,7 @@ class Tournament(abc.BaseTournament):
312312
def __init__(self, **kwargs):
313313
self.title = kwargs.get("title")
314314
self.cycle = kwargs.get("cycle", 0)
315-
self.phase = kwargs.get("phase")
315+
self.phase = try_enum(TournamentPhase, kwargs.get("phase"))
316316
self.start_date = kwargs.get("start_date") # type: datetime.datetime
317317
self.end_date = kwargs.get("end_date") # type: datetime.datetime
318318
self.worlds = kwargs.get("worlds") # type: List[str]
@@ -419,6 +419,8 @@ def _parse_tournament_info(self, table):
419419
value = parse_tibia_datetime(value)
420420
if field in list_fields:
421421
value = split_list(value, ",", ",")
422+
if field == "phase":
423+
value = try_enum(TournamentPhase, value)
422424
try:
423425
setattr(self, field, value)
424426
except AttributeError:

0 commit comments

Comments
 (0)