зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1428713 - [mozprocess] Add support for Python 3 r=davehunt
MozReview-Commit-ID: 9wHoIEboA0K --HG-- extra : rebase_source : ef02475141a1c2d7aa1fb95e2da637b6c033c35f
This commit is contained in:
Родитель
4d5dd95038
Коммит
2022970c76
|
@ -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
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
[DEFAULT]
|
||||
subsuite = mozbase, os == "linux"
|
||||
skip-if = python == 3
|
||||
[test_kill.py]
|
||||
[test_misc.py]
|
||||
[test_poll.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
|
||||
|
||||
|
|
|
@ -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, ())
|
||||
|
||||
|
|
|
@ -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, [])
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче