Bug 1428706 - [mozcrash] Add support for Python 3; r=ted
authorA. Wilcox <AWilcox@Wilcox-Tech.com>
Mon, 11 Feb 2019 13:37:25 +0000
changeset 458535 184745d744bfb4e4ffd18852cb88bcc34d15e408
parent 458534 9d4a32e1dd254ae672fd1f1d35f7a746e648dba3
child 458536 41ba287d84daace7ab964715e34dab7b3c3e25b5
push id111855
push userbtara@mozilla.com
push dateMon, 11 Feb 2019 22:01:49 +0000
treeherdermozilla-inbound@42a097167d36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs1428706
milestone67.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 1428706 - [mozcrash] Add support for Python 3; r=ted Differential Revision: https://phabricator.services.mozilla.com/D19132
testing/mozbase/mozcrash/mozcrash/mozcrash.py
testing/mozbase/mozcrash/tests/manifest.ini
testing/mozbase/mozcrash/tests/test_symbols_path.py
--- a/testing/mozbase/mozcrash/mozcrash/mozcrash.py
+++ b/testing/mozbase/mozcrash/mozcrash/mozcrash.py
@@ -7,19 +7,19 @@ from __future__ import absolute_import, 
 import glob
 import os
 import re
 import shutil
 import signal
 import subprocess
 import sys
 import tempfile
-import urllib2
 import zipfile
 from collections import namedtuple
+from six.moves.urllib.request import urlopen
 
 import mozfile
 import mozinfo
 import mozlog
 
 __all__ = [
     'check_for_crashes',
     'check_for_java_exception',
@@ -105,17 +105,19 @@ def check_for_crashes(dump_directory,
                                         info.stackwalk_retcode))
             signature = info.signature if info.signature else "unknown top frame"
 
             output = u"PROCESS-CRASH | {name} | application crashed [{sig}]\n{out}\n{err}".format(
                 name=test_name,
                 sig=signature,
                 out="\n".join(stackwalk_output),
                 err="\n".join(info.stackwalk_errors))
-            print(output.encode("utf-8"))
+            if sys.stdout.encoding != 'UTF-8':
+                output = output.encode('utf-8')
+            print(output)
 
     return crash_count
 
 
 def log_crashes(logger,
                 dump_directory,
                 symbols_path,
                 process=None,
@@ -174,17 +176,17 @@ class CrashInfo(object):
             self.symbols_path = tempfile.mkdtemp()
             self.remove_symbols = True
 
         # This updates self.symbols_path so we only download once.
         if mozfile.is_url(self.symbols_path):
             self.remove_symbols = True
             self.logger.info("Downloading symbols from: %s" % self.symbols_path)
             # Get the symbols and write them to a temporary zipfile
-            data = urllib2.urlopen(self.symbols_path)
+            data = urlopen(self.symbols_path)
             with tempfile.TemporaryFile() as symbols_file:
                 symbols_file.write(data.read())
                 # extract symbols to a temporary directory (which we'll delete after
                 # processing all crashes)
                 self.symbols_path = tempfile.mkdtemp()
                 with zipfile.ZipFile(symbols_file, 'r') as zfile:
                     mozfile.extract_zip(zfile, self.symbols_path)
 
--- a/testing/mozbase/mozcrash/tests/manifest.ini
+++ b/testing/mozbase/mozcrash/tests/manifest.ini
@@ -1,8 +1,7 @@
 [DEFAULT]
 subsuite = mozbase
-skip-if = python == 3
 [test_basic.py]
 [test_java_exception.py]
 [test_save_path.py]
 [test_stackwalk.py]
 [test_symbols_path.py]
--- a/testing/mozbase/mozcrash/tests/test_symbols_path.py
+++ b/testing/mozbase/mozcrash/tests/test_symbols_path.py
@@ -1,16 +1,16 @@
 #!/usr/bin/env python
 # coding=UTF-8
 
 from __future__ import absolute_import
 
-import urlparse
 import zipfile
-import StringIO
+from six import BytesIO
+from six.moves.urllib.parse import urlunsplit
 
 import mozhttpd
 import mozunit
 
 from conftest import fspath
 
 
 def test_symbols_path_not_present(check_for_crashes, minidump_files):
@@ -29,34 +29,34 @@ def test_symbols_path_unicode(check_for_
     assert fspath(symbols_path) in out
 
 
 def test_symbols_path_url(check_for_crashes, minidump_files):
     """Test that passing a URL as symbols_path correctly fetches the URL."""
     data = {"retrieved": False}
 
     def make_zipfile():
-        data = StringIO.StringIO()
+        data = BytesIO()
         z = zipfile.ZipFile(data, 'w')
         z.writestr("symbols.txt", "abc/xyz")
         z.close()
         return data.getvalue()
 
     def get_symbols(req):
         data["retrieved"] = True
 
         headers = {}
         return (200, headers, make_zipfile())
 
     httpd = mozhttpd.MozHttpd(port=0,
                               urlhandlers=[{'method': 'GET',
                                             'path': '/symbols',
                                             'function': get_symbols}])
     httpd.start()
-    symbol_url = urlparse.urlunsplit(('http', '%s:%d' % httpd.httpd.server_address,
-                                      '/symbols', '', ''))
+    symbol_url = urlunsplit(('http', '%s:%d' % httpd.httpd.server_address,
+                             '/symbols', '', ''))
 
     assert 1 == check_for_crashes(symbols_path=symbol_url)
     assert data["retrieved"]
 
 
 if __name__ == '__main__':
     mozunit.main()