summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Godfrey-Kittle <jamesgk@google.com>2015-09-29 17:46:32 -0700
committerJames Godfrey-Kittle <jamesgk@google.com>2015-09-29 17:46:32 -0700
commit26990b6f5a8170656a0064e49b2c9b7a4f9b8d54 (patch)
tree26ba545000df0387940c3c4a9c5b7b43c33e9602
parentbdf6327ad72f162ca16a16c446d2093ffb75f143 (diff)
Generalize coverage tests in common_tests
-rw-r--r--scripts/common_tests.py33
-rwxr-xr-xscripts/run_android_tests.py66
-rwxr-xr-xscripts/run_general_tests.py9
-rwxr-xr-xscripts/run_web_tests.py9
4 files changed, 41 insertions, 76 deletions
diff --git a/scripts/common_tests.py b/scripts/common_tests.py
index f30afa0..a744482 100644
--- a/scripts/common_tests.py
+++ b/scripts/common_tests.py
@@ -295,39 +295,22 @@ class TestCharacterCoverage(FontTest):
def setUp(self):
_, self.fonts = self.loaded_fonts
- self.LEGACY_PUA = frozenset({0xEE01, 0xEE02, 0xF6C3})
- def test_inclusion_of_legacy_pua(self):
- """Tests that legacy PUA characters remain in the fonts."""
- for font in self.fonts:
- charset = coverage.character_set(font)
- for char in self.LEGACY_PUA:
- self.assertIn(char, charset)
+ def test_inclusion(self):
+ """Tests for characters which should be included."""
- def test_non_inclusion_of_other_pua(self):
- """Tests that there are not other PUA characters except legacy ones."""
for font in self.fonts:
charset = coverage.character_set(font)
- pua_chars = {
- char for char in charset
- if 0xE000 <= char <= 0xF8FF or 0xF0000 <= char <= 0x10FFFF}
- self.assertTrue(pua_chars <= self.LEGACY_PUA)
+ for char in self.include:
+ self.assertIn(char, charset)
- def test_lack_of_unassigned_chars(self):
- """Tests that unassigned characters are not in the fonts."""
- for font in self.fonts:
- charset = coverage.character_set(font)
- self.assertNotIn(0x2072, charset)
- self.assertNotIn(0x2073, charset)
- self.assertNotIn(0x208F, charset)
+ def test_exclusion(self):
+ """Tests that characters which should be excluded are absent."""
- def test_inclusion_of_sound_recording_copyright(self):
- """Tests that sound recording copyright symbol is in the fonts."""
for font in self.fonts:
charset = coverage.character_set(font)
- self.assertIn(
- 0x2117, charset, # SOUND RECORDING COPYRIGHT
- 'U+2117 not found in %s.' % font_data.font_name(font))
+ for char in self.exclude:
+ self.assertNotIn(char, charset)
class TestLigatures(FontTest):
diff --git a/scripts/run_android_tests.py b/scripts/run_android_tests.py
index e978343..3dfe3db 100755
--- a/scripts/run_android_tests.py
+++ b/scripts/run_android_tests.py
@@ -25,14 +25,12 @@ from nototools import coverage
from nototools import font_data
from nototools import render
from nototools import unicode_data
+import common_tests
-def load_fonts():
- """Load all fonts built for Android."""
- all_font_files = glob.glob('out/android/*.ttf')
- all_fonts = [ttLib.TTFont(font) for font in all_font_files]
- assert len(all_font_files) == 18
- return all_font_files, all_fonts
+FONTS = common_tests.load_fonts(
+ ['out/android/*.ttf'],
+ expected_count=18)
class TestVerticalMetrics(unittest.TestCase):
@@ -66,52 +64,20 @@ class TestDigitWidths(unittest.TestCase):
self.assertEqual(len(set(widths)), 1)
-class TestCharacterCoverage(unittest.TestCase):
- """Tests character coverage."""
+class TestCharacterCoverage(common_tests.TestCharacterCoverage):
+ loaded_fonts = FONTS
- def setUp(self):
- _, self.fonts = load_fonts()
- self.LEGACY_PUA = frozenset({0xEE01, 0xEE02, 0xF6C3})
-
- def test_lack_of_arrows_and_combining_keycap(self):
- """Tests that arrows and combining keycap are not in the fonts."""
- for font in self.fonts:
- charset = coverage.character_set(font)
- self.assertNotIn(0x20E3, charset) # COMBINING ENCLOSING KEYCAP
- self.assertNotIn(0x2191, charset) # UPWARDS ARROW
- self.assertNotIn(0x2193, charset) # DOWNWARDS ARROW
-
- def test_lack_of_unassigned_chars(self):
- """Tests that unassigned characters are not in the fonts."""
- for font in self.fonts:
- charset = coverage.character_set(font)
- self.assertNotIn(0x2072, charset)
- self.assertNotIn(0x2073, charset)
- self.assertNotIn(0x208F, charset)
+ include = frozenset([
+ 0x2117, # SOUND RECORDING COPYRIGHT
+ 0xEE01, 0xEE02, 0xF6C3]) # legacy PUA
- def test_inclusion_of_sound_recording_copyright(self):
- """Tests that sound recording copyright symbol is in the fonts."""
- for font in self.fonts:
- charset = coverage.character_set(font)
- self.assertIn(
- 0x2117, charset, # SOUND RECORDING COPYRIGHT
- 'U+2117 not found in %s.' % font_data.font_name(font))
-
- def test_inclusion_of_legacy_pua(self):
- """Tests that legacy PUA characters remain in the fonts."""
- for font in self.fonts:
- charset = coverage.character_set(font)
- for char in self.LEGACY_PUA:
- self.assertIn(char, charset)
-
- def test_non_inclusion_of_other_pua(self):
- """Tests that there are not other PUA characters except legacy ones."""
- for font in self.fonts:
- charset = coverage.character_set(font)
- pua_chars = {
- char for char in charset
- if 0xE000 <= char <= 0xF8FF or 0xF0000 <= char <= 0x10FFFF}
- self.assertTrue(pua_chars <= self.LEGACY_PUA)
+ exclude = frozenset([
+ 0x20E3, # COMBINING ENCLOSING KEYCAP
+ 0x2191, # UPWARDS ARROW
+ 0x2193, # DOWNWARDS ARROW
+ 0x2072, 0x2073, 0x208F] + # unassigned characters
+ range(0xE000, 0xF8FF + 1) + range(0xF0000, 0x10FFFF + 1) # other PUA
+ ) - include # don't exclude legacy PUA
class TestSpacingMarks(unittest.TestCase):
diff --git a/scripts/run_general_tests.py b/scripts/run_general_tests.py
index 7ec8fcc..6105849 100755
--- a/scripts/run_general_tests.py
+++ b/scripts/run_general_tests.py
@@ -54,6 +54,15 @@ class TestDigitWidths(common_tests.TestDigitWidths):
class TestCharacterCoverage(common_tests.TestCharacterCoverage):
loaded_fonts = FONTS
+ include = frozenset([
+ 0x2117, # SOUND RECORDING COPYRIGHT
+ 0xEE01, 0xEE02, 0xF6C3]) # legacy PUA
+
+ exclude = frozenset([
+ 0x2072, 0x2073, 0x208F] + # unassigned characters
+ range(0xE000, 0xF8FF + 1) + range(0xF0000, 0x10FFFF + 1) # other PUA
+ ) - include # don't exclude legacy PUA
+
class TestLigatures(common_tests.TestLigatures):
loaded_fonts = FONTS
diff --git a/scripts/run_web_tests.py b/scripts/run_web_tests.py
index 8ec42be..c6e0aa3 100755
--- a/scripts/run_web_tests.py
+++ b/scripts/run_web_tests.py
@@ -53,7 +53,14 @@ class TestDigitWidths(common_tests.TestDigitWidths):
class TestCharacterCoverage(common_tests.TestCharacterCoverage):
loaded_fonts = FONTS
- test_inclusion_of_sound_recording_copyright = None
+
+ include = frozenset([
+ 0xEE01, 0xEE02, 0xF6C3]) # legacy PUA
+
+ exclude = frozenset([
+ 0x2072, 0x2073, 0x208F] + # unassigned characters
+ range(0xE000, 0xF8FF + 1) + range(0xF0000, 0x10FFFF + 1) # other PUA
+ ) - include # don't exclude legacy PUA
class TestVerticalMetrics(common_tests.TestVerticalMetrics):