summaryrefslogtreecommitdiff
path: root/misc/pylib/robofab/test/test_RInfoFL.py
blob: bfbd13477ab97d69778edd0dd03b8168d7314a5e (plain)
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
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()