mirror of
https://github.com/google/fonts.git
synced 2024-11-24 09:43:46 +03:00
CI: tests for designer profiles (#3268)
This commit is contained in:
parent
537ba8a1da
commit
5069c3df0e
@ -12,6 +12,7 @@ echo "PR url: $PR_URL"
|
||||
for dir in $CHANGED_DIRS
|
||||
do
|
||||
font_count=$(ls -1 $dir*.ttf 2>/dev/null | wc -l)
|
||||
is_designer_dir=$(echo $dir | grep "designers")
|
||||
if [ $font_count != 0 ]
|
||||
then
|
||||
echo "Checking $dir"
|
||||
@ -27,6 +28,10 @@ do
|
||||
echo "Fonts have not been modified. Checking fonts with Fontbakery only"
|
||||
gftools qa -f $dir*.ttf --fontbakery -o $OUT/$(basename $dir)_qa --out-url $PR_URL
|
||||
fi
|
||||
elif [ ! -z $is_designer_dir ]
|
||||
then
|
||||
echo "Checking designer profile"
|
||||
pytest .ci/test_profiles.py $dir
|
||||
else
|
||||
echo "Skipping $dir. Directory does not contain fonts"
|
||||
fi
|
||||
|
88
.ci/test_profiles.py
Normal file
88
.ci/test_profiles.py
Normal file
@ -0,0 +1,88 @@
|
||||
import pytest
|
||||
import sys
|
||||
import os
|
||||
from bs4 import BeautifulSoup
|
||||
import requests
|
||||
from fontbakery.designers_pb2 import DesignerInfoProto
|
||||
from google.protobuf import text_format
|
||||
|
||||
|
||||
# TODO this could potentially be a fontbakery profile
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def profile_dir():
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: python test_profiles fonts/catalog/designers/designerprofile")
|
||||
sys.exit(1)
|
||||
return sys.argv[-1]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def proto_info(profile_dir):
|
||||
info_file = os.path.join(profile_dir, "info.pb")
|
||||
with open(info_file, "rb") as info:
|
||||
text = info.read()
|
||||
return load_info_proto(text)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def bio(profile_dir):
|
||||
bio_file = os.path.join(profile_dir, "bio.html")
|
||||
with open(bio_file) as html:
|
||||
return BeautifulSoup(html.read(), features="lxml")
|
||||
|
||||
|
||||
def load_info_proto(text_data):
|
||||
message = DesignerInfoProto()
|
||||
text_format.Merge(text_data, message)
|
||||
return message
|
||||
|
||||
|
||||
def test_profile_dir_exists(profile_dir):
|
||||
assert os.path.exists(profile_dir)
|
||||
|
||||
|
||||
def test_profile_dir_has_bio(profile_dir):
|
||||
assert "bio.html" in os.listdir(profile_dir), "bio.html is missing"
|
||||
|
||||
|
||||
def test_profile_dir_has_info(profile_dir):
|
||||
assert "info.pb" in os.listdir(profile_dir), "info.pb is missing"
|
||||
|
||||
|
||||
def test_profile_has_correct_img(profile_dir):
|
||||
assert not any(f for f in os.listdir(profile_dir) if f.endswith((".jpg", ".jpeg")))
|
||||
assert any(
|
||||
f for f in os.listdir(profile_dir) if f.endswith(".png")
|
||||
), "Profile is missing png image"
|
||||
|
||||
|
||||
def test_profile_info_image_link_is_correct(profile_dir, proto_info):
|
||||
img_path = proto_info.avatar.file_name
|
||||
assert img_path in os.listdir(profile_dir), "info.pb: image path is incorrect"
|
||||
|
||||
|
||||
def test_info_link(proto_info):
|
||||
link = proto_info.link
|
||||
assert (
|
||||
"plus.google" not in link
|
||||
), "Google+ links are no longer supported. Please replace."
|
||||
|
||||
|
||||
def test_info_link_works(proto_info):
|
||||
link = proto_info.link
|
||||
if "instagram.com" in link:
|
||||
return
|
||||
assert requests.get(link).status_code == 200, "info.pb: link is not producing a 200 status code"
|
||||
|
||||
|
||||
def test_bio_links_work(bio):
|
||||
urls = bio.find_all("a", href=True)
|
||||
urls = [u["href"] for u in urls]
|
||||
for url in urls:
|
||||
if "instagram.com" in url: # these have a habit of raise a 4xx status code
|
||||
continue
|
||||
assert (
|
||||
requests.get(url).status_code == 200
|
||||
), f"{url} is not producing a 200 status code"
|
2
.github/workflows/test.yaml
vendored
2
.github/workflows/test.yaml
vendored
@ -29,7 +29,7 @@ jobs:
|
||||
run: |
|
||||
sudo apt install libharfbuzz-dev libharfbuzz-bin libfreetype6-dev libglib2.0-dev libcairo2-dev
|
||||
python -m pip install --upgrade pip
|
||||
pip install gftools[qa]
|
||||
pip install gftools[qa] pytest
|
||||
- name: Check fonts
|
||||
env:
|
||||
GF_API_KEY: ${{ secrets.GF_API_KEY }}
|
||||
|
Loading…
Reference in New Issue
Block a user