Skip to content

Commit

Permalink
Fix SCRIPT font family in Kiva (#975)
Browse files Browse the repository at this point in the history
* Add a test for #971

This should fail CI.

* Fix bug and clean-up style.
  • Loading branch information
corranwebster committed Aug 8, 2022
1 parent f2899c9 commit e62f176
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion kiva/fonttools/font.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class Font(object):
ROMAN: "serif",
MODERN: "sans-serif",
DECORATIVE: "fantasy",
SCRIPT: "script",
SCRIPT: "cursive",
TELETYPE: "monospace",
}

Expand Down
22 changes: 20 additions & 2 deletions kiva/fonttools/tests/test_font.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
import unittest

from kiva.constants import (
BOLD, BOLD_ITALIC, DEFAULT, ITALIC, MODERN, NORMAL, ROMAN, WEIGHT_BOLD,
WEIGHT_LIGHT, WEIGHT_NORMAL, SWISS,
BOLD, BOLD_ITALIC, DECORATIVE, DEFAULT, ITALIC, MODERN, NORMAL, ROMAN,
SCRIPT, TELETYPE, WEIGHT_BOLD, WEIGHT_LIGHT, WEIGHT_NORMAL, SWISS,
)
from kiva.fonttools._constants import font_family_aliases, preferred_fonts
from kiva.fonttools.tests._testing import patch_global_font_manager
from kiva.fonttools.font import (
DECORATIONS, FAMILIES, NOISE, STYLES, WEIGHTS, Font, str_to_font,
Expand Down Expand Up @@ -193,6 +194,23 @@ def test_font_query_warnings(self):
self.assertEqual(query.get_weight(), WEIGHT_LIGHT)
self.assertEqual(query.get_style(), "italic")

def test_family_queries(self):
# regression test for Enable #971
# this ensures every font family creates a valid query populated
# with query families that work
families = [
DECORATIVE, DEFAULT, MODERN, ROMAN, SCRIPT, SWISS, TELETYPE
]
for family in families:
with self.subTest(family=family):
font = Font(family=family)
query = font._make_font_query()
query_family = query.get_family()[0]

self.assertEqual(query_family, Font.familymap.get(family))
self.assertIn(query_family, font_family_aliases)
self.assertIn(query_family, preferred_fonts)


class TestSimpleParser(unittest.TestCase):

Expand Down

0 comments on commit e62f176

Please sign in to comment.