Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_subpathWriteFile(self):
expected_text = 'foo bar™⁜'
subpathWriteFile(expected_text, self.directory, self.filename)
with open(self.filepath, 'r', encoding='utf-8') as f:
text = f.read()
self.assertEqual(text, expected_text)
def _test_normalizeGlyphNames(self, oldGlyphMapping, expectedGlyphMapping):
import tempfile
directory = tempfile.mkdtemp()
layerDirectory = "glyphs"
fullLayerDirectory = subpathJoin(directory, layerDirectory)
os.mkdir(fullLayerDirectory)
for fileName in oldGlyphMapping.values():
subpathWriteFile("", directory, layerDirectory, fileName)
self.assertEqual(sorted(os.listdir(fullLayerDirectory)),
sorted(oldGlyphMapping.values()))
subpathWritePlist(oldGlyphMapping, directory, layerDirectory,
"contents.plist")
newGlyphMapping = normalizeGlyphNames(directory, layerDirectory)
listing = os.listdir(fullLayerDirectory)
listing.remove("contents.plist")
self.assertEqual(sorted(listing), sorted(newGlyphMapping.values()))
self.assertEqual(
subpathReadPlist(directory, layerDirectory, "contents.plist"),
newGlyphMapping)
shutil.rmtree(directory)
return newGlyphMapping == expectedGlyphMapping
def test_subpathWriteFile(self):
expected_text = 'foo bar™⁜'
subpathWriteFile(expected_text, self.directory, self.filename)
with open(self.filepath, 'r', encoding='utf-8') as f:
text = f.read()
self.assertEqual(text, expected_text)
def test_subpathWriteFile_newline(self):
mixed_eol_text = 'foo\r\nbar\nbaz\rquz'
expected_text = 'foo\nbar\nbaz\nquz'
subpathWriteFile(mixed_eol_text, self.directory, self.filename)
with open(self.filepath, 'r', encoding='utf-8') as f:
text = f.read()
self.assertEqual(text, expected_text)
def _test_normalizeGlyphNames(self, oldGlyphMapping, expectedGlyphMapping):
import tempfile
directory = tempfile.mkdtemp()
layerDirectory = "glyphs"
fullLayerDirectory = subpathJoin(directory, layerDirectory)
os.mkdir(fullLayerDirectory)
for fileName in oldGlyphMapping.values():
subpathWriteFile("", directory, layerDirectory, fileName)
self.assertEqual(sorted(os.listdir(fullLayerDirectory)),
sorted(oldGlyphMapping.values()))
subpathWritePlist(oldGlyphMapping, directory, layerDirectory,
"contents.plist")
newGlyphMapping = normalizeGlyphNames(directory, layerDirectory)
listing = os.listdir(fullLayerDirectory)
listing.remove("contents.plist")
self.assertEqual(sorted(listing), sorted(newGlyphMapping.values()))
self.assertEqual(
subpathReadPlist(directory, layerDirectory, "contents.plist"),
newGlyphMapping)
shutil.rmtree(directory)
return newGlyphMapping == expectedGlyphMapping
org.robofab.fontlab.customdata
<data>
gAJ9cQFVA2xpYnECY3BsaXN0bGliCl9JbnRlcm5hbERpY3QKcQMpgXEEVSdj
b20uc2NocmlmdGdlc3RhbHR1bmcuR2x5cGhzLmxhc3RDaGFuZ2VxBVUTMjAx
Ny8wOS8yNiAwOToxMzoyMXEGc31xB2JzLg==
</data>
"""
with TemporaryDirectory(suffix=".ufo") as indir:
outdir = os.path.join(indir, 'output.ufo')
subpathWriteFile(metainfo, indir, "metainfo.plist")
subpathWriteFile(libdata, indir, "lib.plist")
main(["-o", outdir, indir])
data = subpathReadPlist(outdir, "lib.plist")
self.assertEqual(
data['org.robofab.fontlab.customdata'],
base64.b64decode("""\
gAJ9cQFVA2xpYnECY3BsaXN0bGliCl9JbnRlcm5hbERpY3QKcQMpgXEEVSdj
def test_main_float_precision_argument(self):
metainfo = METAINFO_PLIST % 3
libdata = """
test_float
0.3333333333333334
"""
with TemporaryDirectory(suffix=".ufo") as indir:
outdir = os.path.join(indir, 'output.ufo')
subpathWriteFile(metainfo, indir, "metainfo.plist")
subpathWriteFile(libdata, indir, "lib.plist")
# without --float-precision, it uses 10 decimal digits by default
main(["-o", outdir, indir])
data = subpathReadPlist(outdir, "lib.plist")
self.assertEqual(data["test_float"], 0.3333333333)
main(["-o", outdir, "--float-precision=0", indir])
data = subpathReadPlist(outdir, "lib.plist")
self.assertEqual(data["test_float"], 0)
main(["-o", outdir, "--float-precision=6", indir])
data = subpathReadPlist(outdir, "lib.plist")
self.assertEqual(data["test_float"], 0.333333)
# -1 means no rounding, use repr()
org.robofab.fontlab.customdata
<data>
gAJ9cQFVA2xpYnECY3BsaXN0bGliCl9JbnRlcm5hbERpY3QKcQMpgXEEVSdj
b20uc2NocmlmdGdlc3RhbHR1bmcuR2x5cGhzLmxhc3RDaGFuZ2VxBVUTMjAx
Ny8wOS8yNiAwOToxMzoyMXEGc31xB2JzLg==
</data>
"""
with TemporaryDirectory(suffix=".ufo") as indir:
outdir = os.path.join(indir, 'output.ufo')
subpathWriteFile(metainfo, indir, "metainfo.plist")
subpathWriteFile(libdata, indir, "lib.plist")
main(["-o", outdir, indir])
data = subpathReadPlist(outdir, "lib.plist")
self.assertEqual(
data['org.robofab.fontlab.customdata'],
base64.b64decode("""\
gAJ9cQFVA2xpYnECY3BsaXN0bGliCl9JbnRlcm5hbERpY3QKcQMpgXEEVSdj