Skip to content

Commit

Permalink
Skip tests based on certain conditions (missing features), fixes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Nov 25, 2022
1 parent 559a588 commit 8b16afd
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 21 deletions.
4 changes: 4 additions & 0 deletions shaperglot/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,9 @@ def check(self, lang):
self.results = Reporter()
self.lang = lang
for check_object in self.lang.get("shaperglot_checks", []):
skip_reason = check_object.should_skip(self)
if skip_reason:
self.results.skip(check_name=check_object.name, message=skip_reason)
continue
check_object.execute(self)
return self.results
34 changes: 33 additions & 1 deletion shaperglot/checks/common.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from strictyaml import Str, Map, Optional, MapPattern, Bool
from strictyaml import Str, Map, Optional, MapPattern, Bool, Seq

shaping_input_schema = Map(
{
Expand All @@ -8,6 +8,22 @@
}
)

conditions_schema = Map(
{
Optional("features"): Seq(Str())
}
)

def check_schema(schema):
base_schema = {
"check": Str(),
Optional("rationale"): Str(),
Optional("conditions"): conditions_schema
}
schema.update(base_schema)
return Map(schema)


def and_join(lst):
lst = list(lst)
if len(lst) == 0:
Expand Down Expand Up @@ -57,3 +73,19 @@ def __init__(self, check_yaml):
self.inputs = [ShapeInput(x) for x in check_yaml["inputs"]]
if "input" in check_yaml:
self.input = ShapeInput(check_yaml["input"])

def should_skip(self, checker):
conditions = self.definition.get("conditions")
if conditions is None:
return False
if "features" in conditions:
font_features = set()
for table in ["GSUB", "GPOS"]:
if checker.ttfont.get(table) and checker.ttfont[table].table.FeatureList:
for fr in checker.ttfont[table].table.FeatureList.FeatureRecord:
font_features.add(fr.FeatureTag)
required = set([ str(f) for f in conditions["features"] ])
if required - font_features:
return f"Missing features: {', '.join(required-font_features)}"
return False

6 changes: 2 additions & 4 deletions shaperglot/checks/no_orphaned_marks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from strictyaml import Str, Map, Optional
from youseedee import ucd_data

from .common import shaping_input_schema, ShaperglotCheck
from .common import shaping_input_schema, ShaperglotCheck, check_schema


@cache
Expand All @@ -13,11 +13,9 @@ def _simple_mark_check(codepoint):

class NoOrphanedMarksCheck(ShaperglotCheck):
name = "no_orphaned_marks"
schema = Map(
schema = check_schema(
{
"check": Str(),
"input": shaping_input_schema,
Optional("rationale"): Str(),
}
)

Expand Down
3 changes: 3 additions & 0 deletions shaperglot/checks/orthographies.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ def __init__(self, lang):
self.marks = set(marks)
self.bases = set(bases) - self.marks

def should_skip(self, checker):
return False

def describe(self):
return "that the following glyphs are in the font: " + and_join(
f"'{g}'" for g in self.all_glyphs
Expand Down
6 changes: 2 additions & 4 deletions shaperglot/checks/shaping_differs.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
from strictyaml import FixedSeq, Str, Map, Int, Optional
from num2words import num2words

from .common import shaping_input_schema, ShaperglotCheck
from .common import shaping_input_schema, ShaperglotCheck, check_schema

cluster_schema = Map({Optional("cluster"): Int(), "glyph": Int()})


class ShapingDiffersCheck(ShaperglotCheck):
name = "shaping_differs"
schema = Map(
schema = check_schema(
{
"check": Str(),
"inputs": FixedSeq([shaping_input_schema, shaping_input_schema]),
Optional("differs"): FixedSeq([cluster_schema, cluster_schema]),
Optional("rationale"): Str(),
}
)

Expand Down
24 changes: 12 additions & 12 deletions shaperglot/checks/unencoded_variants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@
from strictyaml import Str, Map, Optional
from youseedee import ucd_data

from .common import shaping_input_schema, ShaperglotCheck
from .common import shaping_input_schema, ShaperglotCheck, check_schema


class UnencodedVariantsCheck(ShaperglotCheck):
name = "unencoded_variants"
schema = Map(
schema = check_schema(
{
"check": Str(),
"input": shaping_input_schema,
Optional("rationale"): Str(),
}
)

Expand All @@ -21,18 +19,22 @@ def describe(self):

def execute(self, checker):
if len(self.input.text) > 1:
raise ValueError(f"Please only pass one codepoint at a time to the unencoded variants check (not '{self.input.text}')")
raise ValueError(
f"Please only pass one codepoint at a time to the unencoded variants check (not '{self.input.text}')"
)
self.input.features["locl"] = False
buffer = self.input.shape(checker)
glyphname = checker.glyphorder[buffer.glyph_infos[0].codepoint]
# Are there variant versions of this glyph?
variants = [glyph for glyph in checker.glyphorder if glyph.startswith(glyphname+".")]
variants = [
glyph for glyph in checker.glyphorder if glyph.startswith(glyphname + ".")
]
if not variants:
checker.results.warn(
check_name="unencoded-variants",
result_code="no-variant",
message="No variant glyphs were found for "+glyphname,
context = { "text": self.input.check_yaml, "glyph": glyphname }
message="No variant glyphs were found for " + glyphname,
context={"text": self.input.check_yaml, "glyph": glyphname},
)
return
# Try it again with locl on, set the language to the one we're
Expand All @@ -47,13 +49,11 @@ def execute(self, checker):
check_name="unencoded-variants",
result_code="unchanged-after-locl",
message=f"The locl feature did not affect {glyphname}",
context = { "text": self.input.check_yaml, "glyph": glyphname }
context={"text": self.input.check_yaml, "glyph": glyphname},
)
else:
checker.results.okay(
check_name="unencoded-variants",
message=f"The locl feature changed {glyphname} to {glyphname2}",
context= { "text": self.input.check_yaml, "glyph": glyphname }
context={"text": self.input.check_yaml, "glyph": glyphname},
)


0 comments on commit 8b16afd

Please sign in to comment.