Exemplo n.º 1
0
class ReadUFOFormatVersion2TestCase(unittest.TestCase):

	def setUpFont(self):
		self.font = OpenFont(ufoPath2)
		self.font.update()

	def tearDownFont(self):
		self.font.close()
		self.font = None

	def compareToUFO(self, doInfo=True):
		reader = UFOReader(ufoPath2)
		results = {}
		# info
		infoMatches = True
		info = self.font.info
		for attr, expectedValue in fontInfoVersion2.items():
			writtenValue = getattr(info, attr)
			if expectedValue != writtenValue:
				infoMatches = False
				break
		results["info"]= infoMatches
		# kerning
		kerning = self.font.kerning.asDict()
		expectedKerning = reader.readKerning()
		results["kerning"] = expectedKerning == kerning
		# groups
		groups = dict(self.font.groups)
		expectedGroups = reader.readGroups()
		results["groups"] = expectedGroups == groups
		# features
		features = self.font.features.text
		expectedFeatures = reader.readFeatures()
		results["features"] = expectedFeatures == features
		# lib
		lib = dict(self.font.lib)
		expectedLib = reader.readLib()
		results["lib"] = expectedLib == lib
		return results

	def testFull(self):
		self.setUpFont()
		otherResults = self.compareToUFO()
		self.assertEqual(otherResults["info"], True)
		self.assertEqual(otherResults["kerning"], True)
		self.assertEqual(otherResults["groups"], True)
		self.assertEqual(otherResults["features"], True)
		self.assertEqual(otherResults["lib"], True)
		self.tearDownFont()

	def testInfo(self):
		self.setUpFont()
		info = self.font.info
		for attr, expectedValue in fontInfoVersion2.items():
			writtenValue = getattr(info, attr)
			self.assertEqual((attr, expectedValue), (attr, writtenValue))
		self.tearDownFont()
Exemplo n.º 2
0
class ReadUFOFormatVersion1TestCase(unittest.TestCase):

	def setUpFont(self):
		self.font = OpenFont(ufoPath1)
		self.font.update()

	def tearDownFont(self):
		self.font.close()
		self.font = None

	def compareToUFO(self, doInfo=True):
		reader = UFOReader(ufoPath1)
		results = {}
		# info
		infoMatches = True
		info = self.font.info
		for attr, expectedValue in expectedFontInfo1To2Conversion.items():
			writtenValue = getattr(info, attr)
			if expectedValue != writtenValue:
				infoMatches = False
				break
		results["info"]= infoMatches
		# kerning
		kerning = self.font.kerning.asDict()
		expectedKerning = reader.readKerning()
		results["kerning"] = expectedKerning == kerning
		# groups
		groups = dict(self.font.groups)
		expectedGroups = reader.readGroups()
		results["groups"] = expectedGroups == groups
		# features
		features = self.font.features.text
		f = open(os.path.join(ufoPath2, "features.fea"), "r")
		expectedFeatures = f.read()
		f.close()
		match = True
		features = [line for line in features.splitlines() if line]
		expectedFeatures = [line for line in expectedFeatures.splitlines() if line]
		if expectedFeatures != features or reader.readFeatures() != "":
			match = False
		results["features"] = match
		# lib
		lib = dict(self.font.lib)
		expectedLib = reader.readLib()
		for key in removeFromFormatVersion1Lib:
			if key in expectedLib:
				del expectedLib[key]
		results["lib"] = expectedLib == lib
		return results

	def testFull(self):
		self.setUpFont()
		otherResults = self.compareToUFO()
		self.assertEqual(otherResults["info"], True)
		self.assertEqual(otherResults["kerning"], True)
		self.assertEqual(otherResults["groups"], True)
		self.assertEqual(otherResults["features"], True)
		self.assertEqual(otherResults["lib"], True)
		self.tearDownFont()

	def testInfo(self):
		self.setUpFont()
		info = self.font.info
		for attr, expectedValue in expectedFontInfo1To2Conversion.items():
			writtenValue = getattr(info, attr)
			self.assertEqual((attr, expectedValue), (attr, writtenValue))
		self.tearDownFont()