summaryrefslogtreecommitdiff
path: root/misc/pylib/robofab/test/test_RInfoFL.py
diff options
context:
space:
mode:
authorRasmus Andersson <rasmus@notion.se>2017-09-04 06:03:17 +0300
committerRasmus Andersson <rasmus@notion.se>2017-09-04 18:12:34 +0300
commit8234b62ab762637ef24c3398b4204a8ce8db31a7 (patch)
tree1c8df547021cdb58951630a015e4101ede46dbf1 /misc/pylib/robofab/test/test_RInfoFL.py
parent31ae014e0c827dd76696fdab7e4ca3fed9f6402b (diff)
downloadinter-8234b62ab762637ef24c3398b4204a8ce8db31a7.tar.xz
Speeds up font compilation by around 200%
Cython is used to compile some hot paths into native Python extensions. These hot paths were identified through running ufocompile with the hotshot profiler and then converting file by file to Cython, starting with the "hottest" paths and continuing until returns were deminishing. This means that only a few Python files were converted to Cython. Closes #23 Closes #20 (really this time)
Diffstat (limited to 'misc/pylib/robofab/test/test_RInfoFL.py')
-rw-r--r--misc/pylib/robofab/test/test_RInfoFL.py111
1 files changed, 111 insertions, 0 deletions
diff --git a/misc/pylib/robofab/test/test_RInfoFL.py b/misc/pylib/robofab/test/test_RInfoFL.py
new file mode 100644
index 000000000..bfbd13477
--- /dev/null
+++ b/misc/pylib/robofab/test/test_RInfoFL.py
@@ -0,0 +1,111 @@
+import unittest
+from cStringIO import StringIO
+import sys
+from robofab import ufoLib
+from robofab.objects.objectsFL import NewFont
+from robofab.test.testSupport import fontInfoVersion1, fontInfoVersion2
+
+
+class RInfoRFTestCase(unittest.TestCase):
+
+ def testRoundTripVersion2(self):
+ font = NewFont()
+ infoObject = font.info
+ for attr, value in fontInfoVersion2.items():
+ if attr in infoObject._ufoToFLAttrMapping and infoObject._ufoToFLAttrMapping[attr]["nakedAttribute"] is None:
+ continue
+ setattr(infoObject, attr, value)
+ newValue = getattr(infoObject, attr)
+ self.assertEqual((attr, newValue), (attr, value))
+ font.close()
+
+ def testVersion2UnsupportedSet(self):
+ saveStderr = sys.stderr
+ saveStdout = sys.stdout
+ tempStderr = StringIO()
+ sys.stderr = tempStderr
+ sys.stdout = tempStderr
+ font = NewFont()
+ infoObject = font.info
+ requiredWarnings = []
+ try:
+ for attr, value in fontInfoVersion2.items():
+ if attr in infoObject._ufoToFLAttrMapping and infoObject._ufoToFLAttrMapping[attr]["nakedAttribute"] is not None:
+ continue
+ setattr(infoObject, attr, value)
+ s = "The attribute %s is not supported by FontLab." % attr
+ requiredWarnings.append((attr, s))
+ finally:
+ sys.stderr = saveStderr
+ sys.stdout = saveStdout
+ tempStderr = tempStderr.getvalue()
+ for attr, line in requiredWarnings:
+ self.assertEquals((attr, line in tempStderr), (attr, True))
+ font.close()
+
+ def testVersion2UnsupportedGet(self):
+ saveStderr = sys.stderr
+ saveStdout = sys.stdout
+ tempStderr = StringIO()
+ sys.stderr = tempStderr
+ sys.stdout = tempStderr
+ font = NewFont()
+ infoObject = font.info
+ requiredWarnings = []
+ try:
+ for attr, value in fontInfoVersion2.items():
+ if attr in infoObject._ufoToFLAttrMapping and infoObject._ufoToFLAttrMapping[attr]["nakedAttribute"] is not None:
+ continue
+ getattr(infoObject, attr, value)
+ s = "The attribute %s is not supported by FontLab." % attr
+ requiredWarnings.append((attr, s))
+ finally:
+ sys.stderr = saveStderr
+ sys.stdout = saveStdout
+ tempStderr = tempStderr.getvalue()
+ for attr, line in requiredWarnings:
+ self.assertEquals((attr, line in tempStderr), (attr, True))
+ font.close()
+
+ def testRoundTripVersion1(self):
+ font = NewFont()
+ infoObject = font.info
+ for attr, value in fontInfoVersion1.items():
+ if attr not in ufoLib.deprecatedFontInfoAttributesVersion2:
+ setattr(infoObject, attr, value)
+ for attr, expectedValue in fontInfoVersion1.items():
+ if attr not in ufoLib.deprecatedFontInfoAttributesVersion2:
+ value = getattr(infoObject, attr)
+ self.assertEqual((attr, expectedValue), (attr, value))
+ font.close()
+
+ def testVersion1DeprecationRoundTrip(self):
+ saveStderr = sys.stderr
+ saveStdout = sys.stdout
+ tempStderr = StringIO()
+ sys.stderr = tempStderr
+ sys.stdout = tempStderr
+ font = NewFont()
+ infoObject = font.info
+ requiredWarnings = []
+ try:
+ for attr, value in fontInfoVersion1.items():
+ if attr in ufoLib.deprecatedFontInfoAttributesVersion2:
+ setattr(infoObject, attr, value)
+ v = getattr(infoObject, attr)
+ self.assertEquals((attr, value), (attr, v))
+ s = "DeprecationWarning: The %s attribute has been deprecated." % attr
+ requiredWarnings.append((attr, s))
+ finally:
+ sys.stderr = saveStderr
+ sys.stdout = saveStdout
+ tempStderr = tempStderr.getvalue()
+ for attr, line in requiredWarnings:
+ self.assertEquals((attr, line in tempStderr), (attr, True))
+ font.close()
+
+
+if __name__ == "__main__":
+ from robofab.test.testSupport import runTests
+ runTests()
+