This repository has been archived by the owner on Jan 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic validation of noto for android file
- Loading branch information
Showing
3 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
venv/ | ||
__pycache__/ |
Binary file removed
BIN
-423 Bytes
tests/__pycache__/noto_fonts_for_android_test.cpython-39-pytest-6.2.5.pyc
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,57 @@ | ||
from lxml import etree | ||
from pathlib import Path | ||
import pytest | ||
|
||
def test_noto_for_android_paths(): | ||
pass | ||
|
||
_KNOWN_PATHLESS = { | ||
"NotoSansSyriacEastern-Regular.ttf", | ||
"NotoSansSyriacWestern-Regular.ttf", | ||
"NotoSansSymbols-Regular-Subsetted.ttf", | ||
"NotoColorEmoji.ttf", | ||
"NotoColorEmojiFlags.ttf", | ||
"NotoSansSymbols-Regular-Subsetted2.ttf", | ||
"NotoSansSoyombo-VF.ttf", | ||
} | ||
|
||
|
||
def _repo_root() -> Path: | ||
root = (Path(__file__).parent / "..").absolute() | ||
if not (root / "LICENSE").is_file(): | ||
raise IOError(f"{root} does not contain LICENSE") | ||
return root | ||
|
||
|
||
def _noto_4_android_file() -> Path: | ||
xml_file = _repo_root() / "android-connection" / "noto-fonts-4-android.xml" | ||
if not xml_file.is_file(): | ||
raise IOError(f"No file {xml_file}") | ||
return xml_file | ||
|
||
|
||
def _font_file(font_el) -> str: | ||
return ("".join(font_el.itertext())).strip() | ||
|
||
|
||
def test_fonts_have_path(): | ||
root = etree.parse(str(_noto_4_android_file())) | ||
bad = [] | ||
for font in root.iter("font"): | ||
font_file = _font_file(font) | ||
if font_file in _KNOWN_PATHLESS: | ||
assert "path" not in font.attrib, f"{font_file} not expected to have path. Correct _KNOWN_PATHLESS if you just added path" | ||
continue | ||
|
||
if not font.attrib.get("path", ""): | ||
bad.append(font_file) | ||
assert not bad, "Missing path attribute: " + ", ".join(bad) | ||
|
||
|
||
def test_font_paths_are_valid(): | ||
root = etree.parse(str(_noto_4_android_file())) | ||
bad = [] | ||
for font in root.xpath("//font[@path]"): | ||
path = font.attrib["path"] | ||
file = _font_file(font) | ||
if not (_repo_root() / path / file).is_file(): | ||
bad.append((path, file)) | ||
assert not bad, "No such file: " + ", ".join(bad) |