Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
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()
main(["-o", outdir, "--float-precision=-1", indir])
data = subpathReadPlist(outdir, "lib.plist")
self.assertEqual(data["test_float"], 0.3333333333333334)
def test_subpathReadPlist(self):
data = dict([('a', 'foo'), ('b', 'bar'), ('c', '™')])
with open(self.plistpath, 'wb') as f:
f.write(dumps(data))
self.assertEqual(subpathReadPlist(self.directory, self.plistname),
data)
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
<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
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_subpathReadPlist(self):
data = dict([('a', 'foo'), ('b', 'bar'), ('c', '™')])
with open(self.plistpath, 'wb') as f:
f.write(dumps(data))
self.assertEqual(subpathReadPlist(self.directory, self.plistname),
data)
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()
main(["-o", outdir, "--float-precision=-1", indir])
data = subpathReadPlist(outdir, "lib.plist")
self.assertEqual(data["test_float"], 0.3333333333333334)