From b23a208805408baf2a40d98b5cb86885c50b318b Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 18 Oct 2018 13:58:47 +0100 Subject: [PATCH] ufoLib: fix doctests failing on py27 for unicode_literals I hate doctests. --- Lib/fontTools/ufoLib/converters.py | 8 ++--- Lib/fontTools/ufoLib/utils.py | 4 +-- Lib/fontTools/ufoLib/validators.py | 56 +++++++++++++++++++++--------- 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/Lib/fontTools/ufoLib/converters.py b/Lib/fontTools/ufoLib/converters.py index 2d76ff80e..c9ec99066 100644 --- a/Lib/fontTools/ufoLib/converters.py +++ b/Lib/fontTools/ufoLib/converters.py @@ -89,10 +89,10 @@ def findKnownKerningGroups(groups): ... "foo" : None, ... } >>> first, second = findKnownKerningGroups(testGroups) - >>> sorted(first) - ['@MMK_L_1', '@MMK_L_2', '@MMK_L_3'] - >>> sorted(second) - ['@MMK_R_1', '@MMK_R_2', '@MMK_R_3'] + >>> sorted(first) == ['@MMK_L_1', '@MMK_L_2', '@MMK_L_3'] + True + >>> sorted(second) == ['@MMK_R_1', '@MMK_R_2', '@MMK_R_3'] + True """ knownFirstGroupPrefixes = [ "@MMK_L_" diff --git a/Lib/fontTools/ufoLib/utils.py b/Lib/fontTools/ufoLib/utils.py index a25bd65e8..77e2f92a8 100644 --- a/Lib/fontTools/ufoLib/utils.py +++ b/Lib/fontTools/ufoLib/utils.py @@ -57,8 +57,8 @@ def deprecated(msg=""): ... print("hello world") >>> some_function() hello world - >>> some_function.__doc__ - "I just print 'hello world'." + >>> some_function.__doc__ == "I just print 'hello world'." + True """ def deprecated_decorator(func): diff --git a/Lib/fontTools/ufoLib/validators.py b/Lib/fontTools/ufoLib/validators.py index cb44f8336..844b7f1b5 100644 --- a/Lib/fontTools/ufoLib/validators.py +++ b/Lib/fontTools/ufoLib/validators.py @@ -841,27 +841,39 @@ def groupsValidator(value): (True, None) >>> groups = {"" : ["A"]} - >>> groupsValidator(groups) - (False, 'A group has an empty name.') + >>> valid, msg = groupsValidator(groups) + >>> valid + False + >>> print(msg) + A group has an empty name. >>> groups = {"public.awesome" : ["A"]} >>> groupsValidator(groups) (True, None) >>> groups = {"public.kern1." : ["A"]} - >>> groupsValidator(groups) - (False, 'The group data contains a kerning group with an incomplete name.') + >>> valid, msg = groupsValidator(groups) + >>> valid + False + >>> print(msg) + The group data contains a kerning group with an incomplete name. >>> groups = {"public.kern2." : ["A"]} - >>> groupsValidator(groups) - (False, 'The group data contains a kerning group with an incomplete name.') + >>> valid, msg = groupsValidator(groups) + >>> valid + False + >>> print(msg) + The group data contains a kerning group with an incomplete name. >>> groups = {"public.kern1.A" : ["A"], "public.kern2.A" : ["A"]} >>> groupsValidator(groups) (True, None) >>> groups = {"public.kern1.A1" : ["A"], "public.kern1.A2" : ["A"]} - >>> groupsValidator(groups) - (False, 'The glyph "A" occurs in too many kerning groups.') + >>> valid, msg = groupsValidator(groups) + >>> valid + False + >>> print(msg) + The glyph "A" occurs in too many kerning groups. """ bogusFormatMessage = "The group data is not in the correct format." if not isDictEnough(value): @@ -908,12 +920,18 @@ def kerningValidator(data): (True, None) >>> kerning = {"A" : ["B"]} - >>> kerningValidator(kerning) - (False, 'The kerning data is not in the correct format.') + >>> valid, msg = kerningValidator(kerning) + >>> valid + False + >>> print(msg) + The kerning data is not in the correct format. >>> kerning = {"A" : {"B" : "100"}} - >>> kerningValidator(kerning) - (False, 'The kerning data is not in the correct format.') + >>> valid, msg = kerningValidator(kerning) + >>> valid + False + >>> print(msg) + The kerning data is not in the correct format. """ bogusFormatMessage = "The kerning data is not in the correct format." if not isinstance(data, Mapping): @@ -975,8 +993,11 @@ def fontLibValidator(value): public.glyphOrder is not properly formatted: expected list or tuple,... >>> lib = {"public.glyphOrder" : ["A", 1, "B"]} - >>> fontLibValidator(lib) - (False, 'public.glyphOrder is not properly formatted: expected basestring, found int') + >>> valid, msg = fontLibValidator(lib) + >>> valid + False + >>> print(msg) # doctest: +ELLIPSIS + public.glyphOrder is not properly formatted: expected basestring,... """ if not isDictEnough(value): reason = "expected a dictionary, found %s" % type(value).__name__ @@ -1020,8 +1041,11 @@ def glyphLibValidator(value): (True, None) >>> lib = {"public.markColor" : 1} - >>> glyphLibValidator(lib) - (False, 'public.markColor is not properly formatted.') + >>> valid, msg = glyphLibValidator(lib) + >>> valid + False + >>> print(msg) + public.markColor is not properly formatted. """ if not isDictEnough(value): reason = "expected a dictionary, found %s" % type(value).__name__