From a8df15d7b96363a6652c5fd4d6dd95db99647326 Mon Sep 17 00:00:00 2001 From: Roozbeh Pournader Date: Thu, 24 Jul 2014 18:41:33 -0700 Subject: Add the beginning of a test infrastructure. We now test for expected values of yMin and yMax, and equal widths for digits. --- scripts/run_android_tests.py | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 scripts/run_android_tests.py (limited to 'scripts') 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() -- cgit v1.2.3