summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJames Godfrey-Kittle <jamesgk@google.com>2015-09-29 17:57:37 -0700
committerJames Godfrey-Kittle <jamesgk@google.com>2015-09-29 17:59:14 -0700
commit24632ad9ef96131a86b5a099f2eb59888df1cc5f (patch)
tree1a15d8d671bfeadadc242b84d3c307c0ae10524a /scripts
parent26990b6f5a8170656a0064e49b2c9b7a4f9b8d54 (diff)
Generalize and move vertical metrics tests
Diffstat (limited to 'scripts')
-rw-r--r--scripts/common_tests.py31
-rwxr-xr-xscripts/run_android_tests.py17
-rwxr-xr-xscripts/run_general_tests.py5
-rwxr-xr-xscripts/run_web_tests.py22
4 files changed, 45 insertions, 30 deletions
diff --git a/scripts/common_tests.py b/scripts/common_tests.py
index a744482..dc24f38 100644
--- a/scripts/common_tests.py
+++ b/scripts/common_tests.py
@@ -362,9 +362,6 @@ class TestFeatures(FontTest):
u''.join(chars_with_no_smcp).encode('UTF-8')))
-EXPECTED_YMIN = -555
-EXPECTED_YMAX = 2163
-
class TestVerticalMetrics(FontTest):
"""Test the vertical metrics of fonts."""
@@ -378,8 +375,8 @@ class TestVerticalMetrics(FontTest):
"""
for font in self.fonts:
head_table = font['head']
- self.assertEqual(head_table.yMin, EXPECTED_YMIN)
- self.assertEqual(head_table.yMax, EXPECTED_YMAX)
+ self.assertEqual(head_table.yMin, self.expected_head_yMin)
+ self.assertEqual(head_table.yMax, self.expected_head_yMax)
def test_glyphs_ymin_ymax(self):
"""Tests yMin and yMax of all glyphs to not go outside the range."""
@@ -393,7 +390,8 @@ class TestVerticalMetrics(FontTest):
continue
self.assertTrue(
- EXPECTED_YMIN <= y_min and y_max <= EXPECTED_YMAX,
+ self.expected_head_yMin <= y_min and
+ y_max <= self.expected_head_yMax,
('The vertical metrics for glyph %s in %s exceed the '
'acceptable range: yMin=%d, yMax=%d' % (
glyph_name, font_file, y_min, y_max)))
@@ -403,9 +401,24 @@ class TestVerticalMetrics(FontTest):
"""
for font in self.fonts:
hhea_table = font['hhea']
- self.assertEqual(hhea_table.descent, -500)
- self.assertEqual(hhea_table.ascent, 1900)
- self.assertEqual(hhea_table.lineGap, 0)
+ self.assertEqual(hhea_table.descent, self.expected_hhea_descent)
+ self.assertEqual(hhea_table.ascent, self.expected_hhea_ascent)
+ self.assertEqual(hhea_table.lineGap, self.expected_hhea_lineGap)
+
+ def test_os2_metrics(self):
+ """Tests OS/2 vertical metrics to be equal to the old values."""
+ for font in self.fonts:
+ os2_table = font['OS/2']
+ self.assertEqual(os2_table.sTypoDescender,
+ self.expected_os2_sTypoDescender)
+ self.assertEqual(os2_table.sTypoAscender,
+ self.expected_os2_sTypoAscender)
+ self.assertEqual(os2_table.sTypoLineGap,
+ self.expected_os2_sTypoLineGap)
+ self.assertEqual(os2_table.usWinDescent,
+ self.expected_os2_usWinDescent)
+ self.assertEqual(os2_table.usWinAscent,
+ self.expected_os2_usWinAscent)
class TestGlyphAreas(unittest.TestCase):
diff --git a/scripts/run_android_tests.py b/scripts/run_android_tests.py
index 3dfe3db..2ca9231 100755
--- a/scripts/run_android_tests.py
+++ b/scripts/run_android_tests.py
@@ -33,18 +33,15 @@ FONTS = common_tests.load_fonts(
expected_count=18)
-class TestVerticalMetrics(unittest.TestCase):
- """Test the vertical metrics of fonts."""
+class TestVerticalMetrics(common_tests.TestVerticalMetrics):
+ loaded_fonts = FONTS
+ test_glyphs_ymin_ymax = None
+ test_hhea_table_metrics = None
+ test_os2_metrics = None
- def setUp(self):
- _, self.fonts = load_fonts()
+ expected_head_yMin = -555
+ expected_head_yMax = 2163
- def test_ymin_ymax(self):
- """Tests yMin and yMax to be equal to what Android expects."""
- for font in self.fonts:
- head_table = font['head']
- self.assertEqual(head_table.yMin, -555)
- self.assertEqual(head_table.yMax, 2163)
class TestDigitWidths(unittest.TestCase):
diff --git a/scripts/run_general_tests.py b/scripts/run_general_tests.py
index 6105849..30445cd 100755
--- a/scripts/run_general_tests.py
+++ b/scripts/run_general_tests.py
@@ -76,6 +76,10 @@ class TestVerticalMetrics(common_tests.TestVerticalMetrics):
loaded_fonts = FONTS
test_ymin_ymax = None
test_hhea_table_metrics = None
+ test_os2_metrics = None
+
+ expected_head_yMin = -555
+ expected_head_yMax = 2163
class TestGlyphAreas(common_tests.TestGlyphAreas):
@@ -85,4 +89,3 @@ class TestGlyphAreas(common_tests.TestGlyphAreas):
if __name__ == '__main__':
unittest.main()
-
diff --git a/scripts/run_web_tests.py b/scripts/run_web_tests.py
index c6e0aa3..1c88537 100755
--- a/scripts/run_web_tests.py
+++ b/scripts/run_web_tests.py
@@ -66,15 +66,18 @@ class TestCharacterCoverage(common_tests.TestCharacterCoverage):
class TestVerticalMetrics(common_tests.TestVerticalMetrics):
loaded_fonts = FONTS
- def test_os2_metrics(self):
- """Tests OS/2 vertical metrics to be equal to the old values."""
- for font in self.fonts:
- os2_table = font['OS/2']
- self.assertEqual(os2_table.sTypoDescender, -512)
- self.assertEqual(os2_table.sTypoAscender, 1536)
- self.assertEqual(os2_table.sTypoLineGap, 102)
- self.assertEqual(os2_table.usWinDescent, 512)
- self.assertEqual(os2_table.usWinAscent, 1946)
+ expected_head_yMin = -555
+ expected_head_yMax = 2163
+
+ expected_hhea_descent = -500
+ expected_hhea_ascent = 1900
+ expected_hhea_lineGap = 0
+
+ expected_os2_sTypoDescender = -512
+ expected_os2_sTypoAscender = 1536
+ expected_os2_sTypoLineGap = 102
+ expected_os2_usWinDescent = 512
+ expected_os2_usWinAscent = 1946
class TestLigatures(common_tests.TestLigatures):
@@ -115,4 +118,3 @@ class TestHints(unittest.TestCase):
if __name__ == '__main__':
unittest.main()
-