From bdfc82582d1af24ff71b8916891dec0c7fbdf6c9 Mon Sep 17 00:00:00 2001 From: Tal Leming Date: Fri, 16 Sep 2011 16:34:32 +0000 Subject: [PATCH] WOFF copyright. git-svn-id: http://svn.robofab.com/branches/ufo3k@281 b5fa9d6c-a76f-4ffd-b3cb-f825fc41095c --- Lib/robofab/test/testSupport.py | 12 ++++ Lib/robofab/test/test_ufoLib.py | 112 ++++++++++++++++++++++++++++++++ Lib/robofab/ufoLib.py | 9 +-- 3 files changed, 129 insertions(+), 4 deletions(-) diff --git a/Lib/robofab/test/testSupport.py b/Lib/robofab/test/testSupport.py index 57f760f25..10def59a2 100755 --- a/Lib/robofab/test/testSupport.py +++ b/Lib/robofab/test/testSupport.py @@ -341,6 +341,18 @@ fontInfoVersion3 = { {"text" : "foo", "class" : ""}, ] ), + "woffMetadataCopyright" : dict( + text=[ + dict(text="foo"), + dict(text=""), + dict(text="foo", language="bar"), + dict(text="foo", language=""), + dict(text="foo", dir="ltr"), + dict(text="foo", dir="rtl"), + {"text" : "foo", "class" : "foo"}, + {"text" : "foo", "class" : ""}, + ] + ), } expectedFontInfo1To2Conversion = { diff --git a/Lib/robofab/test/test_ufoLib.py b/Lib/robofab/test/test_ufoLib.py index 2f1ac1d0e..7509033bb 100644 --- a/Lib/robofab/test/test_ufoLib.py +++ b/Lib/robofab/test/test_ufoLib.py @@ -2181,6 +2181,73 @@ class ReadFontInfoVersion3TestCase(unittest.TestCase): self._writeInfoToPlist(info) reader = UFOReader(self.dstDir) self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject()) + # woffMetadataCopyright + ## unknown attribute + info = dict(fontInfoVersion3) + info["woffMetadataCopyright"] = dict(text=[dict(text="foo")], notTheRightKey=1) + self._writeInfoToPlist(info) + reader = UFOReader(self.dstDir) + self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject()) + ## no text + info = dict(fontInfoVersion3) + info["woffMetadataCopyright"] = dict() + self._writeInfoToPlist(info) + reader = UFOReader(self.dstDir) + self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject()) + ## text not a list + info = dict(fontInfoVersion3) + info["woffMetadataCopyright"] = dict(text="abc") + self._writeInfoToPlist(info) + reader = UFOReader(self.dstDir) + self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject()) + ## text item not a dict + info = dict(fontInfoVersion3) + info["woffMetadataCopyright"] = dict(text=["abc"]) + self._writeInfoToPlist(info) + reader = UFOReader(self.dstDir) + self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject()) + ## text item unknown key + info = dict(fontInfoVersion3) + info["woffMetadataCopyright"] = dict(text=[dict(text="foo", notTheRightKey=1)]) + self._writeInfoToPlist(info) + reader = UFOReader(self.dstDir) + self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject()) + ## text item missing text + info = dict(fontInfoVersion3) + info["woffMetadataCopyright"] = dict(text=[dict(language="foo")]) + self._writeInfoToPlist(info) + reader = UFOReader(self.dstDir) + self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject()) + ## text not a string + info = dict(fontInfoVersion3) + info["woffMetadataCopyright"] = dict(text=[dict(text=1)]) + self._writeInfoToPlist(info) + reader = UFOReader(self.dstDir) + self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject()) + ## url not a string + info = dict(fontInfoVersion3) + info["woffMetadataCopyright"] = dict(text=[dict(text="foo", url=1)]) + self._writeInfoToPlist(info) + reader = UFOReader(self.dstDir) + self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject()) + ## language not a string + info = dict(fontInfoVersion3) + info["woffMetadataCopyright"] = dict(text=[dict(text="foo", language=1)]) + self._writeInfoToPlist(info) + reader = UFOReader(self.dstDir) + self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject()) + ## dir not ltr or rtl + info = dict(fontInfoVersion3) + info["woffMetadataCopyright"] = dict(text=[dict(text="foo", dir="utd")]) + self._writeInfoToPlist(info) + reader = UFOReader(self.dstDir) + self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject()) + ## class not a string + info = dict(fontInfoVersion3) + info["woffMetadataCopyright"] = dict(text=[{"text" : "foo", "class" : 1}]) + self._writeInfoToPlist(info) + reader = UFOReader(self.dstDir) + self.assertRaises(UFOLibError, reader.readInfo, TestInfoObject()) class WriteFontInfoVersion1TestCase(unittest.TestCase): @@ -3970,6 +4037,51 @@ class WriteFontInfoVersion3TestCase(unittest.TestCase): infoObject = self.makeInfoObject() infoObject.woffMetadataLicense = dict(text=[{"text" : "foo", "class" : 1}]) self.assertRaises(UFOLibError, writer.writeInfo, info=infoObject) + # woffMetadataCopyright + ## unknown attribute + infoObject = self.makeInfoObject() + infoObject.woffMetadataCopyright = dict(text=[dict(text="foo")], notTheRightKey=1) + self.assertRaises(UFOLibError, writer.writeInfo, info=infoObject) + ## no text + infoObject = self.makeInfoObject() + infoObject.woffMetadataCopyright = dict() + self.assertRaises(UFOLibError, writer.writeInfo, info=infoObject) + ## text not a list + infoObject = self.makeInfoObject() + infoObject.woffMetadataCopyright = dict(text="abc") + self.assertRaises(UFOLibError, writer.writeInfo, info=infoObject) + ## text item not a dict + infoObject = self.makeInfoObject() + infoObject.woffMetadataCopyright = dict(text=["abc"]) + self.assertRaises(UFOLibError, writer.writeInfo, info=infoObject) + ## text item unknown key + infoObject = self.makeInfoObject() + infoObject.woffMetadataCopyright = dict(text=[dict(text="foo", notTheRightKey=1)]) + self.assertRaises(UFOLibError, writer.writeInfo, info=infoObject) + ## text item missing text + infoObject = self.makeInfoObject() + infoObject.woffMetadataCopyright = dict(text=[dict(language="foo")]) + self.assertRaises(UFOLibError, writer.writeInfo, info=infoObject) + ## text not a string + infoObject = self.makeInfoObject() + infoObject.woffMetadataCopyright = dict(text=[dict(text=1)]) + self.assertRaises(UFOLibError, writer.writeInfo, info=infoObject) + ## url not a string + infoObject = self.makeInfoObject() + infoObject.woffMetadataCopyright = dict(text=[dict(text="foo", url=1)]) + self.assertRaises(UFOLibError, writer.writeInfo, info=infoObject) + ## language not a string + infoObject = self.makeInfoObject() + infoObject.woffMetadataCopyright = dict(text=[dict(text="foo", language=1)]) + self.assertRaises(UFOLibError, writer.writeInfo, info=infoObject) + ## dir not ltr or rtl + infoObject = self.makeInfoObject() + infoObject.woffMetadataCopyright = dict(text=[dict(text="foo", dir="utd")]) + self.assertRaises(UFOLibError, writer.writeInfo, info=infoObject) + ## class not a string + infoObject = self.makeInfoObject() + infoObject.woffMetadataCopyright = dict(text=[{"text" : "foo", "class" : 1}]) + self.assertRaises(UFOLibError, writer.writeInfo, info=infoObject) class UFO3ReadDataTestCase(unittest.TestCase): diff --git a/Lib/robofab/ufoLib.py b/Lib/robofab/ufoLib.py index 8593cab94..2b738c67e 100755 --- a/Lib/robofab/ufoLib.py +++ b/Lib/robofab/ufoLib.py @@ -1264,10 +1264,10 @@ def _fontInfoWOFFMetadataTrademarkValidator(value): """ Version 3+. """ - dictPrototype = dict(text=(list, False)) + dictPrototype = dict(text=(list, True)) if not _fontInfoDictValidator(value, dictPrototype): return False - for text in value: + for text in value["text"]: if not _fontInfoWOFFMetadataTextValue(text): return False return True @@ -1276,10 +1276,10 @@ def _fontInfoWOFFMetadataCopyrightValidator(value): """ Version 3+. """ - dictPrototype = dict(text=(list, False)) + dictPrototype = dict(text=(list, True)) if not _fontInfoDictValidator(value, dictPrototype): return False - for text in value: + for text in value["text"]: if not _fontInfoWOFFMetadataTextValue(text): return False return True @@ -1539,6 +1539,7 @@ _fontInfoAttributesVersion3ValueData.update({ "woffMetadataCredits" : dict(type=dict, valueValidator=_fontInfoWOFFMetadataCreditsValidator), "woffMetadataDescription" : dict(type=dict, valueValidator=_fontInfoWOFFMetadataDescriptionValidator), "woffMetadataLicense" : dict(type=dict, valueValidator=_fontInfoWOFFMetadataLicenseValidator), + "woffMetadataCopyright" : dict(type=dict, valueValidator=_fontInfoWOFFMetadataCopyrightValidator), }) # insert the type validator for all attrs that