diff --git a/testing/mozbase/mozprocess/mozprocess/processhandler.py b/testing/mozbase/mozprocess/mozprocess/processhandler.py index 3efb650b7721..9da6852f8bc9 100644 --- a/testing/mozbase/mozprocess/mozprocess/processhandler.py +++ b/testing/mozbase/mozprocess/mozprocess/processhandler.py @@ -13,7 +13,10 @@ import threading import time import traceback -from Queue import Queue, Empty +try: + from queue import Queue, Empty +except ImportError: + from Queue import Queue, Empty from datetime import datetime @@ -124,14 +127,14 @@ class ProcessHandlerMixin(object): thread = threading.current_thread().name print("DBG::MOZPROC PID:{} ({}) | {}".format(self.pid, thread, msg)) - def __del__(self, _maxint=sys.maxint): + def __del__(self, _maxint=sys.maxsize): if isWin: handle = getattr(self, '_handle', None) if handle: if hasattr(self, '_internal_poll'): self._internal_poll(_deadstate=_maxint) else: - self.poll(_deadstate=sys.maxint) + self.poll(_deadstate=sys.maxsize) if handle or self._job or self._io_port: self._cleanup() else: @@ -1069,7 +1072,7 @@ class StreamOutput(object): def __call__(self, line): try: - self.stream.write(line + '\n') + self.stream.write(line.decode() + '\n') except UnicodeDecodeError: # TODO: Workaround for bug #991866 to make sure we can display when # when normal UTF-8 display is failing diff --git a/testing/mozbase/mozprocess/setup.py b/testing/mozbase/mozprocess/setup.py index 91ebec771e9e..f97c578643e0 100644 --- a/testing/mozbase/mozprocess/setup.py +++ b/testing/mozbase/mozprocess/setup.py @@ -6,7 +6,7 @@ from __future__ import absolute_import from setuptools import setup -PACKAGE_VERSION = '0.26' +PACKAGE_VERSION = '1.0.0' setup(name='mozprocess', version=PACKAGE_VERSION, @@ -17,7 +17,8 @@ setup(name='mozprocess', 'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)', 'Natural Language :: English', 'Operating System :: OS Independent', - 'Programming Language :: Python', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.5' 'Topic :: Software Development :: Libraries :: Python Modules', ], keywords='mozilla', diff --git a/testing/mozbase/mozprocess/tests/manifest.ini b/testing/mozbase/mozprocess/tests/manifest.ini index 23803536dc58..e5e4e66c0ab1 100644 --- a/testing/mozbase/mozprocess/tests/manifest.ini +++ b/testing/mozbase/mozprocess/tests/manifest.ini @@ -1,6 +1,5 @@ [DEFAULT] subsuite = mozbase, os == "linux" -skip-if = python == 3 [test_kill.py] [test_misc.py] [test_poll.py] diff --git a/testing/mozbase/mozprocess/tests/proclaunch.py b/testing/mozbase/mozprocess/tests/proclaunch.py index 434818990de2..eba88f483b5f 100644 --- a/testing/mozbase/mozprocess/tests/proclaunch.py +++ b/testing/mozbase/mozprocess/tests/proclaunch.py @@ -4,7 +4,10 @@ from __future__ import absolute_import, print_function import argparse import collections -import ConfigParser +try: + import configparser as ConfigParser +except ImportError: + import ConfigParser import multiprocessing import time diff --git a/testing/mozbase/mozprocess/tests/test_output.py b/testing/mozbase/mozprocess/tests/test_output.py index 5f9be26bd449..67de8fcae4ab 100644 --- a/testing/mozbase/mozprocess/tests/test_output.py +++ b/testing/mozbase/mozprocess/tests/test_output.py @@ -2,13 +2,13 @@ from __future__ import absolute_import -import io import os import mozunit import proctest from mozprocess import processhandler +import six here = os.path.dirname(os.path.abspath(__file__)) @@ -49,26 +49,24 @@ class ProcTestOutput(proctest.ProcTest): """ expected = '\n'.join([str(n) for n in range(0, 10)]) - stream = io.BytesIO() - buf = io.BufferedRandom(stream) + stream = six.StringIO() p = processhandler.ProcessHandler([self.python, os.path.join("scripts", "proccountfive.py")], cwd=here, - stream=buf) + stream=stream) p.run() p.wait() for i in range(5, 10): stream.write(str(i) + '\n') - buf.flush() self.assertEquals(stream.getvalue().strip(), expected) # make sure mozprocess doesn't close the stream # since mozprocess didn't create it - self.assertFalse(buf.closed) - buf.close() + self.assertFalse(stream.closed) + stream.close() self.determine_status(p, False, ()) diff --git a/testing/mozbase/mozprocess/tests/test_process_reader.py b/testing/mozbase/mozprocess/tests/test_process_reader.py index eb94379caca6..077c16078f1f 100644 --- a/testing/mozbase/mozprocess/tests/test_process_reader.py +++ b/testing/mozbase/mozprocess/tests/test_process_reader.py @@ -33,11 +33,11 @@ class TestProcessReader(unittest.TestCase): timeout_callback=on_timeout) def test_stdout_callback(self): - proc = run_python('print 1; print 2') + proc = run_python('print(1); print(2)') self.reader.start(proc) self.reader.thread.join() - self.assertEqual(self.out.output, ['1', '2']) + self.assertEqual(self.out.output, [b'1', b'2']) self.assertEqual(self.err.output, []) def test_stderr_callback(self): @@ -46,15 +46,15 @@ class TestProcessReader(unittest.TestCase): self.reader.thread.join() self.assertEqual(self.out.output, []) - self.assertEqual(self.err.output, ['hello world']) + self.assertEqual(self.err.output, [b'hello world']) def test_stdout_and_stderr_callbacks(self): - proc = run_python('import sys; sys.stderr.write("hello world\\n"); print 1; print 2') + proc = run_python('import sys; sys.stderr.write("hello world\\n"); print(1); print(2)') self.reader.start(proc) self.reader.thread.join() - self.assertEqual(self.out.output, ['1', '2']) - self.assertEqual(self.err.output, ['hello world']) + self.assertEqual(self.out.output, [b'1', b'2']) + self.assertEqual(self.err.output, [b'hello world']) def test_finished_callback(self): self.assertFalse(self.finished) @@ -85,21 +85,21 @@ class TestProcessReader(unittest.TestCase): proc = run_python('import sys; sys.stdout.write("1")') self.reader.start(proc) self.reader.thread.join() - self.assertEqual(self.out.output, ['1']) + self.assertEqual(self.out.output, [b'1']) def test_read_with_strange_eol(self): proc = run_python('import sys; sys.stdout.write("1\\r\\r\\r\\n")') self.reader.start(proc) self.reader.thread.join() - self.assertEqual(self.out.output, ['1']) + self.assertEqual(self.out.output, [b'1']) def test_mixed_stdout_stderr(self): - proc = run_python('import sys; sys.stderr.write("hello world\\n"); print 1; print 2', + proc = run_python('import sys; sys.stderr.write("hello world\\n"); print(1); print(2)', stderr=subprocess.STDOUT) self.reader.start(proc) self.reader.thread.join() - self.assertEqual(sorted(self.out.output), sorted(['1', '2', 'hello world'])) + self.assertEqual(sorted(self.out.output), sorted([b'1', b'2', b'hello world'])) self.assertEqual(self.err.output, [])