Skip to content

Commit be5099f

Browse files
committed
Added missing covered code
1 parent e1c1f82 commit be5099f

File tree

7 files changed

+27
-5
lines changed

7 files changed

+27
-5
lines changed

tests/tests_highscores.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ def testHighscoresTibiaData(self):
9898
self.assertEqual(highscores.category, Category.AXE_FIGHTING)
9999
self.assertEqual(highscores.results_count, 300)
100100

101+
self.assertEqual(highscores.url_tibiadata,
102+
Highscores.get_url_tibiadata(highscores.world, highscores.category, highscores.vocation))
103+
101104
for entry in highscores.entries:
102105
self.assertIsInstance(entry, HighscoresEntry)
103106
self.assertIsInstance(entry.name, str)

tests/tests_utils.py

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

66
from tests.tests_tibiapy import TestCommons
77
from tibiapy import enums, utils
8+
from tibiapy.utils import parse_integer, parse_tibia_money
89

910
TIBIA_DATETIME_CEST = "Jul 10 2018, 07:13:32 CEST"
1011
TIBIA_DATETIME_CET = "Jan 10 2018, 07:13:32 CET"
@@ -161,3 +162,18 @@ def testEnumStr(self):
161162
self.assertEqual(enums.VocationFilter.from_name("royal paladin"), enums.VocationFilter.PALADINS)
162163
self.assertEqual(enums.VocationFilter.from_name("unknown"), enums.VocationFilter.ALL)
163164
self.assertIsNone(enums.VocationFilter.from_name("unknown", False))
165+
166+
def testParseTibiaMoney(self):
167+
self.assertEqual(1000, parse_tibia_money("1k"))
168+
self.assertEqual(5000000, parse_tibia_money("5kk"))
169+
self.assertEqual(2500, parse_tibia_money("2.5k"))
170+
self.assertEqual(50, parse_tibia_money("50"))
171+
with self.assertRaises(ValueError):
172+
parse_tibia_money("abc")
173+
174+
def testParseInteger(self):
175+
self.assertEqual(1450, parse_integer("1.450"))
176+
self.assertEqual(1110, parse_integer("1,110"))
177+
self.assertEqual(15, parse_integer("15"))
178+
self.assertEqual(0, parse_integer("abc"))
179+
self.assertEqual(-1, parse_integer("abc", -1))

tests/tests_world.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ def testWorldOverview(self):
111111
self.assertGreater(world_overview.total_online, 0)
112112
self.assertIsNotNone(world_overview.record_date)
113113
self.assertIsNotNone(world_overview.record_count)
114+
self.assertEqual(len(world_overview.regular_worlds), 65)
115+
self.assertEqual(len(world_overview.tournament_worlds), 6)
114116

115117
worlds = ListedWorld.list_from_content(content)
116118
self.assertEqual(len(world_overview.worlds), len(worlds))
@@ -206,6 +208,7 @@ def testWorldOverviewTibiaData(self):
206208

207209
self.assertIsInstance(world_overview, WorldOverview)
208210
self.assertEqual(WorldOverview.get_url(), ListedWorld.get_list_url())
211+
self.assertEqual(WorldOverview.get_url_tibiadata(), ListedWorld.get_list_url_tibiadata())
209212
self.assertGreater(sum(w.online_count for w in world_overview.worlds), 0)
210213
self.assertIsInstance(world_overview.worlds[0], ListedWorld)
211214
self.assertIsInstance(world_overview.worlds[0].pvp_type, PvpType)

tibiapy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from tibiapy.creature import *
1414
from tibiapy.client import *
1515

16-
__version__ = '2.0.1'
16+
__version__ = '2.1.0'
1717

1818
from logging import NullHandler
1919

tibiapy/creature.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ def __init__(self, name, image_url):
3131
self.name = name
3232
self.image_url = image_url
3333

34+
def __repr__(self):
35+
return "<{0.__class__.__name__} name={0.name!r} image_url={0.image_url!r}>".format(self)
36+
3437
@classmethod
3538
def from_content(cls, content):
3639
"""

tibiapy/highscores.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,7 @@ def from_tibiadata(cls, content, vocation=None):
187187
highscores.results_count = len(highscores.entries)
188188
except KeyError:
189189
raise InvalidContent("content is not a TibiaData highscores response.")
190-
if isinstance(vocation, VocationFilter):
191-
highscores.vocation = vocation
190+
highscores.vocation = vocation or VocationFilter.ALL
192191
return highscores
193192

194193
@classmethod

tibiapy/world.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,6 @@ def from_content(cls, content):
504504
try:
505505
record_row, *rows = parsed_content.find_all("tr")
506506
m = record_regexp.search(record_row.text)
507-
if not m:
508-
raise InvalidContent("content does not belong to the World Overview section in Tibia.com")
509507
world_overview.record_count = parse_integer(m.group("count"))
510508
world_overview.record_date = parse_tibia_datetime(m.group("date"))
511509
world_rows = rows

0 commit comments

Comments
 (0)