Skip to content

Commit

Permalink
Bug 1559975 - convert dom/canvas/test to python3 syntax r=ahal
Browse files Browse the repository at this point in the history
Changes:
- change syntax of all python files under `dom/canvas/test` to python3 syntax
- remove semicolon line terminators from `dom/canvas/test/webgl-conf/checkout/deqp/genHTMLfromTest.py`

Differential Revision: https://phabricator.services.mozilla.com/D36388

--HG--
extra : moz-landing-system : lando
  • Loading branch information
Edwin Gao committed Jul 5, 2019
1 parent a1e7b69 commit c9ea675
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from xml.dom.minidom import parse

if sys.version < '2.6':
print 'Wrong Python Version !!!: Need >= 2.6'
print('Wrong Python Version !!!: Need >= 2.6')
sys.exit(1)

# each shader test generates up to 3 512x512 images.
Expand Down Expand Up @@ -101,7 +101,7 @@
def Log(msg):
global VERBOSE
if VERBOSE:
print msg
print(msg)


def TransposeMatrix(values, dim):
Expand All @@ -122,7 +122,7 @@ def GetValidTypeName(type_name):
for subst in SUBSTITUTIONS:
type_name = type_name.replace(subst[0], subst[1])
if not type_name in VALID_UNIFORM_TYPES:
print "unknown type name: ", type_name
print("unknown type name: ", type_name)
raise SyntaxError
return type_name

Expand Down Expand Up @@ -236,7 +236,7 @@ def CopyShader(filename, src, dst):
marker = "insert-copyright-here"
new_text = COMMENT_RE.sub(marker, text)
if new_text == text:
print "no matching license found:", s
print("no matching license found:", s)
raise RuntimeError
new_text = REMOVE_COPYRIGHT_RE.sub("", new_text)
new_text = new_text.replace(marker, LICENSE)
Expand All @@ -256,8 +256,8 @@ def CheckForUnknownTags(valid_tags, node, depth=1):
"""do a hacky check to make sure we're not missing something."""
for child in node.childNodes:
if child.localName and not IsOneOf(child.localName, valid_tags[0]):
print "unsupported tag:", child.localName
print "depth:", depth
print("unsupported tag:", child.localName)
print("depth:", depth)
raise SyntaxError
else:
if len(valid_tags) > 1:
Expand All @@ -282,7 +282,7 @@ def __init__(self, basepath):

def Print(self, msg):
if self.verbose:
print msg
print(msg)

def MakeOutPath(self, filename):
relpath = os.path.relpath(os.path.abspath(filename), os.path.dirname(os.path.abspath(self.basepath)))
Expand All @@ -307,7 +307,7 @@ def ReadTests(self, filename):
elif line.endswith(".test"):
tests_data.extend(self.ReadTest(fname))
else:
print "Error in %s:%d:%s" % (filename, count, line)
print("Error in %s:%d:%s" % (filename, count, line))
raise SyntaxError()
if len(tests_data):
global MAX_TESTS_PER_SET
Expand Down Expand Up @@ -457,7 +457,7 @@ def Process_compare(self, test, filename, outname):
uniform["transpose"] = (GetText(child.childNodes) == "true")
else:
if "type" in uniform:
print "utype was:", uniform["type"], " found ", child.localName
print("utype was:", uniform["type"], " found ", child.localName)
raise SyntaxError
type_name = GetValidTypeName(child.localName)
uniform["type"] = type_name
Expand Down
26 changes: 13 additions & 13 deletions dom/canvas/test/webgl-conf/checkout/deqp/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ def read_file(file_path):

def file_exists(file_path):
if not os.path.exists:
print "The file " + file_name + " doesn't exists"
print("The file " + file_name + " doesn't exists")
return False
return True

def build_deps(target, namespace):
cmdLine = 'python ../closure-library/closure/bin/build/closurebuilder.py --root=../closure-library --root=. --namespace=' + namespace
print cmdLine
print(cmdLine)
write_to_file(dep_filename(target), cmdLine, False)

def build_all_deps():
Expand All @@ -189,15 +189,15 @@ def build_target(target, namespace):
if len(dep) > 0:
cmdLine += ' --js ' + dep
cmdLine += ' --closure_entry_point=' + namespace
print cmdLine
print(cmdLine)
filename = compiled_filename(target)
write_to_file(filename, cmdLine, True)
compiled = read_file(filename)
result = re.search(r'(\d*)\s*error\(s\),\s*(\d*)\s*warning\(s\)', compiled)
errors = 0
warnings = 0
if result:
print target + ': ' + result.group(0)
print(target + ': ' + result.group(0))
errors = int(result.group(1))
warnings = int(result.group(2))
total_errors += errors
Expand All @@ -215,9 +215,9 @@ def format_target(target):
for dep in deps.split('\n'):
dep = dep.strip()
if len(dep) > 0 and not re.search('closure-library.*base\.js', dep):
print fixjsstyle + ' ' + dep
print(fixjsstyle + ' ' + dep)
subprocess.call(['python', fixjsstyle, dep])
print reformat + ' -f ' + dep
print(reformat + ' -f ' + dep)
subprocess.call(['python', reformat, '-f', dep])

def format_all_targets():
Expand All @@ -226,21 +226,21 @@ def format_all_targets():

def pass_or_fail():
if total_errors + total_warnings == 0:
print "Passed"
print("Passed")
elif len(results) > 1: #display the summary only when building more than one target
passed = [k for k, v in results.iteritems() if v[0] + v[1] == 0]
failed = dict((k, v) for k, v in results.iteritems() if v[0] + v[1] != 0)
print "\nBuild Summary:"
print("\nBuild Summary:")
# Print first the tests that passed
for target in passed:
print "{0:>30}\tPassed".format(target+":")
print("{0:>30}\tPassed".format(target+":"))

# Print tests that failed. Fixed-width to improve readability
for target in failed:
errors = failed[target][0]
warnings = failed[target][1]
print "{0:>30}\tErrors: {1:4}\tWarnings: {2:4}".format(target+":", errors, warnings)
print "Compilation failed: {} error(s), {} warning(s).".format(total_errors, total_warnings)
print("{0:>30}\tErrors: {1:4}\tWarnings: {2:4}".format(target+":", errors, warnings))
print("Compilation failed: {} error(s), {} warning(s).".format(total_errors, total_warnings))

def main(argv):
if len(argv) == 0:
Expand Down Expand Up @@ -270,9 +270,9 @@ def main(argv):
elif (argv[0] == 'depfile'):
buildDepsFile()
elif (argv[0] == 'list'):
print "List of available targets:"
print("List of available targets:")
for target in targets.keys():
print "\t{}".format(target)
print("\t{}".format(target))
else:
target = argv[0]
build_deps(target, targets[target])
Expand Down
40 changes: 20 additions & 20 deletions dom/canvas/test/webgl-conf/checkout/deqp/genHTMLfromTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,40 @@
# Generate an HTML file for each .test file in the current directory
#

TEST_LIST_FILE = '00_test_list.txt';
TEMPLATE = 'template.html';
TEST_LIST_FILE = '00_test_list.txt'
TEMPLATE = 'template.html'

def genHTML(template, test):
contents = re.sub('___TEST_NAME___', "'" + test + "'", template);
filename = test + '.html';
print "Generating " + filename;
contents = re.sub('___TEST_NAME___', "'" + test + "'", template)
filename = test + '.html'
print("Generating " + filename)
with open(test + '.html', 'w') as f:
f.write(contents);
return filename;
f.write(contents)
return filename


def process_test_files(template):
generated = [];
files = os.listdir(os.getcwd());
generated = []
files = os.listdir(os.getcwd())
for file in files:
found = re.search('(^[^.].*)\.test$', file);
found = re.search('(^[^.].*)\.test$', file)
if found:
generated.append(genHTML(template,found.group(1)));
return generated;
generated.append(genHTML(template,found.group(1)))
return generated

def readTemplate():
contents = None;
contents = None
with open(TEMPLATE, 'r') as f:
contents = f.read();
return contents;
contents = f.read()
return contents


template = readTemplate();
template = readTemplate()
if (template):
test_list = process_test_files(template);
print "Generating " + TEST_LIST_FILE;
test_list = process_test_files(template)
print("Generating " + TEST_LIST_FILE)
with open(TEST_LIST_FILE, 'w') as f:
for item in test_list:
f.write(item + '\n');
f.write(item + '\n')
else:
print "Couldn't find template file: " + TEMPLATE;
print("Couldn't find template file: ", TEMPLATE)
6 changes: 3 additions & 3 deletions dom/canvas/test/webgl-conf/checkout/py/lint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def check_regexp_line(path, f):

def output_errors(errors):
for error_type, error, line_number in errors:
print "%s: %s" % (error_type, error)
print("{}: {}".format(error_type, error))


def output_error_count(error_count):
Expand All @@ -167,9 +167,9 @@ def output_error_count(error_count):
by_type = " ".join("%s: %d" % item for item in error_count.iteritems())
count = sum(error_count.values())
if count == 1:
print "There was 1 error (%s)" % (by_type,)
print("There was 1 error ({})".format(by_type))
else:
print "There were %d errors (%s)" % (count, by_type)
print("There were {} errors ({})".format(count, by_type))


def main():
Expand Down
1 change: 0 additions & 1 deletion tools/lint/py3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ py3:
- client.py
- config
- dom/bindings
- dom/canvas/test
- dom/media/test
- gfx
- ipc/ipdl
Expand Down

0 comments on commit c9ea675

Please sign in to comment.