Last active
January 9, 2020 14:50
-
-
Save AutomatedTester/abc1b20b3967f3ff92a828e4d23f345b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import configparser | |
import glob | |
import os | |
import errno | |
CSS_IMPORT_PATH = "testing/web-platform/tests/css/vendor-imports/mozilla/mozilla-central-reftests/text-decor-3/" | |
CSS_IMPORT_META_PATH = "testing/web-platform/meta/css/vendor-imports/mozilla/mozilla-central-reftests/text-decor-3/" | |
def get_ini(test_file): | |
config = configparser.ConfigParser() | |
config.read( | |
"testing/web-platform/meta/css/vendor-imports/mozilla/mozilla-central-reftests/{}.ini".format(test_file)) | |
return config | |
def find_reftest(tokens): | |
for tk in tokens: | |
#import pdb; pdb.set_trace() | |
if tk.endswith('xht') or tk.endswith('html'): | |
return "testing/web-platform/meta/css/vendor-imports/mozilla/mozilla-central-reftests/text-decor-3/{}.ini".format(tk) | |
print "Couldn't find a file name in tokens {}".format(tokens) | |
def convert_os(reftest_os, not_=False): | |
converted = "" | |
if reftest_os == "OSX" or reftest_os == "cocoaWidget": | |
if not not_: | |
converted = '(os == "mac")' | |
else: | |
converted = '(os != "mac")' | |
elif reftest_os == "Android": | |
if not not_: | |
converted = '(os == "android")' | |
else: | |
converted = '(os != "android")' | |
elif reftest_os == 'winWidget': | |
if not not_: | |
converted = '(os == "win")' | |
else: | |
converted = '(os != "win")' | |
elif reftest_os == "webrender": | |
if not not_: | |
converted = reftest_os | |
else: | |
converted = "not {}".format(reftest_os) | |
elif reftest_os == "gtkWidget": | |
if not not_: | |
converted = '(os == "linux")' | |
else: | |
converted = '(os != "linux")' | |
elif reftest_os == "isDebugBuild": | |
if not not_: | |
converted = 'debug' | |
else: | |
converted = 'not debug' | |
if converted != "": | |
return "if {}".format(converted) | |
else: | |
return None | |
def convert_fuzzy(fuzzy): | |
print(fuzzy) | |
items = fuzzy[fuzzy.index('(')+1:-1] | |
fzz = items.split(',') | |
maxDifference = fzz[-2] | |
totalPixels = fzz[-1] | |
if len(fzz) > 2: | |
and_ = '&&' | |
and_i = None | |
or_ = '||' | |
or_i = None | |
try: | |
and_i = fzz[0].index(and_) | |
except: | |
pass | |
try: | |
or_i = fzz[0].index(or_) | |
except: | |
pass | |
tokens = [] | |
final = [] | |
if and_i is not None: | |
tokens = fzz[0].split(and_) | |
elif or_i is not None: | |
tokens = fzz[0].split(or_) | |
else: | |
tokens = fzz | |
for tk in tokens: | |
not_ = False | |
if tk[0] == '!': | |
not_ = True | |
converted_os = convert_os(tk, not_) | |
if converted_os is not None: | |
final.append(converted_os) | |
else: | |
converted_os = convert_os(tk) | |
if converted_os is not None: | |
final.append(converted_os) | |
if and_i is not None: | |
final.insert(1, "and") | |
elif or_i is not None: | |
final.insert(1, "or") | |
else: | |
final = [] | |
nearly_done = " ".join(final) | |
done = "if {}".format(nearly_done[3:].replace("if ", "")) | |
return done, maxDifference, totalPixels | |
def write_config(filename, tokens): | |
config = get_ini(filename) | |
for tk in tokens: | |
if tk.startswith('fuzzy'): | |
conditions, maxDifference, totalPixels = convert_fuzzy(tk) | |
sections = config.sections() | |
section = filename.split('/')[-1][:-4] | |
if section not in sections: | |
config.add_section(section) | |
config.set(section, | |
conditions, | |
"maxDifference={};totalPixels={}".format(maxDifference, totalPixels)) | |
else: | |
break | |
if not os.path.exists(os.path.dirname(filename)): | |
try: | |
os.makedirs(os.path.dirname(filename)) | |
except OSError as exc: # Guard against race condition | |
if exc.errno != errno.EEXIST: | |
raise | |
with open(filename, 'w+') as configfile: | |
config.write(configfile) | |
def get_failures(): | |
"We need to read layout/reftests/w3c-css/failures.list" | |
failures = None | |
with open("layout/reftests/w3c-css/submitted/text-decor-3/reftest.list", "r") as f: | |
failures = f.read() | |
if failures is not None: | |
fails = failures.split("\n") | |
for line in fails: | |
tokens = line.split(' ') | |
if tokens[0].startswith('fuzzy'): | |
filename = find_reftest(tokens) | |
if filename is None: | |
continue | |
print CSS_IMPORT_PATH + filename[len(CSS_IMPORT_PATH)-1:-4].split('/')[0] | |
if not os.path.exists(CSS_IMPORT_PATH + filename[len(CSS_IMPORT_PATH)-1:-4].split('/')[0]): | |
continue | |
files_to_generate_for = None | |
if "?" in filename: | |
filename = filename.replace("?", "*") | |
files_to_generate_for = glob.glob( | |
filename[len(CSS_IMPORT_PATH)-1:-4].split('/')[-1]) | |
if files_to_generate_for is not None: | |
for fle in files_to_generate_for: | |
write_config(fle, tokens) | |
else: | |
write_config(filename, tokens) | |
if __name__ == "__main__": | |
get_failures() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment