Updated tests/fonttest_playbook.yml, now pulling test from git repo and execute
This commit is contained in:
parent
c913602e05
commit
5a16700df0
@ -1,141 +0,0 @@
|
||||
import subprocess
|
||||
import sys
|
||||
import json
|
||||
from ast import literal_eval
|
||||
|
||||
class fonttest:
|
||||
|
||||
|
||||
def __init__(self, config):
|
||||
self.fontname = config["fontname"]
|
||||
self.coverage_lang_list = config["lang"]
|
||||
self.logfilepath = config["logfilepath"]
|
||||
self.out = dict()
|
||||
self.out["err"] = list()
|
||||
self.test_init()
|
||||
|
||||
|
||||
def execute_command(self, command_str):
|
||||
'''
|
||||
Execute cli commands and return output
|
||||
'''
|
||||
out, err = subprocess.Popen(command_str, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
|
||||
return (str(out, 'utf-8'), str(err, 'utf-8'))
|
||||
|
||||
|
||||
def get_font_family(self):
|
||||
'''
|
||||
This function will excute fc-list and create fontfamily, font file path list
|
||||
'''
|
||||
# get font family
|
||||
font_family, err = self.execute_command("fc-list | grep {0} | cut -d':' -f2".format(self.fontname))
|
||||
#get all font file path
|
||||
font_filepath, err = self.execute_command("fc-list | grep {0} | cut -d':' -f1".format(self.fontname))
|
||||
font_filepath = font_filepath.split("\n")
|
||||
self.out["font file list"] = list(filter(None, font_filepath))
|
||||
|
||||
# if font file exist create a font family list
|
||||
if not err and font_family:
|
||||
font_family = set(font_family.split("\n"))
|
||||
font_family = map(str.strip, font_family)
|
||||
self.out["font family list"] = list(filter(None, font_family))
|
||||
# return self.out_font_family
|
||||
else:
|
||||
self.out["err"].append("invalid test or parameter in font family test")
|
||||
self.out["err"].append(err)
|
||||
sys.stdout.write("invalid test or parameter in font family test")
|
||||
|
||||
|
||||
def get_font_conf(self):
|
||||
'''
|
||||
This function will get all conf file path for given font
|
||||
'''
|
||||
|
||||
# get list of font conf files
|
||||
font_conflist, err = self.execute_command("fc-conflist | grep {0}".format(self.fontname))
|
||||
|
||||
if not err and font_conflist:
|
||||
font_conflist = font_conflist.split("\n")
|
||||
self.out["font conf list"] = list(filter(None, font_conflist))
|
||||
else:
|
||||
self.out["err"].append("invalid test or parameter in font conf test")
|
||||
self.out["err"].append(err)
|
||||
sys.stdout.write("invalid test or parameter in font conf test")
|
||||
|
||||
def get_lang_coverage(self):
|
||||
'''
|
||||
This function will check language coverage as specifed in parameter with fontfiles
|
||||
'''
|
||||
|
||||
self.out["lang covarage"] = dict()
|
||||
for font_file_path in self.out["font file list"]:
|
||||
# get all lang covarage by font
|
||||
font_langlist, err = self.execute_command("fc-query -f 'lang: %{lang}' "+font_file_path)
|
||||
PendingDeprecationWarning
|
||||
if not err and font_langlist:
|
||||
font_langlist = font_langlist.split("|")
|
||||
font_langlist[0] = font_langlist[0].replace("lang: ","")
|
||||
out_lang_dict = dict()
|
||||
for lang in self.coverage_lang_list:
|
||||
out_lang_dict[lang] = lang in font_langlist
|
||||
|
||||
self.out["lang covarage"][font_file_path] = out_lang_dict
|
||||
|
||||
if False in out_lang_dict.values():
|
||||
self.out["err"].append("one or more lang coverage failed for font file:{0}".format(font_file_path))
|
||||
self.out["err"].append(out_lang_dict)
|
||||
sys.stdout.write("fail")
|
||||
else:
|
||||
self.out["err"].append("invalid test or parameter in font lang coverage test")
|
||||
self.out["err"].append(err)
|
||||
sys.stdout.write("invalid test or parameter in font lang coverage test")
|
||||
|
||||
|
||||
def testlog_generator(self):
|
||||
'''
|
||||
This function will generate a testlog and dump all metainfo generated into /tmp/test.log
|
||||
'''
|
||||
with open(self.logfilepath, "w") as file:
|
||||
|
||||
file.write("\nErrors:\n")
|
||||
if not self.out["err"]:
|
||||
file.write("No errors")
|
||||
else:
|
||||
Json = json.dumps(self.out["err"])
|
||||
file.write(Json)
|
||||
|
||||
file.write("\n\nFont Family list:\n")
|
||||
file.write("\n".join(self.out["font family list"]))
|
||||
|
||||
file.write("\n\nFont conf list:\n")
|
||||
file.write("\n".join(self.out["font conf list"]))
|
||||
|
||||
file.write("\n\nFont file list:\n")
|
||||
file.write("\n".join(self.out["font file list"]))
|
||||
|
||||
file.write("\n\nLang coverage:\n")
|
||||
Json = json.dumps(self.out["lang covarage"])
|
||||
for key, value in self.out["lang covarage"].items():
|
||||
jvalue = json.dumps(value)
|
||||
file.write(key +" : "+ jvalue+"\n")
|
||||
|
||||
|
||||
def test_init(self):
|
||||
'''
|
||||
This function invokes all other test methods.
|
||||
'''
|
||||
|
||||
self.get_font_family()
|
||||
self.get_font_conf()
|
||||
self.get_lang_coverage()
|
||||
self.testlog_generator()
|
||||
|
||||
if self.out["err"]:
|
||||
sys.stderr.write("Test failed\n")
|
||||
else:
|
||||
sys.stdout.write("All Test Passed\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
config = literal_eval(sys.argv[1])
|
||||
fonttest(config)
|
@ -1,12 +1,14 @@
|
||||
- hosts: localhost
|
||||
vars:
|
||||
config:
|
||||
artifacts: "{{ lookup('env', 'TEST_ARTIFACTS')|default('./artifacts', true) }}"
|
||||
fontname: liberation
|
||||
lang: ["en","az-az","de","el","he"]
|
||||
testgiturl: https://pagure.io/font_ci_testing.git
|
||||
testgitclonepath: /tmp/fonttest/
|
||||
testfilename: fonttest.py
|
||||
testfilepath: /usr/local/bin
|
||||
logfilepath: /tmp/test.log
|
||||
fontname: liberation
|
||||
lang: ["en","az-az","de","el","he"]
|
||||
artifacts: "{{ lookup('env', 'TEST_ARTIFACTS')|default('./artifacts', true) }}"
|
||||
|
||||
tags:
|
||||
- classic
|
||||
@ -21,8 +23,13 @@
|
||||
- python3
|
||||
- fontconfig
|
||||
|
||||
- name: git clone the tests
|
||||
git:
|
||||
repo: "{{ config.testgiturl }}"
|
||||
dest: "{{ config.testgitclonepath }}"
|
||||
|
||||
- name: Install the test files
|
||||
copy: src={{ config.testfilename }} dest={{ config.testfilepath }}/{{ config.testfilename }} mode=0755
|
||||
copy: src={{ config.testgitclonepath }}/tests/{{ config.testfilename }} dest={{ config.testfilepath }}/{{ config.testfilename }} mode=0755
|
||||
|
||||
- name: Test Execution
|
||||
block:
|
||||
@ -36,4 +43,4 @@
|
||||
src: "{{ item }}"
|
||||
flat: yes
|
||||
with_items:
|
||||
- "{{ config.logfilepath }}"
|
||||
- "{{ config.logfilepath }}"
|
||||
|
Loading…
Reference in New Issue
Block a user