1
0
Fork 0
mirror of https://github.com/matomo-org/matomo-icons.git synced 2024-09-19 17:03:45 +02:00

add test for small source images

This commit is contained in:
Lukas Winkler 2017-05-10 17:28:14 +02:00
parent 8991835681
commit 2aa48dc319
2 changed files with 35 additions and 3 deletions

View file

@ -1,3 +1,4 @@
beautifulsoup4==4.5.3
PyYAML==3.12
requests==2.13.0
Pillow==4.1.1

View file

@ -16,6 +16,7 @@ import hashlib
from glob import glob
import os
import sys
from PIL import Image
ignored_source_files = [
"src/flags/un.svg",
@ -34,6 +35,8 @@ placeholder_icon_filenames = {
"socials": "xx.png"
}
min_image_size = 48
placeholder_icon_hash = "398a623a3b0b10eba6d1884b0ff1713ee12aeafaa8efaf67b60a4624f4dce48c"
@ -78,18 +81,46 @@ def test_if_placeholder_icon_exist():
global error
for folder, filename in placeholder_icon_filenames.items():
file = "src/{folder}/{filename}".format(folder=folder, filename=filename)
if not (os.path.isfile(file) and hashlib.sha256(open(file, 'rb').read()).hexdigest() == placeholder_icon_hash):
if not (os.path.isfile(file) and hashlib.sha256(open(file, "rb").read()).hexdigest() == placeholder_icon_hash):
print("The placeholder icon {path} is missing or invalid".format(path=file))
error = True
if __name__ == '__main__':
def test_if_icons_are_large_enough():
# ignore searchEngines and socials
for icontype in ["brand", "browsers", "devices", "flags", "os", "plugins", "SEO"]:
for filetype in ["png", "gif", "jpg", "ico"]:
for source_file in glob("src/{type}/*.{filetype}".format(type=icontype, filetype=filetype)):
im = Image.open(source_file)
if im.size[0] < min_image_size or im.size[1] < min_image_size:
print(
"{file} is smaller ({width}x{height}) that the target size ({target}x{target})".format(
file=source_file,
width=im.size[0],
height=im.size[1],
target=min_image_size
)
)
if filetype in ["jpg", "gif", "ico"]:
print("{file} is saved in a lossy image format ({filetype}). ".format(
file=source_file,
filetype=filetype
) + "Maybe try to find an PNG or SVG from another source.")
if __name__ == "__main__":
error = False
if 'TRAVIS_PULL_REQUEST' not in os.environ or not os.environ['TRAVIS_PULL_REQUEST']:
if "TRAVIS_PULL_REQUEST" not in os.environ or not os.environ["TRAVIS_PULL_REQUEST"]:
test_if_all_icons_are_converted()
test_if_source_for_images()
test_if_all_symlinks_are_valid()
test_if_placeholder_icon_exist()
if "TRAVIS" in os.environ and os.environ["TRAVIS"]: # collapse on travis
print("travis_fold:start:small_icons")
test_if_icons_are_large_enough()
print("travis_fold:end:small_icons")
else:
test_if_icons_are_large_enough()
sys.exit(error)