Skip to content

Commit

Permalink
further refactoring codetests
Browse files Browse the repository at this point in the history
  • Loading branch information
felipesanches committed Nov 8, 2024
1 parent 3268a83 commit cd382ac
Show file tree
Hide file tree
Showing 39 changed files with 402 additions and 446 deletions.
16 changes: 1 addition & 15 deletions tests/test_checks_fontval.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,12 @@
import shutil
import sys

import pytest

from conftest import check_id, ImportRaiser, remove_import_raiser

from conftest import check_id
from fontbakery.codetesting import TEST_FILE, assert_results_contain
from fontbakery.status import ERROR


def test_extra_needed_exit(monkeypatch):
module_name = "lxml.etree"
sys.meta_path.insert(0, ImportRaiser(module_name))
monkeypatch.delitem(sys.modules, module_name, raising=False)
from fontbakery.checks.fontval import check_fontvalidator

with pytest.raises(SystemExit):
list(check_fontvalidator(None, None))

remove_import_raiser(module_name)


@pytest.mark.skipif(
not shutil.which("FontValidator"),
reason="FontValidator is not installed on your system",
Expand Down
29 changes: 1 addition & 28 deletions tests/test_checks_googlefonts.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import math
import os
import shutil
import sys

import pytest
import requests
from conftest import check_id, ImportRaiser, remove_import_raiser
from conftest import check_id
from fontTools.ttLib import TTFont

from fontbakery.checks.vendorspecific.googlefonts.conditions import (
Expand Down Expand Up @@ -110,32 +109,6 @@ def cabin_regular_path():
return portable_path("data/test/cabin/Cabin-Regular.ttf")


@check_id("googlefonts/metadata/designer_profiles")
def test_extra_needed_exit_from_conditions(check, monkeypatch):
module_name = "google.protobuf"
sys.meta_path.insert(0, ImportRaiser(module_name))
monkeypatch.delitem(sys.modules, module_name, raising=False)

with pytest.raises(SystemExit):
font = TEST_FILE("merriweather/Merriweather-Regular.ttf")
check(font)

remove_import_raiser(module_name)


@check_id("googlefonts/canonical_filename")
def test_extra_needed_exit(check, monkeypatch):
module_name = "axisregistry"
sys.meta_path.insert(0, ImportRaiser(module_name))
monkeypatch.delitem(sys.modules, module_name, raising=False)

with pytest.raises(SystemExit):
ttFont = TTFont(TEST_FILE("cabinvfbeta/Cabin-VF.ttf"))
check(ttFont)

remove_import_raiser(module_name)


@pytest.mark.parametrize(
"""fp,result""",
[
Expand Down
6 changes: 3 additions & 3 deletions tests/test_checks_gpos_kerning_info.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from fontTools.ttLib import TTFont

from conftest import check_id
from fontbakery.codetesting import (
TEST_FILE,
assert_PASS,
assert_results_contain,
CheckTester,
)
from fontbakery.status import WARN


def test_check_gpos_kerning_info():
@check_id("gpos_kerning_info")
def test_check_gpos_kerning_info(check):
"""Does GPOS table have kerning information?"""
check = CheckTester("gpos_kerning_info")

# Our reference Mada Regular is known to have kerning-info
# exclusively on an extension subtable
Expand Down
7 changes: 4 additions & 3 deletions tests/test_checks_interpolation_issues.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from fontTools.ttLib import TTFont

from conftest import check_id
from fontbakery.status import SKIP, WARN
from fontbakery.codetesting import (
assert_PASS,
assert_results_contain,
CheckTester,
TEST_FILE,
)


def test_check_interpolation_issues():
@check_id("interpolation_issues")
def test_check_interpolation_issues(check):
"""Detect any interpolation issues in the font."""
check = CheckTester("interpolation_issues")

# With a good font
ttFont = TTFont(TEST_FILE("cabinvf/Cabin[wdth,wght].ttf"))
assert_PASS(check(ttFont))
Expand Down
40 changes: 11 additions & 29 deletions tests/test_checks_iso15008.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,15 @@
import sys

import pytest

from conftest import ImportRaiser, remove_import_raiser

from conftest import check_id
from fontbakery.status import FAIL
from fontbakery.codetesting import (
assert_PASS,
assert_results_contain,
CheckTester,
TEST_FILE,
)


def test_extra_needed_exit(monkeypatch):
module_name = "uharfbuzz"
sys.meta_path.insert(0, ImportRaiser(module_name))
monkeypatch.delitem(sys.modules, module_name, raising=False)
from fontbakery.checks.iso15008 import pair_kerning

with pytest.raises(SystemExit):
pair_kerning(None, None, None)

remove_import_raiser(module_name)


def test_check_iso15008_proportions():
@check_id("iso15008/proportions")
def test_check_iso15008_proportions(check):
"""Check if 0.65 => (H width / H height) => 0.80"""
check = CheckTester("iso15008/proportions")

# Cabin has a proportion of 0.7, so that's good.
font = TEST_FILE("cabin/Cabin-Regular.ttf")
Expand All @@ -52,9 +34,9 @@ def test_check_iso15008_proportions():
)


def test_check_iso15008_stem_width():
@check_id("iso15008/stem_width")
def test_check_iso15008_stem_width(check):
"""Check if 0.10 <= (stem width / ascender) <= 0.82"""
check = CheckTester("iso15008/stem_width")

font = TEST_FILE("cabin/Cabin-SemiBold.ttf")
assert_PASS(check(font), "with a good font...")
Expand All @@ -75,9 +57,9 @@ def test_check_iso15008_stem_width():
)


def test_check_iso15008_intercharacter_spacing():
@check_id("iso15008/intercharacter_spacing")
def test_check_iso15008_intercharacter_spacing(check):
"""Check if spacing between characters is adequate for display use"""
check = CheckTester("iso15008/intercharacter_spacing")

font = TEST_FILE("cabin/Cabin-Regular.ttf")
assert_PASS(check(font), "with a good font...")
Expand Down Expand Up @@ -111,9 +93,9 @@ def test_check_iso15008_intercharacter_spacing():
)


def test_check_iso15008_interword_spacing():
@check_id("iso15008/interword_spacing")
def test_check_iso15008_interword_spacing(check):
"""Check if spacing between words is adequate for display use"""
check = CheckTester("iso15008/interword_spacing")

font = TEST_FILE("cabin/CabinCondensed-Bold.ttf")
# lm space is 112; m+space+l space is 286; 286/112 = 255%
Expand All @@ -126,9 +108,9 @@ def test_check_iso15008_interword_spacing():
)


def test_check_iso15008_interline_spacing():
@check_id("iso15008/interline_spacing")
def test_check_iso15008_interline_spacing(check):
"""Check if spacing between lines is adequate for display use"""
check = CheckTester("iso15008/interline_spacing")

font = TEST_FILE("cabin/Cabin-Regular.ttf")
assert_PASS(check(font), "with a good font...")
Expand Down
6 changes: 3 additions & 3 deletions tests/test_checks_kerning.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from fontTools.ttLib import TTFont

from conftest import check_id
from fontbakery.codetesting import (
# assert_PASS, FIXME: We must also have PASS test-cases!
assert_results_contain,
CheckTester,
TEST_FILE,
MockFont,
)
from fontbakery.status import FAIL, WARN, SKIP


def test_check_kerning_for_non_ligated_sequences():
@check_id("kerning_for_non_ligated_sequences")
def test_check_kerning_for_non_ligated_sequences(check):
"""Is there kerning info for non-ligated sequences ?"""
check = CheckTester("kerning_for_non_ligated_sequences")

# Our reference Mada Medium doesn't have a GSUB 'liga' feature, so it is skipped
# because of an unfulfilled condition.
Expand Down
6 changes: 3 additions & 3 deletions tests/test_checks_legacy_accents.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from fontTools.ttLib import TTFont

from conftest import check_id
from fontbakery.status import FAIL
from fontbakery.codetesting import (
assert_PASS,
assert_results_contain,
CheckTester,
TEST_FILE,
)


def test_check_legacy_accents():
@check_id("legacy_accents")
def test_check_legacy_accents(check):
"""Check that legacy accents aren't used in composite glyphs."""
check = CheckTester("legacy_accents")

test_font = TTFont(TEST_FILE("montserrat/Montserrat-Regular.ttf"))
assert_PASS(check(test_font))
Expand Down
6 changes: 3 additions & 3 deletions tests/test_checks_ligature_carets.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
from fontTools.ttLib import TTFont

from conftest import check_id
from fontbakery.codetesting import (
# assert_PASS, FIXME: We must also have PASS test-cases!
assert_results_contain,
CheckTester,
TEST_FILE,
MockFont,
)
from fontbakery.status import FAIL, WARN, SKIP


def test_check_ligature_carets():
@check_id("ligature_carets")
def test_check_ligature_carets(check):
"""Is there a caret position declared for every ligature?"""
check = CheckTester("ligature_carets")

# Our reference Mada Medium doesn't have a GSUB 'liga' feature, so it is skipped
# because of an unfulfilled condition.
Expand Down
6 changes: 3 additions & 3 deletions tests/test_checks_math_signs_width.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from conftest import check_id
from fontbakery.status import WARN
from fontbakery.codetesting import (
assert_PASS,
assert_results_contain,
CheckTester,
TEST_FILE,
)


def test_check_math_signs_width():
@check_id("math_signs_width")
def test_check_math_signs_width(check):
"""Check font math signs have the same width."""
check = CheckTester("math_signs_width")

# The STIXTwo family was the reference font project
# that we used to come up with the initial list of math glyphs
Expand Down
Loading

0 comments on commit cd382ac

Please sign in to comment.