[designspaceLib] Add tests for the new parameters
This commit is contained in:
parent
ede5de6fb0
commit
03f8ec3b87
@ -1074,11 +1074,13 @@ class DesignSpaceDocument(object):
|
|||||||
|
|
||||||
def read(self, path):
|
def read(self, path):
|
||||||
self.path = path
|
self.path = path
|
||||||
|
self.filename = os.path.basename(path)
|
||||||
reader = self.readerClass(path, self)
|
reader = self.readerClass(path, self)
|
||||||
reader.read()
|
reader.read()
|
||||||
|
|
||||||
def write(self, path):
|
def write(self, path):
|
||||||
self.path = path
|
self.path = path
|
||||||
|
self.filename = os.path.basename(path)
|
||||||
self.updatePaths()
|
self.updatePaths()
|
||||||
writer = self.writerClass(path, self)
|
writer = self.writerClass(path, self)
|
||||||
writer.write()
|
writer.write()
|
||||||
|
99
Tests/designspaceLib/data/test.designspace
Normal file
99
Tests/designspaceLib/data/test.designspace
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
<?xml version='1.0' encoding='utf-8'?>
|
||||||
|
<designspace format="3">
|
||||||
|
<axes>
|
||||||
|
<axis default="0" maximum="1000" minimum="0" name="weight" tag="wght">
|
||||||
|
<labelname xml:lang="en">Wéíght</labelname>
|
||||||
|
<labelname xml:lang="fa-IR">قطر</labelname>
|
||||||
|
</axis>
|
||||||
|
<axis default="20" hidden="1" maximum="1000" minimum="0" name="width" tag="wdth">
|
||||||
|
<labelname xml:lang="fr">Chasse</labelname>
|
||||||
|
<map input="0" output="10" />
|
||||||
|
<map input="401" output="66" />
|
||||||
|
<map input="1000" output="990" />
|
||||||
|
</axis>
|
||||||
|
</axes>
|
||||||
|
<rules>
|
||||||
|
<rule name="named.rule.1">
|
||||||
|
<condition maximum="1" minimum="0" name="aaaa" />
|
||||||
|
<condition maximum="3" minimum="2" name="bbbb" />
|
||||||
|
<sub name="a" with="a.alt" />
|
||||||
|
</rule>
|
||||||
|
</rules>
|
||||||
|
<sources>
|
||||||
|
<source familyname="MasterFamilyName" filename="masters/masterTest1.ufo" name="master.ufo1" stylename="MasterStyleNameOne">
|
||||||
|
<lib copy="1" />
|
||||||
|
<features copy="1" />
|
||||||
|
<info copy="1" />
|
||||||
|
<glyph mute="1" name="A" />
|
||||||
|
<glyph mute="1" name="Z" />
|
||||||
|
<location>
|
||||||
|
<dimension name="weight" xvalue="0" />
|
||||||
|
<dimension name="width" xvalue="20" />
|
||||||
|
</location>
|
||||||
|
</source>
|
||||||
|
<source familyname="MasterFamilyName" filename="masters/masterTest2.ufo" name="master.ufo2" stylename="MasterStyleNameTwo">
|
||||||
|
<kerning mute="1" />
|
||||||
|
<location>
|
||||||
|
<dimension name="weight" xvalue="1000" />
|
||||||
|
<dimension name="width" xvalue="20" />
|
||||||
|
</location>
|
||||||
|
</source>
|
||||||
|
</sources>
|
||||||
|
<instances>
|
||||||
|
<instance familyname="InstanceFamilyName" filename="instances/instanceTest1.ufo" name="instance.ufo1" postscriptfontname="InstancePostscriptName" stylemapfamilyname="InstanceStyleMapFamilyName" stylemapstylename="InstanceStyleMapStyleName" stylename="InstanceStyleName">
|
||||||
|
<location>
|
||||||
|
<dimension name="weight" xvalue="500" />
|
||||||
|
<dimension name="width" xvalue="20" />
|
||||||
|
</location>
|
||||||
|
<glyphs>
|
||||||
|
<glyph mute="1" name="arrow" unicode="0x123 0x124 0x125" />
|
||||||
|
</glyphs>
|
||||||
|
<kerning />
|
||||||
|
<info />
|
||||||
|
<lib>
|
||||||
|
<dict>
|
||||||
|
<key>com.coolDesignspaceApp.specimenText</key>
|
||||||
|
<string>Hamburgerwhatever</string>
|
||||||
|
</dict>
|
||||||
|
</lib>
|
||||||
|
</instance>
|
||||||
|
<instance familyname="InstanceFamilyName" filename="instances/instanceTest2.ufo" name="instance.ufo2" postscriptfontname="InstancePostscriptName" stylemapfamilyname="InstanceStyleMapFamilyName" stylemapstylename="InstanceStyleMapStyleName" stylename="InstanceStyleName">
|
||||||
|
<location>
|
||||||
|
<dimension name="weight" xvalue="500" />
|
||||||
|
<dimension name="width" xvalue="400" yvalue="300" />
|
||||||
|
</location>
|
||||||
|
<glyphs>
|
||||||
|
<glyph name="arrow" unicode="0x65 0xc9 0x12d">
|
||||||
|
<location>
|
||||||
|
<dimension name="weight" xvalue="120" />
|
||||||
|
<dimension name="width" xvalue="100" />
|
||||||
|
</location>
|
||||||
|
<note>A note about this glyph</note>
|
||||||
|
<masters>
|
||||||
|
<master glyphname="BB" source="master.ufo1">
|
||||||
|
<location>
|
||||||
|
<dimension name="weight" xvalue="20" />
|
||||||
|
<dimension name="width" xvalue="20" />
|
||||||
|
</location>
|
||||||
|
</master>
|
||||||
|
<master glyphname="CC" source="master.ufo2">
|
||||||
|
<location>
|
||||||
|
<dimension name="weight" xvalue="900" />
|
||||||
|
<dimension name="width" xvalue="900" />
|
||||||
|
</location>
|
||||||
|
</master>
|
||||||
|
</masters>
|
||||||
|
</glyph>
|
||||||
|
<glyph name="arrow2" />
|
||||||
|
</glyphs>
|
||||||
|
<kerning />
|
||||||
|
<info />
|
||||||
|
</instance>
|
||||||
|
</instances>
|
||||||
|
<lib>
|
||||||
|
<dict>
|
||||||
|
<key>com.coolDesignspaceApp.previewSize</key>
|
||||||
|
<integer>30</integer>
|
||||||
|
</dict>
|
||||||
|
</lib>
|
||||||
|
</designspace>
|
@ -12,6 +12,17 @@ from fontTools.designspaceLib import (
|
|||||||
InstanceDescriptor, evaluateRule, processRules, posix)
|
InstanceDescriptor, evaluateRule, processRules, posix)
|
||||||
|
|
||||||
|
|
||||||
|
def assert_equals_test_file(path, test_filename):
|
||||||
|
with open(path) as fp:
|
||||||
|
actual = fp.read()
|
||||||
|
|
||||||
|
test_path = os.path.join(os.path.dirname(__file__), test_filename)
|
||||||
|
with open(test_path) as fp:
|
||||||
|
expected = fp.read()
|
||||||
|
|
||||||
|
assert actual == expected
|
||||||
|
|
||||||
|
|
||||||
def test_fill_document(tmpdir):
|
def test_fill_document(tmpdir):
|
||||||
tmpdir = str(tmpdir)
|
tmpdir = str(tmpdir)
|
||||||
testDocPath = os.path.join(tmpdir, "test.designspace")
|
testDocPath = os.path.join(tmpdir, "test.designspace")
|
||||||
@ -23,6 +34,7 @@ def test_fill_document(tmpdir):
|
|||||||
# add master 1
|
# add master 1
|
||||||
s1 = SourceDescriptor()
|
s1 = SourceDescriptor()
|
||||||
s1.filename = os.path.relpath(masterPath1, os.path.dirname(testDocPath))
|
s1.filename = os.path.relpath(masterPath1, os.path.dirname(testDocPath))
|
||||||
|
assert s1.font is None
|
||||||
s1.name = "master.ufo1"
|
s1.name = "master.ufo1"
|
||||||
s1.copyLib = True
|
s1.copyLib = True
|
||||||
s1.copyInfo = True
|
s1.copyInfo = True
|
||||||
@ -57,6 +69,7 @@ def test_fill_document(tmpdir):
|
|||||||
i1.styleMapStyleName = "InstanceStyleMapStyleName"
|
i1.styleMapStyleName = "InstanceStyleMapStyleName"
|
||||||
glyphData = dict(name="arrow", mute=True, unicodes=[0x123, 0x124, 0x125])
|
glyphData = dict(name="arrow", mute=True, unicodes=[0x123, 0x124, 0x125])
|
||||||
i1.glyphs['arrow'] = glyphData
|
i1.glyphs['arrow'] = glyphData
|
||||||
|
i1.lib['com.coolDesignspaceApp.specimenText'] = "Hamburgerwhatever"
|
||||||
doc.addInstance(i1)
|
doc.addInstance(i1)
|
||||||
# add instance 2
|
# add instance 2
|
||||||
i2 = InstanceDescriptor()
|
i2 = InstanceDescriptor()
|
||||||
@ -78,6 +91,9 @@ def test_fill_document(tmpdir):
|
|||||||
i2.glyphs['arrow2'] = dict(mute=False)
|
i2.glyphs['arrow2'] = dict(mute=False)
|
||||||
doc.addInstance(i2)
|
doc.addInstance(i2)
|
||||||
|
|
||||||
|
doc.filename = "suggestedFileName.designspace"
|
||||||
|
doc.lib['com.coolDesignspaceApp.previewSize'] = 30
|
||||||
|
|
||||||
# now we have sources and instances, but no axes yet.
|
# now we have sources and instances, but no axes yet.
|
||||||
doc.check()
|
doc.check()
|
||||||
|
|
||||||
@ -106,7 +122,7 @@ def test_fill_document(tmpdir):
|
|||||||
a2.tag = "wdth"
|
a2.tag = "wdth"
|
||||||
a2.map = [(0.0, 10.0), (401.0, 66.0), (1000.0, 990.0)]
|
a2.map = [(0.0, 10.0), (401.0, 66.0), (1000.0, 990.0)]
|
||||||
a2.hidden = True
|
a2.hidden = True
|
||||||
a2.labelNames[u'fr'] = u"Poids"
|
a2.labelNames[u'fr'] = u"Chasse"
|
||||||
doc.addAxis(a2)
|
doc.addAxis(a2)
|
||||||
# add an axis that is not part of any location to see if that works
|
# add an axis that is not part of any location to see if that works
|
||||||
a3 = AxisDescriptor()
|
a3 = AxisDescriptor()
|
||||||
@ -127,12 +143,16 @@ def test_fill_document(tmpdir):
|
|||||||
# write the document
|
# write the document
|
||||||
doc.write(testDocPath)
|
doc.write(testDocPath)
|
||||||
assert os.path.exists(testDocPath)
|
assert os.path.exists(testDocPath)
|
||||||
|
assert_equals_test_file(testDocPath, 'data/test.designspace')
|
||||||
# import it again
|
# import it again
|
||||||
new = DesignSpaceDocument()
|
new = DesignSpaceDocument()
|
||||||
new.read(testDocPath)
|
new.read(testDocPath)
|
||||||
|
|
||||||
new.check()
|
new.check()
|
||||||
assert new.default.location == {'width': 20.0, 'weight': 0.0}
|
assert new.default.location == {'width': 20.0, 'weight': 0.0}
|
||||||
|
assert new.filename == 'test.designspace'
|
||||||
|
assert new.lib == doc.lib
|
||||||
|
assert new.instances[0].lib == doc.instances[0].lib
|
||||||
|
|
||||||
# >>> for a, b in zip(doc.instances, new.instances):
|
# >>> for a, b in zip(doc.instances, new.instances):
|
||||||
# ... a.compare(b)
|
# ... a.compare(b)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user