summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorRoozbeh Pournader <roozbeh@google.com>2014-07-24 18:41:33 -0700
committerRoozbeh Pournader <roozbeh@google.com>2014-07-24 18:41:33 -0700
commita8df15d7b96363a6652c5fd4d6dd95db99647326 (patch)
tree9e190c3d0a1c123e06b04e591955be8fe7392eba /scripts
parent3a8f38ed8e34c6021444f2ef43527a8f3ded09df (diff)
Add the beginning of a test infrastructure.
We now test for expected values of yMin and yMax, and equal widths for digits.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/run_android_tests.py49
1 files changed, 49 insertions, 0 deletions
diff --git a/scripts/run_android_tests.py b/scripts/run_android_tests.py
new file mode 100644
index 0000000..7880039
--- /dev/null
+++ b/scripts/run_android_tests.py
@@ -0,0 +1,49 @@
+#!/usr/bin/python
+"""Test assumptions that Android relies on."""
+
+import glob
+import unittest
+
+from fontTools import ttLib
+
+
+def load_fonts():
+ """Load all fonts built for Android."""
+ all_fonts = glob.glob('out/android/*.ttf')
+ all_fonts = [ttLib.TTFont(font) for font in all_fonts]
+ return all_fonts
+
+
+class TestVerticalMetrics(unittest.TestCase):
+ """Test the vertical metrics of fonts."""
+
+ def setUp(self):
+ self.fonts = load_fonts()
+
+ 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):
+ """Tests the width of digits."""
+
+ def setUp(self):
+ self.fonts = load_fonts()
+ self.digits = [
+ 'zero', 'one', 'two', 'three', 'four',
+ 'five', 'six', 'seven', 'eight', 'nine']
+
+ def test_digit_widths(self):
+ """Tests all decimal digits to make sure they have the same width."""
+ for font in self.fonts:
+ hmtx_table = font['hmtx']
+ widths = [hmtx_table[digit][0] for digit in self.digits]
+ self.assertEqual(len(set(widths)), 1)
+
+
+if __name__ == '__main__':
+ unittest.main()