Skip to content

Commit

Permalink
Porting a large portion of the remaining code-tests to the new style
Browse files Browse the repository at this point in the history
Using the TestingContext helper class.
(follow-up to PR #3005)
  • Loading branch information
felipesanches committed Sep 24, 2020
1 parent 214506e commit e1e2c94
Show file tree
Hide file tree
Showing 26 changed files with 937 additions and 1,043 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
Below are the most important changes from each release.
A more detailed list of changes is available in the corresponding milestones for each release in the Github issue tracker (https://github.com/googlefonts/fontbakery/milestones?state=closed).

## 0.7.30 (2020-Sept-someday)

## 0.7.31 (2020-Oct-??)
- ...


## 0.7.30 (2020-Sept-24)
### Note-worthy code changes
- The vast majority of code-tests now use our new style which is less errorprone, using the helper CheckTester class. (PR #3035)
- Adopted 4-spaces indentation. We're changing our codestyle to facilitate collaboration from people who also work with the fontTools and AFDKO codebases. (issue 2997)
- All rationale text needs to have 8 indentation spaces (because this indentation on the source should not show up on the user-interface when rationale text is printed on the text terminal)
- Remove PriorityLevel class as it makes classifying checks by priority more complicated then necessary! (issue #2981)
Expand Down
20 changes: 6 additions & 14 deletions Lib/fontbakery/codetesting.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@
from fontbakery.checkrunner import CheckRunner, Profile, get_module_profile


class TestingContext:
""" CAUTION: this uses a lot of "private" methods and properties
class CheckTester:
"""
This class offers a bit of automation to aid in the implementation of
code-tests to validade the proper behaviour of FontBakery checks.
!!!CAUTION: this uses a lot of "private" methods and properties
of CheckRunner, in order to make unit testing different cases simpler.
This is not intended to run in production. However, if that is desired
Expand All @@ -33,18 +37,6 @@ class TestingContext:
An initial run can be with unaltered arguments, as CheckRunner would
produce them by itself. And subsequent calls can reuse some of them.
Example:
> import fontbakery.profiles.googlefonts as googlefonts_profile
> check = TestingContext(googlefonts_profile,
'com.google.fonts/check/some_id')
> first_result = check(initialTTFont) # can be called with overrides
> modifiedTTFont = check['ttFont']
> mofifiedTTFont[opentype_table].some_field = some_value
> second_result = check(modifiedTTFont)
> overriden_value = check['some_dependency']
> overriden_value.change_something()
> another_result = check(modifiedTTFont, {'some_dependency': overriden_value})
"""
def __init__(self, module_or_profile, check_id):
self.profile = module_or_profile \
Expand Down
Binary file added data/test/cabincondensed/CabinCondensed-Bold.ttf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
25 changes: 12 additions & 13 deletions tests/profiles/adobefonts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

from fontTools.ttLib import TTFont
from fontbakery.checkrunner import (PASS, WARN, FAIL)
from fontbakery.codetesting import (TestingContext,
from fontbakery.codetesting import (assert_PASS,
assert_results_contain,
CheckTester,
portable_path,
TEST_FILE,
assert_PASS,
assert_results_contain)
TEST_FILE)
from fontbakery.profiles import adobefonts as adobefonts_profile

def test_check_family_consistent_upm():
check = TestingContext(adobefonts_profile,
"com.adobe.fonts/check/family/consistent_upm")
check = CheckTester(adobefonts_profile,
"com.adobe.fonts/check/family/consistent_upm")

base_path = TEST_FILE("source-sans-pro/OTF")

Expand All @@ -35,9 +35,8 @@ def test_check_family_consistent_upm():

def test_check_family_consistent_upm_new_style():
# these fonts have a consistent unitsPerEm of 1000:
from fontbakery.codetesting import TestingContext
check = TestingContext(adobefonts_profile,
'com.adobe.fonts/check/family/consistent_upm')
check = CheckTester(adobefonts_profile,
"com.adobe.fonts/check/family/consistent_upm")

filenames = ['SourceSansPro-Regular.otf',
'SourceSansPro-Bold.otf',
Expand Down Expand Up @@ -78,8 +77,8 @@ def test_get_family_checks():


def test_check_find_empty_letters():
check = TestingContext(adobefonts_profile,
"com.adobe.fonts/check/find_empty_letters")
check = CheckTester(adobefonts_profile,
"com.adobe.fonts/check/find_empty_letters")

# this font has inked glyphs for all letters
font = TEST_FILE('source-sans-pro/OTF/SourceSansPro-Regular.otf')
Expand All @@ -96,8 +95,8 @@ def test_check_find_empty_letters():

def test_check_missing_whitespace():
""" Check that overridden test for nbsp yields WARN rather than FAIL. """
check = TestingContext(adobefonts_profile,
"com.google.fonts/check/whitespace_glyphs:adobefonts")
check = CheckTester(adobefonts_profile,
"com.google.fonts/check/whitespace_glyphs:adobefonts")

font = TEST_FILE('source-sans-pro/OTF/SourceSansPro-Regular.otf')
ttFont = TTFont(font)
Expand Down
18 changes: 9 additions & 9 deletions tests/profiles/cff_test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from fontTools.ttLib import TTFont

from fontbakery.codetesting import (TEST_FILE,
assert_PASS,
from fontbakery.codetesting import (assert_PASS,
assert_results_contain,
TestingContext)
CheckTester,
TEST_FILE)
from fontbakery.checkrunner import (DEBUG, INFO, WARN, ERROR, SKIP, PASS, FAIL)
from fontbakery.profiles import cff as cff_profile

check_statuses = (ERROR, FAIL, SKIP, PASS, WARN, INFO, DEBUG)


def test_check_cff_call_depth():
check = TestingContext(cff_profile,
"com.adobe.fonts/check/cff_call_depth")
check = CheckTester(cff_profile,
"com.adobe.fonts/check/cff_call_depth")

# this font's CFF subr call depths should all be <= 10:
font = TEST_FILE('source-sans-pro/OTF/SourceSansPro-Regular.otf')
Expand All @@ -38,8 +38,8 @@ def test_check_cff_call_depth():


def test_check_cff2_call_depth():
check = TestingContext(cff_profile,
"com.adobe.fonts/check/cff2_call_depth")
check = CheckTester(cff_profile,
"com.adobe.fonts/check/cff2_call_depth")

# this font's CFF subr call depths should all be <= 10:
font = TEST_FILE('source-sans-pro/VAR/SourceSansVariable-Roman.otf')
Expand All @@ -65,8 +65,8 @@ def test_check_cff2_call_depth():


def test_check_cff_deprecated_operators():
check = TestingContext(cff_profile,
"com.adobe.fonts/check/cff_deprecated_operators")
check = CheckTester(cff_profile,
"com.adobe.fonts/check/cff_deprecated_operators")

# this font uses the deprecated 'dotsection' operator
font = TEST_FILE('deprecated_operators/cff1_dotsection.otf')
Expand Down
16 changes: 8 additions & 8 deletions tests/profiles/cmap_test.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import pytest
from fontTools.ttLib import TTFont

from fontbakery.codetesting import (TestingContext,
TEST_FILE,
assert_PASS,
assert_results_contain)
from fontbakery.codetesting import (assert_PASS,
assert_results_contain,
CheckTester,
TEST_FILE)
from fontbakery.checkrunner import (DEBUG, INFO, WARN, ERROR, SKIP, PASS, FAIL)
from fontbakery.profiles import opentype as opentype_profile

Expand All @@ -27,8 +27,8 @@ def mada_ttFonts():

def test_check_family_equal_unicode_encodings(mada_ttFonts):
""" Fonts have equal unicode encodings ? """
check = TestingContext(opentype_profile,
"com.google.fonts/check/family/equal_unicode_encodings")
check = CheckTester(opentype_profile,
"com.google.fonts/check/family/equal_unicode_encodings")

from fontbakery.constants import WindowsEncodingID

Expand All @@ -52,8 +52,8 @@ def test_check_family_equal_unicode_encodings(mada_ttFonts):
# Note: I am not aware of any real-case of a font that FAILs this check.
def test_check_all_glyphs_have_codepoints():
""" Check all glyphs have codepoints assigned. """
check = TestingContext(opentype_profile,
"com.google.fonts/check/all_glyphs_have_codepoints")
check = CheckTester(opentype_profile,
"com.google.fonts/check/all_glyphs_have_codepoints")

# our reference Mada SemiBold is know to be good here.
ttFont = TTFont(TEST_FILE("mada/Mada-SemiBold.ttf"))
Expand Down
12 changes: 6 additions & 6 deletions tests/profiles/dsig_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from fontbakery.codetesting import (TEST_FILE,
assert_PASS,
assert_results_contain)
from fontbakery.codetesting import TestingContext
from fontbakery.codetesting import (assert_PASS,
assert_results_contain,
CheckTester,
TEST_FILE)
from fontbakery.checkrunner import FAIL
from fontbakery.profiles import opentype as opentype_profile

Expand All @@ -10,8 +10,8 @@

def test_check_dsig():
""" Does the font have a DSIG table ? """
check = TestingContext(opentype_profile,
"com.google.fonts/check/dsig")
check = CheckTester(opentype_profile,
"com.google.fonts/check/dsig")

# Our reference Cabin Regular font is good (theres a DSIG table declared):
ttFont = TTFont(TEST_FILE("cabin/Cabin-Regular.ttf"))
Expand Down
6 changes: 4 additions & 2 deletions tests/profiles/fontval_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import pytest

from fontbakery.codetesting import (TEST_FILE,
Expand All @@ -9,7 +8,9 @@

def test_check_fontvalidator():
""" MS Font Validator checks """
from fontbakery.profiles.fontval import com_google_fonts_check_fontvalidator as check
# check = CheckTester(fontval_profile,
# "com.google.fonts/check/fontvalidator")
check = fontval_profile.com_google_fonts_check_fontvalidator

font = TEST_FILE("mada/Mada-Regular.ttf")

Expand All @@ -19,6 +20,7 @@ def test_check_fontvalidator():
assert status != ERROR

# Simulate FontVal missing.
import os
old_path = os.environ["PATH"]
os.environ["PATH"] = ""
with pytest.raises(OSError) as _:
Expand Down
Loading

0 comments on commit e1e2c94

Please sign in to comment.