diff --git a/.gitignore b/.gitignore index a97e73a..229b1af 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ summon_process.egg-info dist build *.pyc + +.idea/ +atlassian-ide-plugin.xml diff --git a/README.rst b/README.rst index 4e92db9..82e5f30 100644 --- a/README.rst +++ b/README.rst @@ -1,8 +1,7 @@ summon_process ============== -**Current status:** work in progress. The code is lacking proper documentation -and is broken on Python 3.3. +**Current status:** work in progress. The code is lacking proper documentation. .. image:: https://travis-ci.org/mlen/summon_process.png?branch=master :target: https://travis-ci.org/mlen/summon_process diff --git a/setup.py b/setup.py index 6f76ffe..2f2ff45 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,9 @@ from setuptools import setup, find_packages setup(name='summon_process', - version='0.1.3', + version='0.1.4', description='Process coordinator for tests', - long_description=file('README.rst').read(), + long_description=open('README.rst').read(), url='https://github.com/mlen/summon_process', author='Mateusz Lenik', author_email='mlen@mlen.pl', diff --git a/summon_process/executors/simple_executor.py b/summon_process/executors/simple_executor.py index e92ed4a..263c97b 100644 --- a/summon_process/executors/simple_executor.py +++ b/summon_process/executors/simple_executor.py @@ -31,11 +31,20 @@ def running(self): return self._process.poll() is None def start(self): + """ + .. note:: + We want to open ``stdin``, ``stdout`` and ``stderr`` as text + streams in universal newlines mode, so we have to set + ``universal_newlines`` to ``True``. + """ if self._process is None: - self._process = subprocess.Popen(self._args, - shell=self._shell, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE) + self._process = subprocess.Popen( + self._args, + shell=self._shell, + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + universal_newlines=True, + ) if self._timeout: self._endtime = time.time() + self._timeout diff --git a/summon_process/tests/executors/test_http_coordinated_executor.py b/summon_process/tests/executors/test_http_coordinated_executor.py index dc301b6..4800c19 100644 --- a/summon_process/tests/executors/test_http_coordinated_executor.py +++ b/summon_process/tests/executors/test_http_coordinated_executor.py @@ -1,7 +1,15 @@ import os from unittest import TestCase -from httplib import HTTPConnection, OK + + +try: + from httplib import HTTPConnection, OK + http_server = "SimpleHTTPServer" +except ImportError: + # In python3 httplib is renamed to http.client + from http.client import HTTPConnection, OK + http_server = "http.server" from summon_process.executors import HTTPCoordinatedExecutor, TimeoutExpired @@ -11,7 +19,9 @@ class TestHTTPCoordinatedExecutor(TestCase): port = "8000" def test_it_waits_for_process_to_complete_head_request(self): - command = 'bash -c "sleep 3 && exec python -m SimpleHTTPServer"' + command = 'bash -c "sleep 3 && exec python -m {http_server}"'.format( + http_server=http_server, + ) executor = HTTPCoordinatedExecutor( command, 'http://{0}:{1}/'.format(self.host, self.port) ) diff --git a/summon_process/tests/slow_server.py b/summon_process/tests/slow_server.py index f0dce69..6903673 100644 --- a/summon_process/tests/slow_server.py +++ b/summon_process/tests/slow_server.py @@ -1,9 +1,16 @@ import time -from BaseHTTPServer import ( - HTTPServer, - BaseHTTPRequestHandler, -) +try: + from BaseHTTPServer import ( + HTTPServer, + BaseHTTPRequestHandler, + ) +except ImportError: + # python3 + from http.server import ( + HTTPServer, + BaseHTTPRequestHandler, + ) class SlowServerHandler(BaseHTTPRequestHandler):