Skip to content

Commit

Permalink
add more keywords to non-PASS log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
felipesanches committed Aug 9, 2019
1 parent 8ab8212 commit 5440a62
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 51 deletions.
72 changes: 41 additions & 31 deletions Lib/fontbakery/profiles/fvar.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from fontbakery.callable import check
from fontbakery.checkrunner import FAIL, PASS, WARN
from fontbakery.message import Message
# used to inform get_module_profile whether and how to create a profile
from fontbakery.fonts_profile import profile_factory # NOQA pylint: disable=unused-import

Expand Down Expand Up @@ -32,10 +33,11 @@ def com_google_fonts_check_varfont_regular_wght_coord(ttFont, regular_wght_coord
if regular_wght_coord == 400:
yield PASS, "Regular:wght is 400."
else:
yield FAIL, ("The 'wght' axis coordinate of"
" the 'Regular' instance must be 400."
" Got a '{}' coordinate instead."
"").format(regular_wght_coord)
yield FAIL,\
Message("not-400",
f'The "wght" axis coordinate of'
f' the "Regular" instance must be 400.'
f' Got {regular_wght_coord} instead.')


@check(
Expand All @@ -61,10 +63,11 @@ def com_google_fonts_check_varfont_regular_wdth_coord(ttFont, regular_wdth_coord
if regular_wdth_coord == 100:
yield PASS, "Regular:wdth is 100."
else:
yield FAIL, ("The 'wdth' coordinate of"
" the 'Regular' instance must be 100."
" Got {} as a default value instead."
"").format(regular_wdth_coord)
yield FAIL,\
Message("not-100",
f'The "wdth" coordinate of'
f' the "Regular" instance must be 100.'
f' Got {regular_wdth_coord} as a default value instead.')


@check(
Expand All @@ -90,10 +93,11 @@ def com_google_fonts_check_varfont_regular_slnt_coord(ttFont, regular_slnt_coord
if regular_slnt_coord == 0:
yield PASS, "Regular:slnt is zero."
else:
yield FAIL, ("The 'slnt' coordinate of"
" the 'Regular' instance must be zero."
" Got {} as a default value instead."
"").format(regular_slnt_coord)
yield FAIL,\
Message("non-zero",
f'The "slnt" coordinate of'
f' the "Regular" instance must be zero.'
f' Got {regular_slnt_coord} as a default value instead.')


@check(
Expand All @@ -119,10 +123,11 @@ def com_google_fonts_check_varfont_regular_ital_coord(ttFont, regular_ital_coord
if regular_ital_coord == 0:
yield PASS, "Regular:ital is zero."
else:
yield FAIL, ("The 'ital' coordinate of"
" the 'Regular' instance must be zero."
" Got {} as a default value instead."
"").format(regular_ital_coord)
yield FAIL,\
Message("non-zero",
f'The "ital" coordinate of'
f' the "Regular" instance must be zero.'
f' Got {regular_ital_coord} as a default value instead.')


@check(
Expand All @@ -146,14 +151,14 @@ def com_google_fonts_check_varfont_regular_opsz_coord(ttFont, regular_opsz_coord
9 and 13 on the 'Regular' instance."""

if regular_opsz_coord >= 9 and regular_opsz_coord <= 13:
yield PASS, ("Regular:opsz coordinate ({})"
" looks good.").format(regular_opsz_coord)
yield PASS, ("Regular:opsz coordinate ({regular_opsz_coord}) looks good.")
else:
yield WARN, ("The 'opsz' (Optical Size) coordinate"
" on the 'Regular' instance is recommended"
" to be a value in the range 9 to 13."
" Got a '{}' coordinate instead."
"").format(regular_opsz_coord)
yield WARN,\
Message("out-of-range",
f'The "opsz" (Optical Size) coordinate'
f' on the "Regular" instance is recommended'
f' to be a value in the range 9 to 13.'
f' Got {regular_opsz_coord} instead.')


@check(
Expand All @@ -179,10 +184,11 @@ def com_google_fonts_check_varfont_bold_wght_coord(ttFont, bold_wght_coord):
if bold_wght_coord == 700:
yield PASS, "Bold:wght is 700."
else:
yield FAIL, ("The 'wght' axis coordinate of"
" the 'Bold' instance must be 700."
" Got a '{}' coordinate instead."
"").format(bold_wght_coord)
yield FAIL,\
Message("not-700",
f'The "wght" axis coordinate of'
f' the "Bold" instance must be 700.'
f' Got {bold_wght_coord} instead.')


@check(
Expand All @@ -209,8 +215,10 @@ def com_google_fonts_check_wght_valid_range(ttFont):
value = instance.coordinates['wght']
if value < 1 or value > 1000:
Failed = True
yield FAIL, (f"Found a bad wght coordinate with value '{value}'"
" outside of the valid range from 1 to 1000.")
yield FAIL,\
Message("out-of-range",
f'Found a bad "wght" coordinate with value {value}'
f' outside of the valid range from 1 to 1000.')
break

if not Failed:
Expand Down Expand Up @@ -240,8 +248,10 @@ def com_google_fonts_check_wdth_valid_range(ttFont):
value = instance.coordinates['wdth']
if value < 1 or value > 1000:
Failed = True
yield FAIL, (f"Found a bad wdth coordinate with value '{value}'"
" outside of the valid range from 1 to 1000.")
yield FAIL,\
Message("out-of-range",
f'Found a bad "wdth" coordinate with value {value}'
f' outside of the valid range from 1 to 1000.')
break

if not Failed:
Expand Down
41 changes: 21 additions & 20 deletions tests/profiles/fvar_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ def test_check_varfont_regular_wght_coord():
assert status == PASS

# We then change the value so it must FAIL:
ttFont["fvar"].instances[0].coordinates["wght"] = 0
ttFont["fvar"].instances[0].coordinates["wght"] = 500

# Then re-read the coord:
regular_weight_coord = regular_wght_coord(ttFont)

# and now this should FAIL the test:
print('Test FAIL with a bad Regular:wght coordinate (0)...')
print('Test FAIL with a bad Regular:wght coordinate (500)...')
status, message = list(check(ttFont, regular_weight_coord))[-1]
assert status == FAIL
assert status == FAIL and message.code == "not-400"


def test_check_varfont_regular_wdth_coord():
Expand All @@ -63,9 +63,9 @@ def test_check_varfont_regular_wdth_coord():
regular_width_coord = regular_wdth_coord(ttFont)

# and now this should FAIL the test:
print('Test FAIL with a bad Regular:wdth coordinate (100)...')
print('Test FAIL with a bad Regular:wdth coordinate (0)...')
status, message = list(check(ttFont, regular_width_coord))[-1]
assert status == FAIL
assert status == FAIL and message.code == "not-100"


def test_check_varfont_regular_slnt_coord():
Expand All @@ -84,19 +84,19 @@ def test_check_varfont_regular_slnt_coord():
ttFont["fvar"].axes.append(new_axis)

# and specify a bad coordinate for the Regular:
ttFont["fvar"].instances[0].coordinates["slnt"] = 123
ttFont["fvar"].instances[0].coordinates["slnt"] = 12
# Note: I know the correct instance index for this hotfix because
# I inspected the our reference CabinVF using ttx
# I inspected our reference CabinVF using ttx

# then we test the code of the regular_slnt_coord condition:
regular_slant_coord = regular_slnt_coord(ttFont)

# And with this the test must FAIL
print('Test FAIL with a bad Regular:slnt coordinate (123)...')
print('Test FAIL with a bad Regular:slnt coordinate (12)...')
status, message = list(check(ttFont, regular_slant_coord))[-1]
assert status == FAIL
assert status == FAIL and message.code == "non-zero"

# We then fix the Regular:slnt coordinate value value:
# We then fix the Regular:slnt coordinate value:
regular_slant_coord = 0

# and now this should PASS the test:
Expand Down Expand Up @@ -131,7 +131,7 @@ def test_check_varfont_regular_ital_coord():
# So it must FAIL the test
print('Test FAIL with a bad Regular:ital coordinate (123)...')
status, message = list(check(ttFont, regular_italic_coord))[-1]
assert status == FAIL
assert status == FAIL and message.code == "non-zero"

# We then fix the Regular:ital coordinate:
regular_italic_coord = 0
Expand All @@ -141,6 +141,7 @@ def test_check_varfont_regular_ital_coord():
status, message = list(check(ttFont, regular_italic_coord))[-1]
assert status == PASS


def test_check_varfont_regular_opsz_coord():
""" The variable font 'opsz' (Optical Size) axis coordinate
should be between 9 and 13 on the 'Regular' instance. """
Expand All @@ -167,15 +168,15 @@ def test_check_varfont_regular_opsz_coord():
# And it must WARN the test
print('Test WARN with a bad Regular:opsz coordinate (8)...')
status, message = list(check(ttFont, regular_opticalsize_coord))[-1]
assert status == WARN
assert status == WARN and message.code == "out-of-range"

# We try yet another bad value
regualr_opticalsize_coord = 14

# And it must also WARN the test
print('Test WARN with another bad Regular:opsz value (14)...')
status, message = list(check(ttFont, regular_opticalsize_coord))[-1]
assert status == WARN
assert status == WARN and message.code == "out-of-range"

# We then test with good default opsz values:
for value in [9, 10, 11, 12, 13]:
Expand Down Expand Up @@ -204,15 +205,15 @@ def test_check_varfont_bold_wght_coord():
assert status == PASS

# We then change the value so it must FAIL:
ttFont["fvar"].instances[3].coordinates["wght"] = 0
ttFont["fvar"].instances[3].coordinates["wght"] = 600

# Then re-read the coord:
bold_weight_coord = bold_wght_coord(ttFont)

# and now this should FAIL the test:
print('Test FAIL with a bad Bold:wght coordinage (700)...')
print('Test FAIL with a bad Bold:wght coordinage (600)...')
status, message = list(check(ttFont, bold_weight_coord))[-1]
assert status == FAIL
assert status == FAIL and message.code == "not-700"


def test_check_wght_valid_range():
Expand All @@ -235,15 +236,15 @@ def test_check_wght_valid_range():
# And it must FAIL the test
print('Test FAIL with wght=0...')
status, message = list(check(ttFont))[-1]
assert status == FAIL
assert status == FAIL and message.code == "out-of-range"

# And yet another bad value:
ttFont["fvar"].instances[0].coordinates["wght"] = 1001

# Should also FAIL:
print('Test FAIL with wght=1001...')
status, message = list(check(ttFont))[-1]
assert status == FAIL
assert status == FAIL and message.code == "out-of-range"


def test_check_wdth_valid_range():
Expand All @@ -266,12 +267,12 @@ def test_check_wdth_valid_range():
# And it must FAIL the test
print('Test FAIL with wght=0...')
status, message = list(check(ttFont))[-1]
assert status == FAIL
assert status == FAIL and message.code == "out-of-range"

# And yet another bad value:
ttFont["fvar"].instances[0].coordinates["wdth"] = 1001

# Should also FAIL:
print('Test FAIL with wght=1001...')
status, message = list(check(ttFont))[-1]
assert status == FAIL
assert status == FAIL and message.code == "out-of-range"

0 comments on commit 5440a62

Please sign in to comment.