]> git.ipfire.org Git - thirdparty/google/fonts.git/commitdiff
use pytest
authorMarc Foley <m.foley.88@gmail.com>
Tue, 26 Nov 2024 14:42:31 +0000 (14:42 +0000)
committerMarc Foley <m.foley.88@gmail.com>
Tue, 26 Nov 2024 14:44:47 +0000 (14:44 +0000)
.ci/test_font_tags.py

index 7263e0f0f6d9cc731207661562ca909126da1053..07567f2f3bd2b36b5a85490e506516e9f532a17f 100644 (file)
@@ -1,33 +1,44 @@
+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:
+
+@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")
+    )
+    import csv
+
+    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)