forked from mirrors/gecko-dev
Bug 1428713 - [mozprocess] Add support for Python 3 r=davehunt
MozReview-Commit-ID: 9wHoIEboA0K --HG-- extra : rebase_source : ef02475141a1c2d7aa1fb95e2da637b6c033c35f
This commit is contained in:
parent
4d5dd95038
commit
2022970c76
6 changed files with 29 additions and 25 deletions
|
|
@ -13,7 +13,10 @@ import threading
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from Queue import Queue, Empty
|
try:
|
||||||
|
from queue import Queue, Empty
|
||||||
|
except ImportError:
|
||||||
|
from Queue import Queue, Empty
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -124,14 +127,14 @@ class ProcessHandlerMixin(object):
|
||||||
thread = threading.current_thread().name
|
thread = threading.current_thread().name
|
||||||
print("DBG::MOZPROC PID:{} ({}) | {}".format(self.pid, thread, msg))
|
print("DBG::MOZPROC PID:{} ({}) | {}".format(self.pid, thread, msg))
|
||||||
|
|
||||||
def __del__(self, _maxint=sys.maxint):
|
def __del__(self, _maxint=sys.maxsize):
|
||||||
if isWin:
|
if isWin:
|
||||||
handle = getattr(self, '_handle', None)
|
handle = getattr(self, '_handle', None)
|
||||||
if handle:
|
if handle:
|
||||||
if hasattr(self, '_internal_poll'):
|
if hasattr(self, '_internal_poll'):
|
||||||
self._internal_poll(_deadstate=_maxint)
|
self._internal_poll(_deadstate=_maxint)
|
||||||
else:
|
else:
|
||||||
self.poll(_deadstate=sys.maxint)
|
self.poll(_deadstate=sys.maxsize)
|
||||||
if handle or self._job or self._io_port:
|
if handle or self._job or self._io_port:
|
||||||
self._cleanup()
|
self._cleanup()
|
||||||
else:
|
else:
|
||||||
|
|
@ -1069,7 +1072,7 @@ class StreamOutput(object):
|
||||||
|
|
||||||
def __call__(self, line):
|
def __call__(self, line):
|
||||||
try:
|
try:
|
||||||
self.stream.write(line + '\n')
|
self.stream.write(line.decode() + '\n')
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
# TODO: Workaround for bug #991866 to make sure we can display when
|
# TODO: Workaround for bug #991866 to make sure we can display when
|
||||||
# when normal UTF-8 display is failing
|
# when normal UTF-8 display is failing
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ from __future__ import absolute_import
|
||||||
|
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
|
|
||||||
PACKAGE_VERSION = '0.26'
|
PACKAGE_VERSION = '1.0.0'
|
||||||
|
|
||||||
setup(name='mozprocess',
|
setup(name='mozprocess',
|
||||||
version=PACKAGE_VERSION,
|
version=PACKAGE_VERSION,
|
||||||
|
|
@ -17,7 +17,8 @@ setup(name='mozprocess',
|
||||||
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
|
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
|
||||||
'Natural Language :: English',
|
'Natural Language :: English',
|
||||||
'Operating System :: OS Independent',
|
'Operating System :: OS Independent',
|
||||||
'Programming Language :: Python',
|
'Programming Language :: Python :: 2.7',
|
||||||
|
'Programming Language :: Python :: 3.5'
|
||||||
'Topic :: Software Development :: Libraries :: Python Modules',
|
'Topic :: Software Development :: Libraries :: Python Modules',
|
||||||
],
|
],
|
||||||
keywords='mozilla',
|
keywords='mozilla',
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
[DEFAULT]
|
[DEFAULT]
|
||||||
subsuite = mozbase, os == "linux"
|
subsuite = mozbase, os == "linux"
|
||||||
skip-if = python == 3
|
|
||||||
[test_kill.py]
|
[test_kill.py]
|
||||||
[test_misc.py]
|
[test_misc.py]
|
||||||
[test_poll.py]
|
[test_poll.py]
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,10 @@ from __future__ import absolute_import, print_function
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import collections
|
import collections
|
||||||
import ConfigParser
|
try:
|
||||||
|
import configparser as ConfigParser
|
||||||
|
except ImportError:
|
||||||
|
import ConfigParser
|
||||||
import multiprocessing
|
import multiprocessing
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import io
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import mozunit
|
import mozunit
|
||||||
|
|
||||||
import proctest
|
import proctest
|
||||||
from mozprocess import processhandler
|
from mozprocess import processhandler
|
||||||
|
import six
|
||||||
|
|
||||||
here = os.path.dirname(os.path.abspath(__file__))
|
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)])
|
expected = '\n'.join([str(n) for n in range(0, 10)])
|
||||||
|
|
||||||
stream = io.BytesIO()
|
stream = six.StringIO()
|
||||||
buf = io.BufferedRandom(stream)
|
|
||||||
|
|
||||||
p = processhandler.ProcessHandler([self.python,
|
p = processhandler.ProcessHandler([self.python,
|
||||||
os.path.join("scripts", "proccountfive.py")],
|
os.path.join("scripts", "proccountfive.py")],
|
||||||
cwd=here,
|
cwd=here,
|
||||||
stream=buf)
|
stream=stream)
|
||||||
|
|
||||||
p.run()
|
p.run()
|
||||||
p.wait()
|
p.wait()
|
||||||
for i in range(5, 10):
|
for i in range(5, 10):
|
||||||
stream.write(str(i) + '\n')
|
stream.write(str(i) + '\n')
|
||||||
|
|
||||||
buf.flush()
|
|
||||||
self.assertEquals(stream.getvalue().strip(), expected)
|
self.assertEquals(stream.getvalue().strip(), expected)
|
||||||
|
|
||||||
# make sure mozprocess doesn't close the stream
|
# make sure mozprocess doesn't close the stream
|
||||||
# since mozprocess didn't create it
|
# since mozprocess didn't create it
|
||||||
self.assertFalse(buf.closed)
|
self.assertFalse(stream.closed)
|
||||||
buf.close()
|
stream.close()
|
||||||
|
|
||||||
self.determine_status(p, False, ())
|
self.determine_status(p, False, ())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,11 @@ class TestProcessReader(unittest.TestCase):
|
||||||
timeout_callback=on_timeout)
|
timeout_callback=on_timeout)
|
||||||
|
|
||||||
def test_stdout_callback(self):
|
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.start(proc)
|
||||||
self.reader.thread.join()
|
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, [])
|
self.assertEqual(self.err.output, [])
|
||||||
|
|
||||||
def test_stderr_callback(self):
|
def test_stderr_callback(self):
|
||||||
|
|
@ -46,15 +46,15 @@ class TestProcessReader(unittest.TestCase):
|
||||||
self.reader.thread.join()
|
self.reader.thread.join()
|
||||||
|
|
||||||
self.assertEqual(self.out.output, [])
|
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):
|
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.start(proc)
|
||||||
self.reader.thread.join()
|
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, ['hello world'])
|
self.assertEqual(self.err.output, [b'hello world'])
|
||||||
|
|
||||||
def test_finished_callback(self):
|
def test_finished_callback(self):
|
||||||
self.assertFalse(self.finished)
|
self.assertFalse(self.finished)
|
||||||
|
|
@ -85,21 +85,21 @@ class TestProcessReader(unittest.TestCase):
|
||||||
proc = run_python('import sys; sys.stdout.write("1")')
|
proc = run_python('import sys; sys.stdout.write("1")')
|
||||||
self.reader.start(proc)
|
self.reader.start(proc)
|
||||||
self.reader.thread.join()
|
self.reader.thread.join()
|
||||||
self.assertEqual(self.out.output, ['1'])
|
self.assertEqual(self.out.output, [b'1'])
|
||||||
|
|
||||||
def test_read_with_strange_eol(self):
|
def test_read_with_strange_eol(self):
|
||||||
proc = run_python('import sys; sys.stdout.write("1\\r\\r\\r\\n")')
|
proc = run_python('import sys; sys.stdout.write("1\\r\\r\\r\\n")')
|
||||||
self.reader.start(proc)
|
self.reader.start(proc)
|
||||||
self.reader.thread.join()
|
self.reader.thread.join()
|
||||||
self.assertEqual(self.out.output, ['1'])
|
self.assertEqual(self.out.output, [b'1'])
|
||||||
|
|
||||||
def test_mixed_stdout_stderr(self):
|
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)
|
stderr=subprocess.STDOUT)
|
||||||
self.reader.start(proc)
|
self.reader.start(proc)
|
||||||
self.reader.thread.join()
|
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, [])
|
self.assertEqual(self.err.output, [])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue