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

96 lines
3.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
# Copyright (C) 2017 Lukas Winkler
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program. If not, see <http://www.gnu.org/licenses/>.
2017-05-08 20:48:32 +02:00
import hashlib
2017-05-08 17:13:14 +02:00
from glob import glob
2017-05-07 17:30:53 +02:00
import os
import sys
ignored_source_files = [
"src/flags/un.svg",
"src/flags/gb-wls.svg",
"src/flags/gb-sct.svg",
"src/flags/gb-eng.svg",
"src/flags/gb-nir.svg"
]
2017-05-08 20:48:32 +02:00
placeholder_icon_filenames = {
"brand": "unk.png",
"browsers": "UNK.png",
"devices": "unknown.png",
"os": "UNK.png",
"searchEngines": "xx.png",
"socials": "xx.png"
}
placeholder_icon_hash = "398a623a3b0b10eba6d1884b0ff1713ee12aeafaa8efaf67b60a4624f4dce48c"
def test_if_all_icons_are_converted():
global error
for filetype in ["svg", "png", "gif", "jpg", "ico"]:
2017-05-08 17:13:14 +02:00
for file in glob("src/**/*.{}".format(filetype)):
2017-05-07 17:30:53 +02:00
abs_dirname, filename = os.path.split(file)
code = os.path.splitext(filename)[0]
distfolder = "dist/" + abs_dirname[4:]
distfile = "{folder}/{code}.png".format(folder=distfolder, code=code)
2017-05-07 17:30:53 +02:00
if not os.path.isfile(distfile) and file not in ignored_source_files:
print("{file} is missing (From {source})".format(file=distfile, source=file))
error = True
return True
2017-05-07 17:30:53 +02:00
def test_if_source_for_images():
global error
for icontype in ["brand", "browsers", "os", "plugins", "SEO"]:
for filetype in ["svg", "png", "gif", "jpg", "ico"]:
2017-05-08 17:13:14 +02:00
for source_file in glob("src/{type}/*.{filetype}".format(type=icontype, filetype=filetype)):
2017-05-07 17:30:53 +02:00
if not os.path.islink(source_file):
2017-05-08 18:19:55 +02:00
if not os.path.isfile(source_file + ".source") and "UNK" not in source_file:
2017-05-07 17:30:53 +02:00
print("Source is missing for {file}".format(file=source_file))
error = True
2017-05-08 17:13:14 +02:00
def test_if_all_symlinks_are_valid():
global error
for file in glob("src/**/*"):
if os.path.islink(file) and not os.path.exists(file):
print(
2017-05-08 18:19:55 +02:00
"Symlink doesn't link to file (from {link} to {target}".format(link=file, target=os.readlink(file))
2017-05-08 17:13:14 +02:00
)
error = True
2017-05-08 20:48:32 +02:00
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):
print("The placeholder icon {path} is missing or invalid".format(path=file))
error = True
if __name__ == '__main__':
error = False
if 'TRAVIS_PULL_REQUEST' not in os.environ or not os.environ['TRAVIS_PULL_REQUEST']:
test_if_all_icons_are_converted()
2017-05-07 17:30:53 +02:00
test_if_source_for_images()
2017-05-08 17:13:14 +02:00
test_if_all_symlinks_are_valid()
2017-05-08 20:48:32 +02:00
test_if_placeholder_icon_exist()
sys.exit(error)