From 69c18bd6cc4faba1279976388f8d1c0d6547014d Mon Sep 17 00:00:00 2001 From: malayaleecoder Date: Wed, 29 Jun 2016 11:05:18 +0530 Subject: [PATCH] Bug 1282398 - Fix all flake8 errors in testing/talos/talos. r=jmaher --- testing/talos/talos/cmanager_linux.py | 4 ++-- testing/talos/talos/cmanager_mac.py | 12 +++++----- testing/talos/talos/cmdline.py | 14 ++++++------ testing/talos/talos/config.py | 4 ++-- testing/talos/talos/filter.py | 2 +- testing/talos/talos/mainthreadio.py | 14 ++++++------ testing/talos/talos/output.py | 2 +- testing/talos/talos/profiler/symbolication.py | 6 ++--- .../talos/profiler/symbolicationRequest.py | 6 ++--- testing/talos/talos/results.py | 22 +++++++++---------- testing/talos/talos/run_tests.py | 12 +++++----- testing/talos/talos/talosconfig.py | 2 +- testing/talos/talos/ttest.py | 2 +- testing/talos/talos/whitelist.py | 8 +++---- testing/talos/talos/xtalos/etlparser.py | 16 +++++++------- testing/talos/talos/xtalos/parse_xperf.py | 4 ++-- testing/talos/talos/xtalos/start_xperf.py | 4 ++-- testing/talos/talos/xtalos/xtalos.py | 2 +- 18 files changed, 68 insertions(+), 68 deletions(-) diff --git a/testing/talos/talos/cmanager_linux.py b/testing/talos/talos/cmanager_linux.py index b2d754a967fd..54de636ddcca 100644 --- a/testing/talos/talos/cmanager_linux.py +++ b/testing/talos/talos/cmanager_linux.py @@ -133,7 +133,7 @@ def GetXRes(pids): data = float(data) XRes += data except ValueError: - print "Invalid data, not a float" + print("Invalid data, not a float") raise else: raise Exception("Could not find PID=%s in xrestop output" % pid) @@ -178,4 +178,4 @@ class LinuxCounterManager(CounterManager): return [self.process.pid] + [child.pid for child in self.process.children()] except: - print "WARNING: problem updating child PID's" + print("WARNING: problem updating child PID's") diff --git a/testing/talos/talos/cmanager_mac.py b/testing/talos/talos/cmanager_mac.py index 2ee656543123..fe57778a31e0 100644 --- a/testing/talos/talos/cmanager_mac.py +++ b/testing/talos/talos/cmanager_mac.py @@ -20,7 +20,7 @@ def GetProcessData(pid): handle.wait() data = handle.stdout.readlines() except: - print "Unexpected error executing '%s': %s", (command, sys.exc_info()) + print("Unexpected error executing '%s': %s", (command, sys.exc_info())) raise # First line is header output should look like: @@ -75,12 +75,12 @@ class MacCounterManager(CounterManager): def getCounterValue(self, counterName): """Returns the last value of the counter 'counterName'""" if counterName not in self.registeredCounters: - print ("Warning: attempting to collect counter %s and it is not" - " registered" % counterName) + print("Warning: attempting to collect counter %s and it is not" + " registered" % counterName) return try: return self.registeredCounters[counterName][0](self.pid) - except Exception, e: - print ("Error in collecting counter: %s, pid: %s, exception: %s" - % (counterName, self.pid, e)) + except Exception as e: + print("Error in collecting counter: %s, pid: %s, exception: %s" + % (counterName, self.pid, e)) diff --git a/testing/talos/talos/cmdline.py b/testing/talos/talos/cmdline.py index a4f1c7ad363e..e06e1adb1ba4 100644 --- a/testing/talos/talos/cmdline.py +++ b/testing/talos/talos/cmdline.py @@ -22,17 +22,17 @@ class _StopAction(argparse.Action): class _ListTests(_StopAction): def __call__(self, parser, namespace, values, option_string=None): from talos import test - print 'Available tests:' - print '================\n' + print('Available tests:') + print('================\n') test_class_names = [ (test_class.name(), test_class.description()) for test_class in test.test_dict().itervalues() ] test_class_names.sort() for name, description in test_class_names: - print name - print '-'*len(name) - print description + print(name) + print('-'*len(name)) + print(description) print # Appends a single blank line to the end parser.exit() @@ -40,12 +40,12 @@ class _ListTests(_StopAction): class _ListSuite(_StopAction): def __call__(self, parser, namespace, values, option_string=None): from talos.config import suites_conf - print 'Available suites:' + print('Available suites:') conf = suites_conf() max_suite_name = max([len(s) for s in conf]) pattern = " %%-%ds (%%s)" % max_suite_name for name in conf: - print pattern % (name, ':'.join(conf[name]['tests'])) + print(pattern % (name, ':'.join(conf[name]['tests']))) print parser.exit() diff --git a/testing/talos/talos/config.py b/testing/talos/talos/config.py index e5242b6b6aee..a5bd7d105301 100644 --- a/testing/talos/talos/config.py +++ b/testing/talos/talos/config.py @@ -467,6 +467,6 @@ def get_configs(argv=None): if __name__ == '__main__': cfgs = get_configs() - print cfgs[0] + print(cfgs[0]) print - print cfgs[1] + print(cfgs[1]) diff --git a/testing/talos/talos/filter.py b/testing/talos/talos/filter.py index 7a50b2b05653..33aa8fe5c5db 100644 --- a/testing/talos/talos/filter.py +++ b/testing/talos/talos/filter.py @@ -106,7 +106,7 @@ def dromaeo(series): @define_filter def dromaeo_chunks(series, size): - for i in xrange(0, len(series), size): + for i in range(0, len(series), size): yield series[i:i+size] diff --git a/testing/talos/talos/mainthreadio.py b/testing/talos/talos/mainthreadio.py index 2896b643ffbc..2f1029e6df1c 100644 --- a/testing/talos/talos/mainthreadio.py +++ b/testing/talos/talos/mainthreadio.py @@ -87,7 +87,7 @@ def parse(logfilename, data): stage = stage + 1 return True except IOError as e: - print "%s: %s" % (e.filename, e.strerror) + print("%s: %s" % (e.filename, e.strerror)) return False @@ -108,21 +108,21 @@ def write_output(outfilename, data): outfile.write("]\n") return True except IOError as e: - print "%s: %s" % (e.filename, e.strerror) + print("%s: %s" % (e.filename, e.strerror)) return False def main(argv): if len(argv) < 4: - print ("Usage: %s " - % argv[0]) + print("Usage: %s " + % argv[0]) return 1 if not os.path.exists(argv[3]): - print "XRE Path \"%s\" does not exist" % argv[3] + print("XRE Path \"%s\" does not exist" % argv[3]) return 1 data = {} if not parse(argv[1], data): - print "Log parsing failed" + print("Log parsing failed") return 1 wl = whitelist.Whitelist(test_name='mainthreadio', @@ -130,7 +130,7 @@ def main(argv): path_substitutions=PATH_SUBSTITUTIONS, name_substitutions=NAME_SUBSTITUTIONS) if not wl.load(WHITELIST_FILENAME): - print "Failed to load whitelist" + print("Failed to load whitelist") return 1 wl.filter(data, TUPLE_FILENAME_INDEX) diff --git a/testing/talos/talos/output.py b/testing/talos/talos/output.py index 7bc1d6afbf6d..003e98f0216c 100755 --- a/testing/talos/talos/output.py +++ b/testing/talos/talos/output.py @@ -197,7 +197,7 @@ class Output(object): if 'spsProfile' not in self.results.extra_options: LOG.info("PERFHERDER_DATA: %s" % json.dumps(results)) if results_scheme in ('file'): - json.dump(results, file(results_path, 'w'), indent=2, + json.dump(results, open(results_path, 'w'), indent=2, sort_keys=True) def post(self, results, server, path, scheme, tbpl_output): diff --git a/testing/talos/talos/profiler/symbolication.py b/testing/talos/talos/profiler/symbolication.py index 37453408c2e7..41894bc7362b 100755 --- a/testing/talos/talos/profiler/symbolication.py +++ b/testing/talos/talos/profiler/symbolication.py @@ -266,7 +266,7 @@ class ProfileSymbolicator: delta_time = profile_start_time - self.main_start_time for i, thread in enumerate(profile_json["threads"]): - if isinstance(thread, basestring): + if isinstance(thread, str): thread_json = json.loads(thread) self.symbolicate_profile(thread_json) profile_json["threads"][i] = json.dumps(thread_json) @@ -297,7 +297,7 @@ class ProfileSymbolicator: def _find_addresses_v3(self, profile_json): addresses = set() for thread in profile_json["threads"]: - if isinstance(thread, basestring): + if isinstance(thread, str): continue for s in thread["stringTable"]: if s[0:2] == "0x": @@ -306,7 +306,7 @@ class ProfileSymbolicator: def _substitute_symbols_v3(self, profile_json, symbolication_table): for thread in profile_json["threads"]: - if isinstance(thread, basestring): + if isinstance(thread, str): continue for i, s in enumerate(thread["stringTable"]): thread["stringTable"][i] = symbolication_table.get(s, s) diff --git a/testing/talos/talos/profiler/symbolicationRequest.py b/testing/talos/talos/profiler/symbolicationRequest.py index d0bbd5439ff7..5a3f1ee22c3b 100755 --- a/testing/talos/talos/profiler/symbolicationRequest.py +++ b/testing/talos/talos/profiler/symbolicationRequest.py @@ -25,11 +25,11 @@ class ModuleV3: def getModuleV3(libName, breakpadId): - if not isinstance(libName, basestring) or not gLibNameRE.match(libName): + if not isinstance(libName, str) or not gLibNameRE.match(libName): LogTrace("Bad library name: " + str(libName)) return None - if not isinstance(breakpadId, basestring): + if not isinstance(breakpadId, str): LogTrace("Bad breakpad id: " + str(breakpadId)) return None @@ -72,7 +72,7 @@ class SymbolicationRequest: return if "forwarded" in rawRequests: - if not isinstance(rawRequests["forwarded"], (int, long)): + if not isinstance(rawRequests["forwarded"], (int, int)): LogTrace("Invalid 'forwards' field: %s" % rawRequests["forwarded"]) return diff --git a/testing/talos/talos/results.py b/testing/talos/talos/results.py index f830a733cb67..de81ac4902b7 100755 --- a/testing/talos/talos/results.py +++ b/testing/talos/talos/results.py @@ -44,7 +44,7 @@ class TalosResults(object): for url in urls: _output.output(results, url, tbpl_output) - except utils.TalosError, e: + except utils.TalosError as e: # print to results.out try: _output = output.GraphserverOutput(self) @@ -55,11 +55,11 @@ class TalosResults(object): ) except: pass - print '\nFAIL: %s' % str(e).replace('\n', '\nRETURN:') + print('\nFAIL: %s' % str(e).replace('\n', '\nRETURN:')) raise e if tbpl_output: - print "TinderboxPrint: TalosResult: %s" % json.dumps(tbpl_output) + print("TinderboxPrint: TalosResult: %s" % json.dumps(tbpl_output)) class TestResults(object): @@ -367,7 +367,7 @@ class BrowserLogResults(object): try: parts, last_token = utils.tokenize(self.results_raw, start_token, end_token) - except AssertionError, e: + except AssertionError as e: self.error(str(e)) if not parts: return None, -1 # no match @@ -426,11 +426,11 @@ class BrowserLogResults(object): filename = 'etl_output_thread_stats.csv' if not os.path.exists(filename): - print ("Warning: we are looking for xperf results file %s, and" - " didn't find it" % filename) + print("Warning: we are looking for xperf results file %s, and" + " didn't find it" % filename) return - contents = file(filename).read() + contents = open(filename).read() lines = contents.splitlines() reader = csv.reader(lines) header = None @@ -458,11 +458,11 @@ class BrowserLogResults(object): if (set(mainthread_counters).intersection(counter_results.keys())): filename = 'etl_output.csv' if not os.path.exists(filename): - print ("Warning: we are looking for xperf results file" - " %s, and didn't find it" % filename) + print("Warning: we are looking for xperf results file" + " %s, and didn't find it" % filename) return - contents = file(filename).read() + contents = open(filename).read() lines = contents.splitlines() reader = csv.reader(lines) header = None @@ -506,7 +506,7 @@ class BrowserLogResults(object): os.path.abspath(os.path.realpath(os.path.dirname(__file__))) filename = os.path.join(SCRIPT_DIR, 'mainthread_io.json') try: - contents = file(filename).read() + contents = open(filename).read() counter_results.setdefault('mainthreadio', []).append(contents) self.using_xperf = True except: diff --git a/testing/talos/talos/run_tests.py b/testing/talos/talos/run_tests.py index e98686340e56..1e5c3ac508ba 100755 --- a/testing/talos/talos/run_tests.py +++ b/testing/talos/talos/run_tests.py @@ -150,7 +150,7 @@ def run_tests(config, browser_config): browser_config['sourcestamp'] = version_info['application_changeset'] except KeyError: if not browser_config['develop']: - print "unable to find changeset or repository: %s" % version_info + print("unable to find changeset or repository: %s" % version_info) sys.exit() else: browser_config['repository'] = 'develop' @@ -207,14 +207,14 @@ def run_tests(config, browser_config): LOG.error("Detected a regression for %s" % testname) # by returning 1, we report an orange to buildbot # http://docs.buildbot.net/latest/developer/results.html - LOG.test_end(testname, status='FAIL', message=unicode(exc), + LOG.test_end(testname, status='FAIL', message=str(exc), stack=traceback.format_exc()) return 1 except Exception as exc: # NOTE: if we get into this condition, talos has an internal # problem and cannot continue # this will prevent future tests from running - LOG.test_end(testname, status='ERROR', message=unicode(exc), + LOG.test_end(testname, status='ERROR', message=str(exc), stack=traceback.format_exc()) # indicate a failure to buildbot, turn the job red return 2 @@ -228,8 +228,8 @@ def run_tests(config, browser_config): if results_urls: talos_results.output(results_urls) if browser_config['develop'] or config['sps_profile']: - print ("Thanks for running Talos locally. Results are in %s" - % (results_urls['output_urls'])) + print("Thanks for running Talos locally. Results are in %s" + % (results_urls['output_urls'])) # we will stop running tests on a failed test, or we will return 0 for # green @@ -239,7 +239,7 @@ def run_tests(config, browser_config): def main(args=sys.argv[1:]): try: config, browser_config = get_configs() - except ConfigurationError, exc: + except ConfigurationError as exc: sys.exit("ERROR: %s" % exc) sys.exit(run_tests(config, browser_config)) diff --git a/testing/talos/talos/talosconfig.py b/testing/talos/talos/talosconfig.py index b7c887e8c85f..2645a56bf343 100644 --- a/testing/talos/talos/talosconfig.py +++ b/testing/talos/talos/talosconfig.py @@ -25,7 +25,7 @@ def generateTalosConfig(command_line, browser_config, test_config, pid=None): ('xperf_user_providers' in test_config) and ('xperf_stackwalk' in test_config)): # noqa - print "extending with xperf!" + print("extending with xperf!") browser_config['xperf_providers'] = test_config['xperf_providers'] browser_config['xperf_user_providers'] = \ test_config['xperf_user_providers'] diff --git a/testing/talos/talos/ttest.py b/testing/talos/talos/ttest.py index b1e558cca20d..4a0fcd1351c7 100644 --- a/testing/talos/talos/ttest.py +++ b/testing/talos/talos/ttest.py @@ -195,7 +195,7 @@ class TTest(object): if line.strip() == "": continue - print line + print(line) mainthread_error_count += 1 mozfile.remove(rawlog) diff --git a/testing/talos/talos/whitelist.py b/testing/talos/talos/whitelist.py index 0782609ac9ba..6b01e10fc0db 100644 --- a/testing/talos/talos/whitelist.py +++ b/testing/talos/talos/whitelist.py @@ -38,7 +38,7 @@ class Whitelist: self.listmap[whitelist_name.lower()] = temp[whitelist_name] except IOError as e: - print "%s: %s" % (e.filename, e.strerror) + print("%s: %s" % (e.filename, e.strerror)) return False return True @@ -136,8 +136,8 @@ class Whitelist: def print_errors(self, error_strs): for error_msg in error_strs: - print "TEST-UNEXPECTED-FAIL | %s | %s" % (self.test_name, - error_msg) + print("TEST-UNEXPECTED-FAIL | %s | %s" % (self.test_name, + error_msg)) # Note that we don't store dependent libs in listmap. This makes # save_baseline cleaner. Since a baseline whitelist should not include @@ -154,5 +154,5 @@ class Whitelist: {'ignore': True} for lib in libs} return True except IOError as e: - print "%s: %s" % (e.filename, e.strerror) + print("%s: %s" % (e.filename, e.strerror)) return False diff --git a/testing/talos/talos/xtalos/etlparser.py b/testing/talos/talos/xtalos/etlparser.py index c9f710139083..d52c112e18b5 100644 --- a/testing/talos/talos/xtalos/etlparser.py +++ b/testing/talos/talos/xtalos/etlparser.py @@ -79,7 +79,7 @@ def getIndex(eventType, colName): def readFile(filename): - print "etlparser: in readfile: %s" % filename + print("etlparser: in readfile: %s" % filename) data = csv.reader(open(filename, 'rb'), delimiter=',', quotechar='"', skipinitialspace=True) data = filterOutHeader(data) @@ -150,7 +150,7 @@ def etl2csv(xperf_path, etl_filename, debug=False): '%s.kernel' % etl_filename, etl_filename] if debug: - print "executing '%s'" % subprocess.list2cmdline(xperf_cmd) + print("executing '%s'" % subprocess.list2cmdline(xperf_cmd)) subprocess.call(xperf_cmd) csv_filename = '%s.csv' % etl_filename @@ -158,7 +158,7 @@ def etl2csv(xperf_path, etl_filename, debug=False): '-i', etl_filename, '-o', csv_filename] if debug: - print "executing '%s'" % subprocess.list2cmdline(xperf_cmd) + print("executing '%s'" % subprocess.list2cmdline(xperf_cmd)) subprocess.call(xperf_cmd) return csv_filename @@ -226,9 +226,9 @@ def loadWhitelist(filename): if not filename: return if not os.path.exists(filename): - print "Warning: xperf whitelist %s was not found" % filename + print("Warning: xperf whitelist %s was not found" % filename) return - lines = file(filename).readlines() + lines = open(filename).readlines() # Expand paths lines = [os.path.expandvars(elem.strip()) for elem in lines] files = set() @@ -276,7 +276,7 @@ def etlparser(xperf_path, etl_filename, processID, approot=None, io = {} stage = 0 - print "reading etl filename: %s" % etl_filename + print("reading etl filename: %s" % etl_filename) csvname = etl2csv(xperf_path, etl_filename, debug=debug) for row in readFile(csvname): event = row[EVENTNAME_INDEX] @@ -304,7 +304,7 @@ def etlparser(xperf_path, etl_filename, processID, approot=None, with open(fname, "w") as f: f.write(output) else: - print output + print(output) whitelist = loadWhitelist(whitelist_file) @@ -447,7 +447,7 @@ def etlparser(xperf_path, etl_filename, processID, approot=None, for error in errors: # NOTE: the ' :' is intentional, without the space before the :, # some parser will translate this - print "TEST-UNEXPECTED-FAIL : xperf: %s" % error + print("TEST-UNEXPECTED-FAIL : xperf: %s" % error) # We detect if browser_failures.txt exists to exit and turn the job # orange diff --git a/testing/talos/talos/xtalos/parse_xperf.py b/testing/talos/talos/xtalos/parse_xperf.py index 996c348b563e..c53425fa33e9 100644 --- a/testing/talos/talos/xtalos/parse_xperf.py +++ b/testing/talos/talos/xtalos/parse_xperf.py @@ -14,7 +14,7 @@ import etlparser def stop(xperf_path, debug=False): xperf_cmd = [xperf_path, '-stop', '-stop', 'talos_ses'] if debug: - print "executing '%s'" % subprocess.list2cmdline(xperf_cmd) + print("executing '%s'" % subprocess.list2cmdline(xperf_cmd)) subprocess.call(xperf_cmd) @@ -67,7 +67,7 @@ def main(args=sys.argv[1:]): stop_from_config(config_file=args.configFile, debug=args.debug_level >= xtalos.DEBUG_INFO, **args.__dict__) - except xtalos.XTalosError, e: + except xtalos.XTalosError as e: parser.error(str(e)) if __name__ == "__main__": diff --git a/testing/talos/talos/xtalos/start_xperf.py b/testing/talos/talos/xtalos/start_xperf.py index 5925871f1082..06585b47979e 100644 --- a/testing/talos/talos/xtalos/start_xperf.py +++ b/testing/talos/talos/xtalos/start_xperf.py @@ -26,7 +26,7 @@ def start(xperf_path, xperf_providers, xperf_stackwalk, xperf_user_providers, '-f', '%s.user' % etl_filename ] if debug: - print "executing '%s'" % subprocess.list2cmdline(xperf_cmd) + print("executing '%s'" % subprocess.list2cmdline(xperf_cmd)) subprocess.call(xperf_cmd) @@ -76,7 +76,7 @@ def main(args=sys.argv[1:]): start_from_config(config_file=args.configFile, debug=args.debug_level >= xtalos.DEBUG_INFO, **args.__dict__) - except xtalos.XTalosError, e: + except xtalos.XTalosError as e: parser.error(str(e)) diff --git a/testing/talos/talos/xtalos/xtalos.py b/testing/talos/talos/xtalos/xtalos.py index 4855f89b3b95..df9a9eecc392 100644 --- a/testing/talos/talos/xtalos/xtalos.py +++ b/testing/talos/talos/xtalos/xtalos.py @@ -120,7 +120,7 @@ class XtalosOptions(argparse.ArgumentParser): # ensure xperf path exists options.xperf_path = os.path.abspath(options.xperf_path) if not os.path.exists(options.xperf_path): - print "ERROR: xperf_path '%s' does not exist" % options.xperf_path + print("ERROR: xperf_path '%s' does not exist" % options.xperf_path) return None return options