/usr/lib/python3/dist-packages/ufoLib/test/test_UFO1.py is in python3-ufolib 2.1.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | # -*- coding: utf-8 -*-
import os
import shutil
import unittest
import tempfile
from io import open
from ufoLib import UFOReader, UFOWriter, UFOLibError
from ufoLib.plistlib import readPlist, writePlist
from ufoLib.test.testSupport import fontInfoVersion1, fontInfoVersion2
class TestInfoObject(object): pass
class ReadFontInfoVersion1TestCase(unittest.TestCase):
def setUp(self):
self.dstDir = tempfile.mktemp()
os.mkdir(self.dstDir)
metaInfo = {
"creator": "test",
"formatVersion": 1
}
path = os.path.join(self.dstDir, "metainfo.plist")
with open(path, "wb") as f:
writePlist(metaInfo, f)
def tearDown(self):
shutil.rmtree(self.dstDir)
def _writeInfoToPlist(self, info):
path = os.path.join(self.dstDir, "fontinfo.plist")
with open(path, "wb") as f:
writePlist(info, f)
def testRead(self):
originalData = dict(fontInfoVersion1)
self._writeInfoToPlist(originalData)
infoObject = TestInfoObject()
reader = UFOReader(self.dstDir)
reader.readInfo(infoObject)
for attr in dir(infoObject):
if attr not in fontInfoVersion2:
continue
originalValue = fontInfoVersion2[attr]
readValue = getattr(infoObject, attr)
self.assertEqual(originalValue, readValue)
def testFontStyleConversion(self):
fontStyle1To2 = {
64 : "regular",
1 : "italic",
32 : "bold",
33 : "bold italic"
}
for old, new in list(fontStyle1To2.items()):
info = dict(fontInfoVersion1)
info["fontStyle"] = old
self._writeInfoToPlist(info)
reader = UFOReader(self.dstDir)
infoObject = TestInfoObject()
reader.readInfo(infoObject)
self.assertEqual(new, infoObject.styleMapStyleName)
def testWidthNameConversion(self):
widthName1To2 = {
"Ultra-condensed" : 1,
"Extra-condensed" : 2,
"Condensed" : 3,
"Semi-condensed" : 4,
"Medium (normal)" : 5,
"Semi-expanded" : 6,
"Expanded" : 7,
"Extra-expanded" : 8,
"Ultra-expanded" : 9
}
for old, new in list(widthName1To2.items()):
info = dict(fontInfoVersion1)
info["widthName"] = old
self._writeInfoToPlist(info)
reader = UFOReader(self.dstDir)
infoObject = TestInfoObject()
reader.readInfo(infoObject)
self.assertEqual(new, infoObject.openTypeOS2WidthClass)
class WriteFontInfoVersion1TestCase(unittest.TestCase):
def setUp(self):
self.tempDir = tempfile.mktemp()
os.mkdir(self.tempDir)
self.dstDir = os.path.join(self.tempDir, "test.ufo")
def tearDown(self):
shutil.rmtree(self.tempDir)
def makeInfoObject(self):
infoObject = TestInfoObject()
for attr, value in list(fontInfoVersion2.items()):
setattr(infoObject, attr, value)
return infoObject
def readPlist(self):
path = os.path.join(self.dstDir, "fontinfo.plist")
with open(path, "rb") as f:
plist = readPlist(f)
return plist
def testWrite(self):
infoObject = self.makeInfoObject()
writer = UFOWriter(self.dstDir, formatVersion=1)
writer.writeInfo(infoObject)
writtenData = self.readPlist()
for attr, originalValue in list(fontInfoVersion1.items()):
newValue = writtenData[attr]
self.assertEqual(newValue, originalValue)
def testFontStyleConversion(self):
fontStyle1To2 = {
64 : "regular",
1 : "italic",
32 : "bold",
33 : "bold italic"
}
for old, new in list(fontStyle1To2.items()):
infoObject = self.makeInfoObject()
infoObject.styleMapStyleName = new
writer = UFOWriter(self.dstDir, formatVersion=1)
writer.writeInfo(infoObject)
writtenData = self.readPlist()
self.assertEqual(writtenData["fontStyle"], old)
def testWidthNameConversion(self):
widthName1To2 = {
"Ultra-condensed" : 1,
"Extra-condensed" : 2,
"Condensed" : 3,
"Semi-condensed" : 4,
"Medium (normal)" : 5,
"Semi-expanded" : 6,
"Expanded" : 7,
"Extra-expanded" : 8,
"Ultra-expanded" : 9
}
for old, new in list(widthName1To2.items()):
infoObject = self.makeInfoObject()
infoObject.openTypeOS2WidthClass = new
writer = UFOWriter(self.dstDir, formatVersion=1)
writer.writeInfo(infoObject)
writtenData = self.readPlist()
self.assertEqual(writtenData["widthName"], old)
if __name__ == "__main__":
from ufoLib.test.testSupport import runTests
runTests()
|