Skip to content

Commit 7ba523a

Browse files
committed
[ruff] Ruff-specific rules and fixes
1 parent 65372d2 commit 7ba523a

30 files changed

+117
-91
lines changed

pyproject.toml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ select = [
200200
"ARG",
201201
# Perflint
202202
"PERF",
203+
# Ruff-specific rules
204+
"RUF",
203205

204206
]
205207
ignore = [
@@ -209,7 +211,14 @@ ignore = [
209211
"D107",
210212
# Unused lambda argument
211213
"ARG005",
212-
214+
# 1 blank line required before class docstring
215+
"D203",
216+
# 1 blank line required before class docstring
217+
"D213",
218+
# Mutable class attributes should be annotated with `typing.ClassVar`
219+
"RUF012",
220+
# PEP 484 prohibits implicit `Optional`
221+
"RUF013"
213222
]
214223

215224

tests/tests_bazaar.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
AuctionSkillFilter, \
66
AuctionStatus, AuctionVocationFilter, BidType, PvpTypeFilter, Sex, Vocation
77
from tibiapy.parsers import AuctionParser, CharacterBazaarParser
8-
from tibiapy import InvalidContent
8+
from tibiapy import InvalidContentError
99

1010
FILE_BAZAAR_CURRENT_EMPTY = "characterBazaar/bazaarHistoryEmpty.txt"
1111
FILE_BAZAAR_CURRENT = "characterBazaar/bazaarCurrentAuctions.txt"
@@ -73,7 +73,7 @@ def test_character_bazaar_parser_from_content_history(self):
7373
def test_character_bazaar_parser_from_content_unrelated(self):
7474
"""Testing parsing an unrelated tibia.com section"""
7575
content = self.load_resource(self.FILE_UNRELATED_SECTION)
76-
with self.assertRaises(InvalidContent):
76+
with self.assertRaises(InvalidContentError):
7777
CharacterBazaarParser.from_content(content)
7878

7979
def test_auction_parser_from_content_finished(self):
@@ -206,5 +206,5 @@ def test_auction_parser_from_content_not_found(self):
206206
def test_auction_parser_from_content_unrelated(self):
207207
"""Testing parsing an unrelated tibia.com section"""
208208
content = self.load_resource(self.FILE_UNRELATED_SECTION)
209-
with self.assertRaises(InvalidContent):
209+
with self.assertRaises(InvalidContentError):
210210
AuctionParser.from_content(content)

tests/tests_character.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime
22

33
from tests.tests_tibiapy import TestCommons
4-
from tibiapy import InvalidContent
4+
from tibiapy import InvalidContentError
55
from tibiapy.enums import Sex, Vocation
66
from tibiapy.models import Character
77
from tibiapy.parsers import CharacterParser
@@ -164,7 +164,7 @@ def test_character_parser_from_content_truncated_deaths(self):
164164
def test_character_parser_from_content_unrelated(self):
165165
"""Testing parsing an unrelated tibia.com section"""
166166
content = self.load_resource(self.FILE_UNRELATED_SECTION)
167-
with self.assertRaises(InvalidContent):
167+
with self.assertRaises(InvalidContentError):
168168
CharacterParser.from_content(content)
169169

170170
# endregion

tests/tests_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from tests.tests_news import FILE_NEWS_ARCHIVE_RESULTS_FILTERED, FILE_NEWS_ARTICLE
1818
from tests.tests_tibiapy import TestCommons
1919
from tests.tests_world import FILE_WORLD_ONLINE, FILE_WORLD_OVERVIEW_ONLINE
20-
from tibiapy import Forbidden, NetworkError
20+
from tibiapy import ForbiddenError, NetworkError
2121
from tibiapy.client import Client
2222
from tibiapy.enums import BazaarType, HouseType
2323
from tibiapy.models import Auction, CMPostArchive, Character, CharacterBazaar, ForumBoard, ForumSection, Guild, \
@@ -53,7 +53,7 @@ async def test_client_init_pass_session(self):
5353
async def test_client_handle_errors(self, mock):
5454
"""Testing error handling"""
5555
mock.get(get_world_overview_url(), status=403)
56-
with self.assertRaises(Forbidden):
56+
with self.assertRaises(ForbiddenError):
5757
await self.client.fetch_world_overview()
5858

5959
mock.get(get_world_overview_url(), status=404)

tests/tests_creature.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from tests.tests_tibiapy import TestCommons
2-
from tibiapy import InvalidContent
2+
from tibiapy import InvalidContentError
33
from tibiapy.models import CreatureEntry
44
from tibiapy.parsers import BoostableBossesParser, CreatureParser, CreaturesSectionParser
55

@@ -20,7 +20,7 @@ def test_creatures_section_from_boosted_creature_header_content(self):
2020

2121
def test_creatures_section_from_boosted_creature_header_content_not_tibiacom(self):
2222
"""Testing parsing the boosted creature from a page that is not Tibia.com"""
23-
with self.assertRaises(InvalidContent):
23+
with self.assertRaises(InvalidContentError):
2424
CreaturesSectionParser.boosted_creature_from_header("<html><div><p>Nothing</p></div></html>")
2525

2626
def test_creature_section_from_content(self):
@@ -42,7 +42,7 @@ def test_creature_section_from_content(self):
4242
def test_creatures_section_from_content_invalid_content(self):
4343
"""Testing parsing the creatures section from an invalid section"""
4444
content = self.load_resource(self.FILE_UNRELATED_SECTION)
45-
with self.assertRaises(InvalidContent):
45+
with self.assertRaises(InvalidContentError):
4646
CreaturesSectionParser.from_content(content)
4747

4848
def test_creature_from_content(self):
@@ -103,7 +103,7 @@ def test_boostable_bosses_from_content_invalid_content(self):
103103
"""Testing parsing the creatures section from an invalid section"""
104104
content = self.load_resource(self.FILE_UNRELATED_SECTION)
105105

106-
with self.assertRaises(InvalidContent):
106+
with self.assertRaises(InvalidContentError):
107107
BoostableBossesParser.from_content(content)
108108

109109

tests/tests_forums.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime
22

33
from tests.tests_tibiapy import TestCommons
4-
from tibiapy import InvalidContent
4+
from tibiapy import InvalidContentError
55
from tibiapy.enums import ThreadStatus
66
from tibiapy.models import BoardEntry, CMPostArchive, ForumPost, LastPost, ThreadEntry
77
from tibiapy.parsers import (CMPostArchiveParser, ForumAnnouncementParser, ForumBoardParser, ForumSectionParser,
@@ -81,7 +81,7 @@ def test_forum_section_parser_from_content_empty_section(self):
8181
def test_forum_section_parser_from_content_unrelated_section(self):
8282
content = self.load_resource(self.FILE_UNRELATED_SECTION)
8383

84-
with self.assertRaises(InvalidContent):
84+
with self.assertRaises(InvalidContentError):
8585
ForumSectionParser.from_content(content)
8686

8787
# endregion
@@ -128,7 +128,7 @@ def test_forum_board_parser_from_content_empty_threads(self):
128128
def test_forum_board_parser_from_content_unrelated_section(self):
129129
content = self.load_resource(self.FILE_UNRELATED_SECTION)
130130

131-
with self.assertRaises(InvalidContent):
131+
with self.assertRaises(InvalidContentError):
132132
ForumBoardParser.from_content(content)
133133

134134
def test_forum_board_parser_from_content_invalid_page(self):
@@ -246,7 +246,7 @@ def test_forum_announcement_from_content_not_found(self):
246246
def test_forum_announcement_from_content_unrelated_section(self):
247247
content = self.load_resource(self.FILE_UNRELATED_SECTION)
248248

249-
with self.assertRaises(InvalidContent):
249+
with self.assertRaises(InvalidContentError):
250250
ForumAnnouncementParser.from_content(content, 34)
251251

252252
# endregion
@@ -368,7 +368,7 @@ def test_forum_thread_parser_from_content_not_found(self):
368368
def test_forum_thread_parser_from_content_unrelated_section(self):
369369
content = self.load_resource(self.FILE_UNRELATED_SECTION)
370370

371-
with self.assertRaises(InvalidContent):
371+
with self.assertRaises(InvalidContentError):
372372
ForumThreadParser.from_content(content)
373373

374374
# endregion
@@ -423,7 +423,7 @@ def test_cm_post_archive_from_content_pages(self):
423423

424424
def test_cm_post_archive_from_content_unrelated_section(self):
425425
content = self.load_resource(self.FILE_UNRELATED_SECTION)
426-
with self.assertRaises(InvalidContent):
426+
with self.assertRaises(InvalidContentError):
427427
CMPostArchiveParser.from_content(content)
428428

429429
def test_cm_post_archive_get_page_url_negative_page(self):

tests/tests_guild.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import datetime
22

33
from tests.tests_tibiapy import TestCommons
4-
from tibiapy import InvalidContent
4+
from tibiapy import InvalidContentError
55
from tibiapy.builders import GuildBuilder
66
from tibiapy.models import Guild, GuildHouse, GuildWars
77
from tibiapy.parsers import GuildParser, GuildWarsParser, GuildsSectionParser
@@ -69,7 +69,7 @@ def test_guild_parser_from_content_not_found(self):
6969
def test_guild_parser_from_content_unrelated(self):
7070
"""Testing parsing an unrelated tibiacom section"""
7171
content = self.load_resource(self.FILE_UNRELATED_SECTION)
72-
with self.assertRaises(InvalidContent):
72+
with self.assertRaises(InvalidContentError):
7373
GuildParser.from_content(content)
7474

7575

@@ -143,7 +143,7 @@ def test_guilds_section_parser_from_content_not_found(self):
143143
def test_guilds_section_parser_from_content_unrelated(self):
144144
"""Testing parsing and unrelated section"""
145145
content = self.load_resource(self.FILE_UNRELATED_SECTION)
146-
with self.assertRaises(InvalidContent):
146+
with self.assertRaises(InvalidContentError):
147147
GuildsSectionParser.from_content(content)
148148

149149

tests/tests_highscores.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from tests.tests_tibiapy import TestCommons
2-
from tibiapy import InvalidContent
2+
from tibiapy import InvalidContentError
33
from tibiapy.enums import HighscoresBattlEyeType, HighscoresCategory, HighscoresProfession, Vocation
44
from tibiapy.models import Highscores, HighscoresEntry, LoyaltyHighscoresEntry
55
from tibiapy.parsers import HighscoresParser
@@ -117,7 +117,7 @@ def test_highscores_parser_from_content_no_results(self):
117117
def test_highscores_parser_from_content_unrelated_section(self):
118118
"""Testing parsing an unrelated section"""
119119
content = self.load_resource(self.FILE_UNRELATED_SECTION)
120-
with self.assertRaises(InvalidContent):
120+
with self.assertRaises(InvalidContentError):
121121
HighscoresParser.from_content(content)
122122

123123
# endregion

tests/tests_house.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from tests.tests_tibiapy import TestCommons
2-
from tibiapy import InvalidContent
2+
from tibiapy import InvalidContentError
33
from tibiapy.enums import HouseOrder, HouseStatus, HouseType
44
from tibiapy.models import House, HouseEntry, HousesSection
55
from tibiapy.parsers import HouseParser, HousesSectionParser
@@ -87,7 +87,7 @@ def test_house_parser_from_content_not_found(self):
8787
def test_house_parser_from_content_unrelated(self):
8888
"""Testing parsing an unrelated section"""
8989
content = self.load_resource(self.FILE_UNRELATED_SECTION)
90-
with self.assertRaises(InvalidContent):
90+
with self.assertRaises(InvalidContentError):
9191
HouseParser.from_content(content)
9292

9393
# endregion
@@ -161,7 +161,7 @@ def test_houses_section_parser_from_content_not_found(self):
161161
def test_houses_section_parser_from_content_unrelated(self):
162162
"""Testing parsing an unrelated section"""
163163
content = self.load_resource(self.FILE_UNRELATED_SECTION)
164-
with self.assertRaises(InvalidContent):
164+
with self.assertRaises(InvalidContentError):
165165
HousesSectionParser.from_content(content)
166166

167167
# endregion

tests/tests_kill_statistics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from tests.tests_tibiapy import TestCommons
2-
from tibiapy import InvalidContent
2+
from tibiapy import InvalidContentError
33
from tibiapy.parsers import KillStatisticsParser
44

55
FILE_KILL_STATISTICS_FULL = "killStatistics/killStatisticsWithResults.txt"
@@ -51,5 +51,5 @@ def test_kill_statistics_from_parser_content_not_found(self):
5151
def test_kill_statistics_from_parser_content_unrelated_section(self):
5252
"""Testing parsing an unrelated section"""
5353
content = self.load_resource(self.FILE_UNRELATED_SECTION)
54-
with self.assertRaises(InvalidContent):
54+
with self.assertRaises(InvalidContentError):
5555
KillStatisticsParser.from_content(content)

0 commit comments

Comments
 (0)