Bug 1506611 - Fixed linter errors in testing/tps. r=ahal
authorterrameijar <terrameijar@gmail.com>
Tue, 15 Jan 2019 15:58:52 +0000
changeset 453945 ad473f67f76950921b049ffe896dd25a0e987de6
parent 453944 63debb1d02d3ca285def538c88c1e47295923613
child 453946 18bdd2ab1081221fd7b0e115e792645ff036fe95
push id35380
push userdluca@mozilla.com
push dateTue, 15 Jan 2019 22:13:12 +0000
treeherdermozilla-central@a51d26029042 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahal
bugs1506611
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1506611 - Fixed linter errors in testing/tps. r=ahal Before this change, testing/tps had 19 linter errors. These have been resolved. Differential Revision: https://phabricator.services.mozilla.com/D15846
testing/tps/create_venv.py
testing/tps/setup.py
testing/tps/tps/__init__.py
testing/tps/tps/cli.py
testing/tps/tps/firefoxrunner.py
testing/tps/tps/phase.py
testing/tps/tps/testrunner.py
tools/lint/flake8.yml
--- a/testing/tps/create_venv.py
+++ b/testing/tps/create_venv.py
@@ -144,17 +144,17 @@ def main():
                       dest='username',
                       metavar='FX_ACCOUNT_USERNAME',
                       default=None,
                       help='The Firefox Account username.')
 
     (options, args) = parser.parse_args(args=None, values=None)
 
     if len(args) != 1:
-         parser.error('Path to the environment has to be specified')
+        parser.error('Path to the environment has to be specified')
     target = args[0]
     assert(target)
 
     setup_virtualenv(target, python_bin=options.python)
 
     # Activate tps environment
     tps_env = os.path.join(target, activate_env)
     execfile(tps_env, dict(__file__=tps_env))
@@ -173,27 +173,28 @@ def main():
     else:
         testdir = os.path.join(here, 'tests')
         extdir = os.path.join(here, 'extensions')
 
     if not options.keep_config:
         update_configfile(os.path.join(here, 'config', 'config.json.in'),
                           os.path.join(target, 'config.json'),
                           replacements={
-                          '__TESTDIR__': testdir.replace('\\','/'),
-                          '__EXTENSIONDIR__': extdir.replace('\\','/'),
+                          '__TESTDIR__': testdir.replace('\\', '/'),
+                          '__EXTENSIONDIR__': extdir.replace('\\', '/'),
                           '__FX_ACCOUNT_USERNAME__': options.username,
                           '__FX_ACCOUNT_PASSWORD__': options.password,
                           '__SYNC_ACCOUNT_USERNAME__': options.sync_username,
                           '__SYNC_ACCOUNT_PASSWORD__': options.sync_password,
                           '__SYNC_ACCOUNT_PASSPHRASE__': options.sync_passphrase})
 
         if not (options.username and options.password):
             print '\nFirefox Account credentials not specified.'
         if not (options.sync_username and options.sync_password and options.passphrase):
             print '\nFirefox Sync account credentials not specified.'
 
     # Print the user instructions
     print usage_message.format(TARGET=target,
                                BIN_NAME=bin_name)
 
+
 if __name__ == "__main__":
     main()
--- a/testing/tps/setup.py
+++ b/testing/tps/setup.py
@@ -12,30 +12,30 @@ deps = ['httplib2 == 0.9.2',
         'mozfile >= 1.2',
         'mozhttpd == 0.7',
         'mozinfo >= 0.10',
         'mozinstall == 1.16',
         'mozprocess == 0.26',
         'mozprofile ~= 2.1',
         'mozrunner ~= 7.2',
         'mozversion == 1.5',
-       ]
+        ]
 
 # we only support python 2.6+ right now
 assert sys.version_info[0] == 2
 assert sys.version_info[1] >= 6
 
 setup(name='tps',
       version=version,
       description='run automated multi-profile sync tests',
       long_description="""\
 """,
       classifiers=['Programming Language :: Python :: 2.7',
-		   'Programming Language :: Python :: 2 :: Only',
-		  ], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+                   'Programming Language :: Python :: 2 :: Only',
+                   ],  # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
       keywords='',
       author='Mozilla Automation and Tools team',
       author_email='tools@lists.mozilla.org',
       url='https://developer.mozilla.org/en-US/docs/TPS',
       license='MPL 2.0',
       packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
       include_package_data=True,
       zip_safe=False,
--- a/testing/tps/tps/__init__.py
+++ b/testing/tps/tps/__init__.py
@@ -1,6 +1,7 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
+# flake8: noqa
 from . firefoxrunner import TPSFirefoxRunner
 from . testrunner import TPSTestRunner
--- a/testing/tps/tps/cli.py
+++ b/testing/tps/tps/cli.py
@@ -29,21 +29,21 @@ def main():
                       default=None,
                       help='path to the config file to use default: %default]')
     parser.add_option('--debug',
                       action='store_true',
                       dest='debug',
                       default=False,
                       help='run in debug mode')
     parser.add_option('--ignore-unused-engines',
-                       default=False,
-                       action='store_true',
-                       dest='ignore_unused_engines',
-                       help='If defined, do not load unused engines in individual tests.'
-                            ' Has no effect for pulse monitor.')
+                      default=False,
+                      action='store_true',
+                      dest='ignore_unused_engines',
+                      help='If defined, do not load unused engines in individual tests.'
+                      ' Has no effect for pulse monitor.')
     parser.add_option('--logfile',
                       action='store',
                       type='string',
                       dest='logfile',
                       default='tps.log',
                       help='path to the log file [default: %default]')
     parser.add_option('--mobile',
                       action='store_true',
@@ -117,16 +117,17 @@ def main():
                         debug=options.debug,
                         ignore_unused_engines=options.ignore_unused_engines,
                         logfile=options.logfile,
                         mobile=options.mobile,
                         resultfile=options.resultfile,
                         rlock=rlock,
                         testfile=testfile,
                         stop_on_error=options.stop_on_error,
-                      )
+                        )
     TPS.run_tests()
 
     if TPS.numfailed > 0 or TPS.numpassed == 0:
         sys.exit(1)
 
+
 if __name__ == '__main__':
     main()
--- a/testing/tps/tps/firefoxrunner.py
+++ b/testing/tps/tps/firefoxrunner.py
@@ -1,14 +1,13 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 
-import copy
 import httplib2
 import os
 
 import mozfile
 import mozinstall
 from mozprofile import Profile
 from mozrunner import FirefoxRunner
 
@@ -29,17 +28,17 @@ class TPSFirefoxRunner(object):
 
     def __del__(self):
         if self.installdir:
             mozfile.remove(self.installdir, True)
 
     def download_url(self, url, dest=None):
         h = httplib2.Http()
         resp, content = h.request(url, 'GET')
-        if dest == None:
+        if dest is None:
             dest = os.path.basename(url)
 
         local = open(dest, 'wb')
         local.write(content)
         local.close()
         return dest
 
     def download_build(self, installdir='downloadedbuild', appname='firefox'):
--- a/testing/tps/tps/phase.py
+++ b/testing/tps/tps/phase.py
@@ -1,25 +1,26 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import re
 import os.path
 
+
 class TPSTestPhase(object):
 
     lineRe = re.compile(
         r'^(.*?)test phase (?P<matchphase>[^\s]+): (?P<matchstatus>.*)$')
 
     def __init__(self, phase, profile, testname, testpath, logfile, env,
                  firefoxRunner, logfn, ignore_unused_engines=False):
         self.phase = phase
         self.profile = profile
-        self.testname = str(testname) # this might be passed in as unicode
+        self.testname = str(testname)  # this might be passed in as unicode
         self.testpath = testpath
         self.logfile = logfile
         self.env = env
         self.firefoxRunner = firefoxRunner
         self.log = logfn
         self.ignore_unused_engines = ignore_unused_engines
         self._status = None
         self.errline = ''
@@ -33,17 +34,17 @@ class TPSTestPhase(object):
 
         prefs = {
             "testing.tps.testFile": os.path.abspath(self.testpath),
             "testing.tps.testPhase": self.phase,
             "testing.tps.logFile": self.logfile,
             "testing.tps.ignoreUnusedEngines": self.ignore_unused_engines
         }
 
-        self.profile.set_preferences(prefs);
+        self.profile.set_preferences(prefs)
 
         self.log('\nLaunching Firefox for phase %s with prefs %s\n' %
                  (self.phase, str(prefs)))
 
         self.firefoxRunner.run(env=self.env,
                                args=[],
                                profile=self.profile)
 
--- a/testing/tps/tps/testrunner.py
+++ b/testing/tps/tps/testrunner.py
@@ -1,16 +1,14 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import json
 import os
-import platform
-import random
 import re
 import tempfile
 import time
 import traceback
 
 from mozhttpd import MozHttpd
 import mozinfo
 from mozprofile import Profile
@@ -183,68 +181,71 @@ class TPSTestRunner(object):
         f.close()
 
     def _zip_add_file(self, zip, file, rootDir):
         zip.write(os.path.join(rootDir, file), file)
 
     def _zip_add_dir(self, zip, dir, rootDir):
         try:
             zip.write(os.path.join(rootDir, dir), dir)
-        except:
+        except Exception:
             # on some OS's, adding directory entries doesn't seem to work
             pass
         for root, dirs, files in os.walk(os.path.join(rootDir, dir)):
             for f in files:
                 zip.write(os.path.join(root, f), os.path.join(dir, f))
 
     def handle_phase_failure(self, profiles):
         for profile in profiles:
-            self.log('\nDumping sync log for profile %s\n' %  profiles[profile].profile)
-            for root, dirs, files in os.walk(os.path.join(profiles[profile].profile, 'weave', 'logs')):
+            self.log('\nDumping sync log for profile %s\n'
+                     % profiles[profile].profile)
+            for root, dirs, files in os.walk(
+                    os.path.join(profiles[profile].profile, 'weave', 'logs')):
                 for f in files:
-                    weavelog = os.path.join(profiles[profile].profile, 'weave', 'logs', f)
+                    weavelog = os.path.join(
+                        profiles[profile].profile, 'weave', 'logs', f)
                     if os.access(weavelog, os.F_OK):
                         with open(weavelog, 'r') as fh:
                             for line in fh:
                                 possible_time = line[0:13]
                                 if len(possible_time) == 13 and possible_time.isdigit():
                                     time_ms = int(possible_time)
                                     formatted = time.strftime('%Y-%m-%d %H:%M:%S',
-                                            time.localtime(time_ms / 1000))
+                                                              time.localtime(time_ms / 1000))
                                     self.log('%s.%03d %s' % (
-                                        formatted, time_ms % 1000, line[14:] ))
+                                        formatted, time_ms % 1000, line[14:]))
                                 else:
                                     self.log(line)
 
     def run_single_test(self, testdir, testname):
         testpath = os.path.join(testdir, testname)
         self.log("Running test %s\n" % testname, True)
 
         # Read and parse the test file, merge it with the contents of the config
         # file, and write the combined output to a temporary file.
         f = open(testpath, 'r')
         testcontent = f.read()
         f.close()
         try:
             test = json.loads(testcontent)
-        except:
+        except Exception:
             test = json.loads(testcontent[testcontent.find('{'):testcontent.find('}') + 1])
 
         self.preferences['tps.seconds_since_epoch'] = int(time.time())
 
         # generate the profiles defined in the test, and a list of test phases
         profiles = {}
         phaselist = []
         for phase in test:
             profilename = test[phase]
 
             # create the profile if necessary
-            if not profilename in profiles:
-                profiles[profilename] = Profile(preferences = self.preferences.copy(),
-                                                addons = self.extensions)
+            if profilename not in profiles:
+                profiles[profilename] = Profile(preferences=self.preferences.copy(),
+                                                addons=self.extensions)
 
             # create the test phase
             phaselist.append(TPSTestPhase(
                 phase,
                 profiles[profilename],
                 testname,
                 testpath,
                 self.logfile,
@@ -257,17 +258,17 @@ class TPSTestRunner(object):
         phaselist = sorted(phaselist, key=lambda phase: phase.phase)
 
         # run each phase in sequence, aborting at the first failure
         failed = False
         for phase in phaselist:
             phase.run()
             if phase.status != 'PASS':
                 failed = True
-                break;
+                break
 
         for profilename in profiles:
             print "### Cleanup Profile ", profilename
             cleanup_phase = TPSTestPhase(
                 'cleanup-' + profilename,
                 profiles[profilename], testname,
                 testpath,
                 self.logfile,
@@ -298,60 +299,61 @@ class TPSTestRunner(object):
         else:
             # we only care about the log data for this specific test
             logdata = logdata[logdata.find('Running test %s' % (str(testname))):]
 
         result = {
           'PASS': lambda x: ('TEST-PASS', ''),
           'FAIL': lambda x: ('TEST-UNEXPECTED-FAIL', x.rstrip()),
           'unknown': lambda x: ('TEST-UNEXPECTED-FAIL', 'test did not complete')
-        } [phase.status](phase.errline)
-        logstr = "\n%s | %s%s\n" % (result[0], testname, (' | %s' % result[1] if result[1] else ''))
+        }[phase.status](phase.errline)
+        logstr = "\n%s | %s%s\n" % (result[0], testname, (' | %s' %
+                                                          result[1] if result[1] else ''))
 
         try:
             repoinfo = mozversion.get_version(self.binary)
-        except:
+        except Exception:
             repoinfo = {}
         apprepo = repoinfo.get('application_repository', '')
         appchangeset = repoinfo.get('application_changeset', '')
 
         # save logdata to a temporary file for posting to the db
         tmplogfile = None
         if logdata:
             tmplogfile = TempFile(prefix='tps_log_')
             tmplogfile.write(logdata)
             tmplogfile.close()
             self.errorlogs[testname] = tmplogfile
 
-        resultdata = ({ 'productversion': { 'version': firefox_version,
-                                            'buildid': firefox_buildid,
-                                            'builddate': firefox_buildid[0:8],
-                                            'product': 'Firefox',
-                                            'repository': apprepo,
-                                            'changeset': appchangeset,
+        resultdata = ({'productversion': {'version': firefox_version,
+                                          'buildid': firefox_buildid,
+                                          'builddate': firefox_buildid[0:8],
+                                          'product': 'Firefox',
+                                          'repository': apprepo,
+                                          'changeset': appchangeset,
                                           },
-                        'addonversion': { 'version': sync_version,
-                                          'product': 'Firefox Sync' },
-                        'name': testname,
-                        'message': result[1],
-                        'state': result[0],
-                        'logdata': logdata
-                      })
+                       'addonversion': {'version': sync_version,
+                                        'product': 'Firefox Sync'},
+                       'name': testname,
+                       'message': result[1],
+                       'state': result[0],
+                       'logdata': logdata
+                       })
 
         self.log(logstr, True)
         for phase in phaselist:
             print "\t%s: %s" % (phase.phase, phase.status)
 
         return resultdata
 
     def update_preferences(self):
         self.preferences = self.default_preferences.copy()
 
         if self.mobile:
-            self.preferences.update({'services.sync.client.type' : 'mobile'})
+            self.preferences.update({'services.sync.client.type': 'mobile'})
 
         # If we are using legacy Sync, then set a dummy username to force the
         # correct authentication type. Without this pref set to a value
         # without an '@' character, Sync will initialize for FxA.
         if self.config.get('auth_type', 'fx_account') != "fx_account":
             self.preferences.update({'services.sync.username': "dummy"})
 
         if self.debug:
@@ -383,40 +385,40 @@ class TPSTestRunner(object):
             # Create the Firefox runner, which will download and install the
             # build, as needed.
             if not self.firefoxRunner:
                 self.firefoxRunner = TPSFirefoxRunner(self.binary)
 
             # now, run the test group
             self.run_test_group()
 
-        except:
+        except Exception:
             traceback.print_exc()
             self.numpassed = 0
             self.numfailed = 1
             try:
                 self.writeToResultFile(self.postdata,
                                        '<pre>%s</pre>' % traceback.format_exc())
-            except:
+            except Exception:
                 traceback.print_exc()
         else:
             try:
 
                 if self.numfailed > 0 or self.numpassed == 0:
                     To = self.config['email'].get('notificationlist')
                 else:
                     To = self.config['email'].get('passednotificationlist')
                 self.writeToResultFile(self.postdata,
                                        sendTo=To)
-            except:
+            except Exception:
                 traceback.print_exc()
                 try:
                     self.writeToResultFile(self.postdata,
                                            '<pre>%s</pre>' % traceback.format_exc())
-                except:
+                except Exception:
                     traceback.print_exc()
 
         # release our lock
         if self.rlock:
             self.rlock.release()
 
         # dump out a summary of test results
         print 'Test Summary\n'
@@ -467,21 +469,22 @@ class TPSTestRunner(object):
                                  'name': result['name'],
                                  'message': result['message'],
                                  'logdata': result['logdata']})
             if result['state'] == 'TEST-PASS':
                 self.numpassed += 1
             else:
                 self.numfailed += 1
                 if self.stop_on_error:
-                    print '\nTest failed with --stop-on-error specified; not running any more tests.\n'
+                    print '\nTest failed with --stop-on-error specified; ' \
+                          'not running any more tests.\n'
                     break
 
         self.mozhttpd.stop()
 
         # generate the postdata we'll use to post the results to the db
-        self.postdata = { 'tests': self.results,
-                          'os': '%s %sbit' % (mozinfo.version, mozinfo.bits),
-                          'testtype': 'crossweave',
-                          'productversion': self.productversion,
-                          'addonversion': self.addonversion,
-                          'synctype': self.synctype,
-                        }
+        self.postdata = {'tests': self.results,
+                         'os': '%s %sbit' % (mozinfo.version, mozinfo.bits),
+                         'testtype': 'crossweave',
+                         'productversion': self.productversion,
+                         'addonversion': self.addonversion,
+                         'synctype': self.synctype,
+                         }
--- a/tools/lint/flake8.yml
+++ b/tools/lint/flake8.yml
@@ -45,16 +45,17 @@ flake8:
         - testing/mozharness/mozharness/mozilla/tooltool.py
         - testing/mozharness/mozinfo
         - testing/mozharness/scripts
         - testing/mozharness/test
         - testing/raptor
         - testing/remotecppunittests.py
         - testing/runcppunittests.py
         - testing/talos/
+        - testing/tps/
         - testing/xpcshell
         - toolkit/components/telemetry
         - toolkit/crashreporter/tools/upload_symbols.py
         - tools/
         - xpcom/
     # Excludes should be added to topsrcdir/.flake8 due to a bug in flake8 where
     # specifying --exclude causes custom configuration files to be ignored.
     exclude: []