5 # A single test in a subset test suite. Identifies a font
6 # a subsetting profile, and a subset to be cut.
8 def __init__(self, font_path, profile_path, subset):
9 self.font_path = font_path
10 self.profile_path = profile_path
14 if self.subset == '*':
17 return ",".join("%X" % ord(c) for (i, c) in enumerate(self.subset))
19 def get_profile_flags(self):
20 with open (self.profile_path, mode="r", encoding="utf-8") as f:
21 return f.read().splitlines()
23 def get_font_name(self):
24 font_base_name = os.path.basename(self.font_path)
25 font_base_name_parts = os.path.splitext(font_base_name)
26 profile_name = os.path.splitext(os.path.basename(self.profile_path))[0]
28 if self.unicodes() == "*":
29 return "%s.%s.retain-all-codepoint%s" % (font_base_name_parts[0],
31 font_base_name_parts[1])
33 return "%s.%s.%s%s" % (font_base_name_parts[0],
36 font_base_name_parts[1])
38 def get_font_extension(self):
39 font_base_name = os.path.basename(self.font_path)
40 font_base_name_parts = os.path.splitext(font_base_name)
41 return font_base_name_parts[1]
43 # A group of tests to perform on the subsetter. Each test
44 # Identifies a font a subsetting profile, and a subset to be cut.
45 class SubsetTestSuite:
47 def __init__(self, test_path, definition):
48 self.test_path = test_path
52 self._parse(definition)
54 def get_output_directory(self):
55 test_name = os.path.splitext(os.path.basename(self.test_path))[0]
56 data_dir = os.path.join(os.path.dirname(self.test_path), "..")
58 output_dir = os.path.normpath(os.path.join(data_dir, "expected", test_name))
59 if not os.path.exists(output_dir):
61 if not os.path.isdir(output_dir):
62 raise Exception("%s is not a directory." % output_dir)
67 for font in self.fonts:
68 font = os.path.join(self._base_path(), "fonts", font)
69 for profile in self.profiles:
70 profile = os.path.join(self._base_path(), "profiles", profile)
71 for subset in self.subsets:
72 yield Test(font, profile, subset)
75 return os.path.dirname(os.path.dirname(self.test_path))
77 def _parse(self, definition):
80 "PROFILES:": self.profiles,
81 "SUBSETS:": self.subsets
84 current_destination = None
85 for line in definition.splitlines():
88 if line.startswith("#"):
94 if line in destinations:
95 current_destination = destinations[line]
96 elif current_destination is not None:
97 current_destination.append(line)
99 raise Exception("Failed to parse test suite file.")