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_subpathWritePlist(self):
expected_data = dict([('a', 'foo'), ('b', 'bar'), ('c', '™')])
subpathWritePlist(expected_data, self.directory, self.plistname)
with open(self.plistpath, 'rb') as f:
data = loads(f.read())
self.assertEqual(data, expected_data)
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_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_subpathWritePlist(self):
expected_data = dict([('a', 'foo'), ('b', 'bar'), ('c', '™')])
subpathWritePlist(expected_data, self.directory, self.plistname)
with open(self.plistpath, 'rb') as f:
data = loads(f.read())
self.assertEqual(data, expected_data)
def _test_normalizeGlyphsDirectoryNames(self, oldLayers, expectedLayers):
directory = tempfile.mkdtemp()
for layerName, subDirectory in oldLayers:
os.mkdir(os.path.join(directory, subDirectory))
self.assertEqual(
sorted(os.listdir(directory)),
sorted([oldDirectory for oldName, oldDirectory in oldLayers]))
subpathWritePlist(oldLayers, directory, "layercontents.plist")
newLayers = normalizeGlyphsDirectoryNames(directory)
listing = os.listdir(directory)
listing.remove("layercontents.plist")
self.assertEqual(
sorted(listing),
sorted([newDirectory for newName, newDirectory in newLayers]))
shutil.rmtree(directory)
return newLayers == expectedLayers
def _test_normalizeGlyphsDirectoryNames(self, oldLayers, expectedLayers):
directory = tempfile.mkdtemp()
for layerName, subDirectory in oldLayers:
os.mkdir(os.path.join(directory, subDirectory))
self.assertEqual(
sorted(os.listdir(directory)),
sorted([oldDirectory for oldName, oldDirectory in oldLayers]))
subpathWritePlist(oldLayers, directory, "layercontents.plist")
newLayers = normalizeGlyphsDirectoryNames(directory)
listing = os.listdir(directory)
listing.remove("layercontents.plist")
self.assertEqual(
sorted(listing),
sorted([newDirectory for newName, newDirectory in newLayers]))
shutil.rmtree(directory)
return newLayers == expectedLayers