Skip to content

Commit 1146a3a

Browse files
committed
Improved version checks when in font outline tests.
1 parent 9087d3e commit 1146a3a

File tree

1 file changed

+48
-16
lines changed

1 file changed

+48
-16
lines changed

test/font_test.py

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,9 @@ def test_point_size_method(self):
688688
self.assertRaises(ValueError, f.set_point_size, -500)
689689
self.assertRaises(TypeError, f.set_point_size, "15")
690690

691+
@unittest.skipIf(
692+
pygame.font.get_sdl_ttf_version() < (2, 0, 12), "outlines were added in SDL_TTF 2.0.12"
693+
)
691694
def test_outline_property(self):
692695
if pygame_font.__name__ == "pygame.ftfont":
693696
return # not a pygame.ftfont feature
@@ -698,14 +701,6 @@ def test_outline_property(self):
698701
)
699702
f = pygame_font.Font(pathlib.Path(font_path), 25)
700703

701-
ttf_version = pygame_font.get_sdl_ttf_version()
702-
if ttf_version < (2, 0, 12):
703-
with self.assertRaises(pygame.error):
704-
f.outline = 0
705-
with self.assertRaises(pygame.error):
706-
_ = f.outline
707-
return
708-
709704
# Default outline should be an integer >= 0 (typically 0)
710705
self.assertIsInstance(f.outline, int)
711706
self.assertGreaterEqual(f.outline, 0)
@@ -727,7 +722,10 @@ def test_incorrect_type():
727722
self.assertRaises(ValueError, test_neg)
728723
self.assertRaises(TypeError, test_incorrect_type)
729724

730-
def test_outline_method(self):
725+
@unittest.skipIf(
726+
pygame.font.get_sdl_ttf_version() >= (2, 0, 12), "outlines were added in SDL_TTF 2.0.12"
727+
)
728+
def test_outline_property_stub(self):
731729
if pygame_font.__name__ == "pygame.ftfont":
732730
return # not a pygame.ftfont feature
733731

@@ -737,11 +735,24 @@ def test_outline_method(self):
737735
)
738736
f = pygame_font.Font(pathlib.Path(font_path), 25)
739737

740-
ttf_version = pygame_font.get_sdl_ttf_version()
741-
if ttf_version < (2, 0, 12):
742-
self.assertRaises(pygame.error, f.get_outline)
743-
self.assertRaises(pygame.error, f.set_outline, 1)
744-
return
738+
with self.assertRaises(pygame.error):
739+
f.outline = 0
740+
with self.assertRaises(pygame.error):
741+
_ = f.outline
742+
743+
744+
@unittest.skipIf(
745+
pygame.font.get_sdl_ttf_version() < (2, 0, 12), "outlines were added in SDL_TTF 2.0.12"
746+
)
747+
def test_outline_method(self):
748+
if pygame_font.__name__ == "pygame.ftfont":
749+
return # not a pygame.ftfont feature
750+
751+
pygame_font.init()
752+
font_path = os.path.join(
753+
os.path.split(pygame.__file__)[0], pygame_font.get_default_font()
754+
)
755+
f = pygame_font.Font(pathlib.Path(font_path), 25)
745756

746757
val0 = f.get_outline()
747758
self.assertIsInstance(val0, int)
@@ -752,6 +763,22 @@ def test_outline_method(self):
752763
self.assertRaises(ValueError, f.set_outline, -1)
753764
self.assertRaises(TypeError, f.set_outline, "2")
754765

766+
@unittest.skipIf(
767+
pygame.font.get_sdl_ttf_version() >= (2, 0, 12), "outlines were added in SDL_TTF 2.0.12"
768+
)
769+
def test_outline_method_stub(self):
770+
if pygame_font.__name__ == "pygame.ftfont":
771+
return # not a pygame.ftfont feature
772+
773+
pygame_font.init()
774+
font_path = os.path.join(
775+
os.path.split(pygame.__file__)[0], pygame_font.get_default_font()
776+
)
777+
f = pygame_font.Font(pathlib.Path(font_path), 25)
778+
779+
self.assertRaises(pygame.error, f.get_outline)
780+
self.assertRaises(pygame.error, f.set_outline, 1)
781+
755782
def test_font_name(self):
756783
f = pygame_font.Font(None, 20)
757784
self.assertEqual(f.name, "FreeSans")
@@ -1208,15 +1235,17 @@ def query(
12081235
f.set_italic(italic)
12091236
f.set_underline(underline)
12101237
f.set_strikethrough(strikethrough)
1211-
f.set_outline(outline)
1238+
if pygame.font.get_sdl_ttf_version() >= (2, 0, 12):
1239+
f.set_outline(outline)
12121240
s = f.render(text, antialiase, (0, 0, 0))
12131241
screen.blit(s, (offset, y))
12141242
y += s.get_size()[1] + spacing
12151243
f.set_bold(False)
12161244
f.set_italic(False)
12171245
f.set_underline(False)
12181246
f.set_strikethrough(False)
1219-
f.set_outline(0)
1247+
if pygame.font.get_sdl_ttf_version() >= (2, 0, 12):
1248+
f.set_outline(0)
12201249
s = f.render("(some comparison text)", False, (0, 0, 0))
12211250
screen.blit(s, (offset, y))
12221251
pygame.display.flip()
@@ -1258,6 +1287,9 @@ def test_italic_underline(self):
12581287
def test_bold_strikethrough(self):
12591288
self.assertTrue(self.query(bold=True, strikethrough=True))
12601289

1290+
@unittest.skipIf(
1291+
pygame.font.get_sdl_ttf_version() < (2, 0, 12), "outlines were added in SDL_TTF 2.0.12"
1292+
)
12611293
def test_outline(self):
12621294
self.assertTrue(self.query(outline=1))
12631295

0 commit comments

Comments
 (0)