diff options
Diffstat (limited to 'Lib/fontTools/misc/testTools.py')
-rw-r--r-- | Lib/fontTools/misc/testTools.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/fontTools/misc/testTools.py b/Lib/fontTools/misc/testTools.py index db316a82..871a9951 100644 --- a/Lib/fontTools/misc/testTools.py +++ b/Lib/fontTools/misc/testTools.py @@ -3,10 +3,12 @@ from collections.abc import Iterable from io import BytesIO import os +import re import shutil import sys import tempfile from unittest import TestCase as _TestCase +from fontTools.config import Config from fontTools.misc.textTools import tobytes from fontTools.misc.xmlWriter import XMLWriter @@ -52,6 +54,7 @@ class FakeFont: self.reverseGlyphOrderDict_ = {g: i for i, g in enumerate(glyphs)} self.lazy = False self.tables = {} + self.cfg = Config() def __getitem__(self, tag): return self.tables[tag] @@ -133,6 +136,31 @@ def getXML(func, ttFont=None): return xml.splitlines() +def stripVariableItemsFromTTX( + string: str, + ttLibVersion: bool = True, + checkSumAdjustment: bool = True, + modified: bool = True, + created: bool = True, + sfntVersion: bool = False, # opt-in only +) -> str: + """Strip stuff like ttLibVersion, checksums, timestamps, etc. from TTX dumps.""" + # ttlib changes with the fontTools version + if ttLibVersion: + string = re.sub(' ttLibVersion="[^"]+"', "", string) + # sometimes (e.g. some subsetter tests) we don't care whether it's OTF or TTF + if sfntVersion: + string = re.sub(' sfntVersion="[^"]+"', "", string) + # head table checksum and creation and mod date changes with each save. + if checkSumAdjustment: + string = re.sub('<checkSumAdjustment value="[^"]+"/>', "", string) + if modified: + string = re.sub('<modified value="[^"]+"/>', "", string) + if created: + string = re.sub('<created value="[^"]+"/>', "", string) + return string + + class MockFont(object): """A font-like object that automatically adds any looked up glyphname to its glyphOrder.""" |