-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8596 from google/font-tag-ci
ci test_font_tags: Add more checks
- Loading branch information
Showing
1 changed file
with
52 additions
and
24 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,33 +1,61 @@ | ||
import pytest | ||
import json | ||
from urllib.request import urlopen | ||
import sys | ||
|
||
dev_data = json.loads( | ||
urlopen("https://fonts.google.com/metadata/fonts").read().decode("utf-8") | ||
) | ||
dev_families = set(f["family"] for f in dev_data["familyMetadataList"]) | ||
|
||
csv_data = ( | ||
urlopen("https://raw.githubusercontent.com/google/fonts/main/tags/all/families.csv") | ||
.read() | ||
.decode("utf-8") | ||
) | ||
csv_families = set( | ||
line.split(",")[0] | ||
for line in csv_data.split("\n") | ||
if line | ||
if line.split(",")[0] != "Family" | ||
) | ||
|
||
families_missing_tags = sorted(dev_families - csv_families) | ||
|
||
if families_missing_tags: | ||
import csv | ||
|
||
|
||
@pytest.fixture | ||
def family_metadata(): | ||
data = json.loads( | ||
urlopen("https://fonts.google.com/metadata/fonts").read().decode("utf-8") | ||
) | ||
return data["familyMetadataList"] | ||
|
||
|
||
@pytest.fixture | ||
def family_tags(): | ||
csv_data = ( | ||
urlopen( | ||
"https://raw.githubusercontent.com/google/fonts/main/tags/all/families.csv" | ||
) | ||
.read() | ||
.decode("utf-8") | ||
) | ||
reader = csv.reader(csv_data.splitlines()) | ||
res = [] | ||
for row in reader: | ||
res.append([row[0], row[1], float(row[2])]) | ||
return res | ||
|
||
|
||
def test_families_missing_tags(family_tags, family_metadata): | ||
tagged_families = set(f[0] for f in family_tags) | ||
families_in_gf = set(f["family"] for f in family_metadata) | ||
families_missing_tags = sorted(families_in_gf - tagged_families) | ||
missing_list = "\n".join(families_missing_tags) | ||
raise ValueError( | ||
|
||
assert len(families_missing_tags) == 0, ( | ||
f"The following {len(families_missing_tags)} families are missing tags:\n\n" | ||
f"{missing_list}\n\n" | ||
"Please add tags for these families using the following webapp: " | ||
"https://google.github.io/fonts/tags.html" | ||
) | ||
|
||
sys.exit(0) | ||
|
||
def test_no_duplicate_families(family_tags): | ||
seen = set() | ||
dups = [] | ||
for family, cat, _ in family_tags: | ||
key = (family, cat) | ||
if key in seen: | ||
dups.append(",".join(key)) | ||
seen.add(key) | ||
assert not dups, f"Duplicate tags found: {dups}" | ||
|
||
|
||
def test_tag_vals_in_range(family_tags): | ||
out_of_range = [] | ||
for family, cat, val in family_tags: | ||
if val <= 0 or val > 100: | ||
out_of_range.append((family, cat, val)) | ||
assert not out_of_range, f"Values out of range 1-100: {out_of_range}" |