def _load(path: str) -> GSFont: '''Load `.glyphspackage` bundle. See [googlefonts/glyphsLib#643](https://github.com/googlefonts/glyphsLib/issues/643). ''' with open(os.path.join(path, 'fontinfo.plist'), 'r') as fontinfo_plist: fontinfo = fontinfo_plist.read() with open(os.path.join(path, 'order.plist'), 'r') as order_plist: order = Parser().parse(order_plist.read()) insert_pos = fontinfo.find('instances = (') glyphs = ',\n'.join(Font._read_glyph(path, name) for name in order) glyphs = f'glyphs = (\n{glyphs}\n);\n' return glyphsLib.loads(fontinfo[:insert_pos] + glyphs + fontinfo[insert_pos:-1])
def assertParseWriteRoundtrip(self, filename): with open(filename) as f: expected = f.read().splitlines() f.seek(0, 0) font = glyphsLib.load(f) actual = write_to_lines(font) # Roundtrip again to check idempotence font = glyphsLib.loads("\n".join(actual)) actual_idempotent = write_to_lines(font) # Assert idempotence first, because if that fails it's a big issue self.assertLinesEqual( actual, actual_idempotent, "The parser/writer should be idempotent. BIG PROBLEM!") self.assertLinesEqual( expected, actual, "The writer should output exactly what the parser read")