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
15 if self.subset == '*':
17 elif re.match("^U\+", self.subset):
18 s = re.sub (r"U\+", "", self.subset)
21 return ",".join("%X" % ord(c) for (i, c) in enumerate(self.subset))
23 def get_profile_flags(self):
24 with open (self.profile_path, mode="r", encoding="utf-8") as f:
25 return f.read().splitlines()
27 def get_font_name(self):
28 font_base_name = os.path.basename(self.font_path)
29 font_base_name_parts = os.path.splitext(font_base_name)
30 profile_name = os.path.splitext(os.path.basename(self.profile_path))[0]
32 if self.unicodes() == "*":
33 return "%s.%s.retain-all-codepoint%s" % (font_base_name_parts[0],
35 font_base_name_parts[1])
37 return "%s.%s.%s%s" % (font_base_name_parts[0],
40 font_base_name_parts[1])
42 def get_font_extension(self):
43 font_base_name = os.path.basename(self.font_path)
44 font_base_name_parts = os.path.splitext(font_base_name)
45 return font_base_name_parts[1]
47 # A group of tests to perform on the subsetter. Each test
48 # Identifies a font a subsetting profile, and a subset to be cut.
49 class SubsetTestSuite:
51 def __init__(self, test_path, definition):
52 self.test_path = test_path
56 self._parse(definition)
58 def get_output_directory(self):
59 test_name = os.path.splitext(os.path.basename(self.test_path))[0]
60 data_dir = os.path.join(os.path.dirname(self.test_path), "..")
62 output_dir = os.path.normpath(os.path.join(data_dir, "expected", test_name))
63 if not os.path.exists(output_dir):
65 if not os.path.isdir(output_dir):
66 raise Exception("%s is not a directory." % output_dir)
71 for font in self.fonts:
72 font = os.path.join(self._base_path(), "fonts", font)
73 for profile in self.profiles:
74 profile = os.path.join(self._base_path(), "profiles", profile)
75 for subset in self.subsets:
76 yield Test(font, profile, subset)
79 return os.path.dirname(os.path.dirname(self.test_path))
81 def _parse(self, definition):
84 "PROFILES:": self.profiles,
85 "SUBSETS:": self.subsets
88 current_destination = None
89 for line in definition.splitlines():
92 if line.startswith("#"):
98 if line in destinations:
99 current_destination = destinations[line]
100 elif current_destination is not None:
101 current_destination.append(line)
103 raise Exception("Failed to parse test suite file.")