From 0276d7e3cc82e8d3b5a9b922ff9dbd1a2dc01b77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mas=C5=82owski?= Date: Fri, 2 Aug 2019 11:03:49 +0200 Subject: [PATCH 1/7] Do not build nor install on Python 3.5 --- .travis.yml | 1 - setup.py | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e93dcd46..aa4ac8f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ dist: xenial language: python conditions: v1 python: -- 3.5 - 3.6 - 3.7 - pypy3 diff --git a/setup.py b/setup.py index 611ad7ba..02f4c35a 100644 --- a/setup.py +++ b/setup.py @@ -64,7 +64,7 @@ def read(fname): author='Clearcode - The A Room', author_email='thearoom@clearcode.cc', license='LGPL', - python_requires='>=3.5', + python_requires='>=3.6', classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Web Environment', @@ -75,7 +75,6 @@ def read(fname): 'Operating System :: OS Independent', 'Programming Language :: Python', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.6', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3 :: Only', From d6f3370531d6d4fca0bb11932322682acb978f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mas=C5=82owski?= Date: Fri, 2 Aug 2019 11:04:09 +0200 Subject: [PATCH 2/7] Use the Python 3.6 variable type annotation syntax --- src/mirakuru/base.py | 9 ++++----- src/mirakuru/base_env.py | 2 +- src/mirakuru/output.py | 2 +- tests/executors/test_http_executor.py | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/mirakuru/base.py b/src/mirakuru/base.py index e26faee9..6495d41d 100644 --- a/src/mirakuru/base.py +++ b/src/mirakuru/base.py @@ -151,8 +151,8 @@ def __init__( # pylint:disable=too-many-arguments self._stdout = stdout self._stderr = stderr - self._endtime = None # type: Optional[float] - self.process = None # type: Optional[subprocess.Popen] + self._endtime: Optional[float] = None + self.process: Optional[subprocess.Popen] = None """A :class:`subprocess.Popen` instance once process is started.""" self._uuid = '{0}:{1}'.format(os.getpid(), uuid.uuid4()) @@ -196,7 +196,7 @@ def _popen_kwargs(self) -> Dict[str, Any]: :return: """ - kwargs = {} # type: Dict[str, Any] + kwargs: Dict[str, Any] = {} if self._stdin: kwargs['stdin'] = self._stdin @@ -239,8 +239,7 @@ def start(self: SimpleExecutorType) -> SimpleExecutorType: :rtype: SimpleExecutor """ if self.process is None: - command = \ - self.command # type: Union[str, List[str], Tuple[str, ...]] + command: Union[str, List[str], Tuple[str, ...]] = self.command if not self._shell: command = self.command_parts diff --git a/src/mirakuru/base_env.py b/src/mirakuru/base_env.py index 9538972e..b6ebf82b 100644 --- a/src/mirakuru/base_env.py +++ b/src/mirakuru/base_env.py @@ -78,7 +78,7 @@ def processes_with_env_ps(env_name: str, env_value: str) -> Set[int]: environment variable equal certain value :rtype: set """ - pids = set() # type: Set[int] + pids: Set[int] = set() ps_xe = '' try: cmd = 'ps', 'xe', '-o', 'pid,cmd' diff --git a/src/mirakuru/output.py b/src/mirakuru/output.py index 5dba50c1..1f33507d 100644 --- a/src/mirakuru/output.py +++ b/src/mirakuru/output.py @@ -71,7 +71,7 @@ def start(self: OutputExecutorType) -> OutputExecutorType: """ super(OutputExecutor, self).start() - polls = [] # type: List[Tuple[select.poll, IO[Any]]] + polls: List[Tuple[select.poll, IO[Any]]] = [] for output_handle, output_method in ( (self._stdout, self.output), diff --git a/tests/executors/test_http_executor.py b/tests/executors/test_http_executor.py index c7125de6..d0d2fa8a 100644 --- a/tests/executors/test_http_executor.py +++ b/tests/executors/test_http_executor.py @@ -215,11 +215,11 @@ def test_http_status_codes(accepted_status, expected_timeout): :param int|str accepted_status: Executor 'status' value :param bool expected_timeout: if Executor raises TimeoutExpired or not """ - kwargs = { + kwargs: Dict[str, Any] = { 'command': HTTP_NORMAL_CMD, 'url': 'http://{0}:{1}/badpath'.format(HOST, PORT), 'timeout': 2 - } # type: Dict[str, Any] + } if accepted_status: kwargs['status'] = accepted_status executor = HTTPExecutor(**kwargs) From a20abb9e0ea03e1b87d356803ba5b5dd1b0a0a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mas=C5=82owski?= Date: Fri, 2 Aug 2019 11:55:03 +0200 Subject: [PATCH 3/7] Use f-strings instead of str.format Fix exception message accessing executor.port even for executors not having port numbers. --- src/mirakuru/base.py | 19 +++----- src/mirakuru/base_env.py | 2 +- src/mirakuru/exceptions.py | 21 +++++---- tests/__init__.py | 4 +- tests/executors/test_executor.py | 13 +++--- tests/executors/test_executor_kill.py | 4 +- tests/executors/test_http_executor.py | 51 ++++++++------------- tests/executors/test_pid_executor.py | 8 ++-- tests/executors/test_tcp_executor.py | 2 +- tests/executors/test_unixsocket_executor.py | 8 +--- tests/server_for_tests.py | 2 +- tests/signals.py | 2 +- tests/unixsocketserver_for_tests.py | 4 +- 13 files changed, 58 insertions(+), 82 deletions(-) diff --git a/src/mirakuru/base.py b/src/mirakuru/base.py index 6495d41d..4a281e22 100644 --- a/src/mirakuru/base.py +++ b/src/mirakuru/base.py @@ -155,7 +155,7 @@ def __init__( # pylint:disable=too-many-arguments self.process: Optional[subprocess.Popen] = None """A :class:`subprocess.Popen` instance once process is started.""" - self._uuid = '{0}:{1}'.format(os.getpid(), uuid.uuid4()) + self._uuid = f'{os.getpid()}:{uuid.uuid4()}' def __enter__(self: SimpleExecutorType) -> SimpleExecutorType: """ @@ -445,20 +445,15 @@ def __repr__(self) -> str: command = self.command if len(command) > 10: command = command[:10] + '...' - return '<{module}.{executor}: "{command}" {id}>'.format( - module=self.__class__.__module__, - executor=self.__class__.__name__, - command=command, - id=hex(id(self)) - ) + module = self.__class__.__module__ + executor = self.__class__.__name__ + return f'<{module}.{executor}: "{command}" {hex(id(self))}>' def __str__(self) -> str: """Return readable executor representation.""" - return '<{module}.{executor}: "{command}">'.format( - module=self.__class__.__module__, - executor=self.__class__.__name__, - command=self.command - ) + module = self.__class__.__module__ + executor = self.__class__.__name__ + return f'<{module}.{executor}: "{self.command}" {hex(id(self))}>' class Executor(SimpleExecutor): diff --git a/src/mirakuru/base_env.py b/src/mirakuru/base_env.py index b6ebf82b..fe265a39 100644 --- a/src/mirakuru/base_env.py +++ b/src/mirakuru/base_env.py @@ -93,7 +93,7 @@ def processes_with_env_ps(env_name: str, env_value: str) -> Set[int]: except subprocess.CalledProcessError: log.error("`$ ps xe -o pid,cmd` command exited with non-zero code.") - env = '{0}={1}'.format(env_name, env_value) + env = f'{env_name}={env_value}' for line in ps_xe: line = str(line) diff --git a/src/mirakuru/exceptions.py b/src/mirakuru/exceptions.py index 5637cb5e..58d627be 100644 --- a/src/mirakuru/exceptions.py +++ b/src/mirakuru/exceptions.py @@ -43,8 +43,8 @@ def __str__(self) -> str: :returns: string representation :rtype: str """ - return 'Executor {0} timed out after {1} seconds'.format( - self.executor, self.timeout + return ( + f'Executor {self.executor} timed out after {self.timeout} seconds' ) @@ -63,11 +63,13 @@ def __str__(self) -> str: :returns: string representation :rtype: str """ - return ("Executor {exc.executor} seems to be already running. " - "It looks like the previous executor process hasn't been " - "terminated or killed. Also there might be some completely " - "different service listening on {exc.executor.port} port." - .format(exc=self)) + port = getattr(self.executor, 'port') + return (f"Executor {self.executor} seems to be already running. " + f"It looks like the previous executor process hasn't been " + f"terminated or killed." + + ("" if port is None else + f" Also there might be some completely " + f"different service listening on {port} port.")) class ProcessExitedWithError(ExecutorError): @@ -97,6 +99,5 @@ def __str__(self) -> str: :returns: string representation :rtype: str """ - return ("The process invoked by the {exc.executor} executor has " - "exited with a non-zero code: {exc.exit_code}." - .format(exc=self)) + return (f"The process invoked by the {self.executor} executor has " + f"exited with a non-zero code: {self.exit_code}.") diff --git a/tests/__init__.py b/tests/__init__.py index 21ab4a22..086a51da 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -15,9 +15,7 @@ TEST_SOCKET_SERVER_PATH = path.join(TEST_PATH, 'unixsocketserver_for_tests.py') SAMPLE_DAEMON_PATH = path.join(TEST_PATH, "sample_daemon.py") -HTTP_SERVER_CMD = ( - "{python} -m http.server" -).format(python=sys.executable) +HTTP_SERVER_CMD = f"{sys.executable} -m http.server" def ps_aux(): diff --git a/tests/executors/test_executor.py b/tests/executors/test_executor.py index f8a65ea2..910b7591 100644 --- a/tests/executors/test_executor.py +++ b/tests/executors/test_executor.py @@ -148,7 +148,7 @@ def test_forgotten_stop(): # get substituted with 'sleep 300' and the marked commandline would be # overwritten. # Injecting some flow control (`&&`) forces bash to fork properly. - marked_command = 'sleep 300 && true #{0!s}'.format(mark) + marked_command = f'sleep 300 && true #{mark!s}' executor = SimpleExecutor(marked_command, shell=True) executor.start() assert executor.running() is True @@ -168,7 +168,7 @@ def test_executor_raises_if_process_exits_with_error(): """ error_code = 12 failing_executor = Executor( - ['bash', '-c', 'exit {0!s}'.format(error_code)], + ['bash', '-c', f'exit {error_code!s}'], timeout=5 ) failing_executor.pre_start_check = mock.Mock( # type: ignore @@ -181,7 +181,7 @@ def test_executor_raises_if_process_exits_with_error(): failing_executor.start() assert exc.value.exit_code == 12 - error_msg = 'exited with a non-zero code: {0!s}'.format(error_code) + error_msg = f'exited with a non-zero code: {error_code!s}' assert error_msg in str(exc.value) # Pre-start check should have been called - after-start check might or @@ -228,14 +228,15 @@ def test_executor_methods_returning_self(): def test_mirakuru_cleanup(): """Test if cleanup_subprocesses is fired correctly on python exit.""" - cmd = ''' + cmd = f''' python -c 'from mirakuru import SimpleExecutor; from time import sleep; import gc; gc.disable(); - ex = SimpleExecutor(("python", "{0}")).start(); + ex = SimpleExecutor( + ("python", "{SAMPLE_DAEMON_PATH}")).start(); sleep(1); ' - '''.format(SAMPLE_DAEMON_PATH) + ''' check_output(shlex.split(cmd.replace('\n', ''))) assert SAMPLE_DAEMON_PATH not in ps_aux() diff --git a/tests/executors/test_executor_kill.py b/tests/executors/test_executor_kill.py index e624eec4..a6b47482 100644 --- a/tests/executors/test_executor_kill.py +++ b/tests/executors/test_executor_kill.py @@ -76,8 +76,8 @@ def test_stopping_brutally(): by executor with SIGKILL automatically. """ host_port = "127.0.0.1:8000" - cmd = '{0} {1} {2} True'.format(sys.executable, TEST_SERVER_PATH, host_port) - executor = HTTPExecutor(cmd, 'http://{0!s}/'.format(host_port), timeout=20) + cmd = f'{sys.executable} {TEST_SERVER_PATH} {host_port} True' + executor = HTTPExecutor(cmd, f'http://{host_port!s}/', timeout=20) executor.start() assert executor.running() is True diff --git a/tests/executors/test_http_executor.py b/tests/executors/test_http_executor.py index d0d2fa8a..02357dae 100644 --- a/tests/executors/test_http_executor.py +++ b/tests/executors/test_http_executor.py @@ -15,15 +15,14 @@ HOST = "127.0.0.1" PORT = 7987 -HTTP_NORMAL_CMD = '{0} {1}'.format(HTTP_SERVER_CMD, PORT) -HTTP_SLOW_CMD = '{python} {srv} {host}:{port}' \ - .format(python=sys.executable, srv=TEST_SERVER_PATH, host=HOST, port=PORT) +HTTP_NORMAL_CMD = f'{HTTP_SERVER_CMD} {PORT}' +HTTP_SLOW_CMD = f'{sys.executable} {TEST_SERVER_PATH} {HOST}:{PORT}' slow_server_executor = partial( # pylint: disable=invalid-name HTTPExecutor, HTTP_SLOW_CMD, - 'http://{0}:{1}/'.format(HOST, PORT), + f'http://{HOST}:{PORT}/', ) @@ -37,11 +36,11 @@ def connect_to_server(): def test_executor_starts_and_waits(): """Test if process awaits for HEAD request to be completed.""" - command = 'bash -c "sleep 3 && {0}"'.format(HTTP_NORMAL_CMD) + command = f'bash -c "sleep 3 && {HTTP_NORMAL_CMD}"' executor = HTTPExecutor( command, - 'http://{0}:{1}/'.format(HOST, PORT), + f'http://{HOST}:{PORT}/', timeout=20 ) executor.start() @@ -60,7 +59,7 @@ def test_shell_started_server_stops(): """Test if executor terminates properly executor with shell=True.""" executor = HTTPExecutor( HTTP_NORMAL_CMD, - 'http://{0}:{1}/'.format(HOST, PORT), + f'http://{HOST}:{PORT}/', timeout=20, shell=True ) @@ -89,16 +88,12 @@ def test_slow_method_server_starting(method): wait for worker processes. """ - http_method_slow_cmd = '{python} {srv} {host}:{port} False {method}'.format( - python=sys.executable, - srv=TEST_SERVER_PATH, - host=HOST, - port=PORT, - method=method + http_method_slow_cmd = ( + f'{sys.executable} {TEST_SERVER_PATH} {HOST}:{PORT} False {method}' ) with HTTPExecutor( http_method_slow_cmd, - 'http://{0}:{1}/'.format(HOST, PORT), method=method, timeout=30 + f'http://{HOST}:{PORT}/', method=method, timeout=30 ) as executor: assert executor.running() is True connect_to_server() @@ -112,16 +107,12 @@ def test_slow_post_payload_server_starting(): wait for worker processes. """ - http_method_slow_cmd = '{python} {srv} {host}:{port} False {method}'.format( - python=sys.executable, - srv=TEST_SERVER_PATH, - host=HOST, - port=PORT, - method='Key' + http_method_slow_cmd = ( + f'{sys.executable} {TEST_SERVER_PATH} {HOST}:{PORT} False Key' ) with HTTPExecutor( http_method_slow_cmd, - 'http://{0}:{1}/'.format(HOST, PORT), + f'http://{HOST}:{PORT}/', method='POST', timeout=30, payload={'key': 'hole'} @@ -136,16 +127,12 @@ def test_slow_post_payload_server_starting(): def test_slow_method_server_timed_out(method): """Check if timeout properly expires.""" - http_method_slow_cmd = '{python} {srv} {host}:{port} False {method}'.format( - python=sys.executable, - srv=TEST_SERVER_PATH, - host=HOST, - port=PORT, - method=method + http_method_slow_cmd = ( + f'{sys.executable} {TEST_SERVER_PATH} {HOST}:{PORT} False {method}' ) executor = HTTPExecutor( http_method_slow_cmd, - 'http://{0}:{1}/'.format(HOST, PORT), method=method, timeout=1 + f'http://{HOST}:{PORT}/', method=method, timeout=1 ) with pytest.raises(TimeoutExpired) as exc: @@ -158,10 +145,10 @@ def test_slow_method_server_timed_out(method): def test_fail_if_other_running(): """Test raising AlreadyRunning exception when port is blocked.""" executor = HTTPExecutor( - HTTP_NORMAL_CMD, 'http://{0}:{1}/'.format(HOST, PORT), + HTTP_NORMAL_CMD, f'http://{HOST}:{PORT}/', ) executor2 = HTTPExecutor( - HTTP_NORMAL_CMD, 'http://{0}:{1}/'.format(HOST, PORT), + HTTP_NORMAL_CMD, f'http://{HOST}:{PORT}/', ) with executor: @@ -185,7 +172,7 @@ def test_default_port(): Check if HTTP executor fills in the default port for the TCP check from the base class if no port is provided in the URL. """ - executor = HTTPExecutor(HTTP_NORMAL_CMD, 'http://{0}/'.format(HOST)) + executor = HTTPExecutor(HTTP_NORMAL_CMD, f'http://{HOST}/') assert executor.url.port is None assert executor.port == PORT @@ -217,7 +204,7 @@ def test_http_status_codes(accepted_status, expected_timeout): """ kwargs: Dict[str, Any] = { 'command': HTTP_NORMAL_CMD, - 'url': 'http://{0}:{1}/badpath'.format(HOST, PORT), + 'url': f'http://{HOST}:{PORT}/badpath', 'timeout': 2 } if accepted_status: diff --git a/tests/executors/test_pid_executor.py b/tests/executors/test_pid_executor.py index 1dacd3fe..e513f76d 100644 --- a/tests/executors/test_pid_executor.py +++ b/tests/executors/test_pid_executor.py @@ -7,8 +7,8 @@ from mirakuru import TimeoutExpired, AlreadyRunning -FILENAME = "pid-test-tmp{0}".format(os.getpid()) -SLEEP = 'bash -c "sleep 1 && touch {0} && sleep 1"'.format(FILENAME) +FILENAME = f"pid-test-tmp{os.getpid()}" +SLEEP = f'bash -c "sleep 1 && touch {FILENAME} && sleep 1"' @pytest.yield_fixture(autouse=True) @@ -34,7 +34,7 @@ def run_around_tests(): def test_start_and_wait(): """Test if the executor will await for the process to create a file.""" - process = 'bash -c "sleep 2 && touch {0} && sleep 10"'.format(FILENAME) + process = f'bash -c "sleep 2 && touch {FILENAME} && sleep 10"' with PidExecutor(process, FILENAME, timeout=5) as executor: assert executor.running() is True @@ -70,7 +70,7 @@ def test_timeout_error(): def test_fail_if_other_executor_running(): """Test raising AlreadyRunning exception when port is blocked.""" - process = 'bash -c "sleep 2 && touch {0} && sleep 10"'.format(FILENAME) + process = f'bash -c "sleep 2 && touch {FILENAME} && sleep 10"' executor = PidExecutor(process, FILENAME) executor2 = PidExecutor(process, FILENAME) diff --git a/tests/executors/test_tcp_executor.py b/tests/executors/test_tcp_executor.py index 8df6fd0c..2dd2920d 100644 --- a/tests/executors/test_tcp_executor.py +++ b/tests/executors/test_tcp_executor.py @@ -13,7 +13,7 @@ PORT = 7986 -HTTP_SERVER = '{0} {1}'.format(HTTP_SERVER_CMD, PORT) +HTTP_SERVER = f'{HTTP_SERVER_CMD} {PORT}' def test_start_and_wait(): diff --git a/tests/executors/test_unixsocket_executor.py b/tests/executors/test_unixsocket_executor.py index c92db841..8f317e3a 100644 --- a/tests/executors/test_unixsocket_executor.py +++ b/tests/executors/test_unixsocket_executor.py @@ -14,13 +14,7 @@ SOCKET_PATH = '/tmp/mirakuru.sock' -SOCKET_SERVER_CMD = ( - "{python} {srv} {socket_path}" -).format( - python=sys.executable, - srv=TEST_SOCKET_SERVER_PATH, - socket_path=SOCKET_PATH, -) +SOCKET_SERVER_CMD = f"{sys.executable} {TEST_SOCKET_SERVER_PATH} {SOCKET_PATH}" def test_start_and_wait(): diff --git a/tests/server_for_tests.py b/tests/server_for_tests.py index 3a32f753..3837210d 100644 --- a/tests/server_for_tests.py +++ b/tests/server_for_tests.py @@ -141,5 +141,5 @@ def do_HEAD(self): # pylint:disable=invalid-name server = HTTPServer( # pylint: disable=invalid-name (HOST, int(PORT)), HANDLERS[METHOD] ) - print("Starting slow server on {0}:{1}...".format(HOST, PORT)) + print(f"Starting slow server on {HOST}:{PORT}...") server.serve_forever() diff --git a/tests/signals.py b/tests/signals.py index ef52e322..4b2e188d 100644 --- a/tests/signals.py +++ b/tests/signals.py @@ -12,7 +12,7 @@ def block_signals(): """ def sighandler(signum, _): """Signal handling function.""" - print('Tried to kill with signal {0}.'.format(signum)) + print(f'Tried to kill with signal {signum}.') for sgn in [x for x in dir(signal) if x.startswith("SIG")]: try: diff --git a/tests/unixsocketserver_for_tests.py b/tests/unixsocketserver_for_tests.py index 5d1a5c85..17f3f742 100644 --- a/tests/unixsocketserver_for_tests.py +++ b/tests/unixsocketserver_for_tests.py @@ -48,7 +48,7 @@ SOCK = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) # Bind the socket to the address -print('starting up on {}'.format(SOCKET_ADDRESS)) +print(f'starting up on {SOCKET_ADDRESS}') SOCK.bind(SOCKET_ADDRESS) sleep(SLEEP) @@ -65,7 +65,7 @@ # Receive the data in small chunks and retransmit it while True: RECEIVED_DATA = CONNECTION.recv(16) - print('received {!r}'.format(RECEIVED_DATA)) + print(f'received {RECEIVED_DATA!r}') if RECEIVED_DATA: print('sending data back to the client') CONNECTION.sendall(RECEIVED_DATA) From 7acadf3dd6e6f7490118c03eb583f37cb2b8c85f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mas=C5=82owski?= Date: Fri, 2 Aug 2019 12:17:28 +0200 Subject: [PATCH 4/7] Use pytest.ini to turn warnings into errors on all Python versions --- pytest.ini | 1 + tests/conftest.py | 31 ------------------------------- 2 files changed, 1 insertion(+), 31 deletions(-) delete mode 100644 tests/conftest.py diff --git a/pytest.ini b/pytest.ini index 39baf331..59bbf5e5 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,2 +1,3 @@ [pytest] testpaths = tests/ +filterwarnings = error diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index 83afd3da..00000000 --- a/tests/conftest.py +++ /dev/null @@ -1,31 +0,0 @@ -""" -Tests pre-configuration. - -* Filtering ResourceWarning for the Python 3. -* Fixture for raising an error whenever we leave any resource open. -""" -import platform -import os -import sys -from warnings import simplefilter - -import pytest - -IS_TRAVIS = 'TRAVIS' in os.environ -IS_PYPY_35 = ( - platform.python_implementation() == 'PyPy' and sys.version_info < (3, 6) -) - - -simplefilter( - 'default', - ResourceWarning -) - - -@pytest.fixture(autouse=True) -def error_warn(recwarn): - """Raise error whenever any warning gets listed.""" - yield - if recwarn.list and not (IS_PYPY_35 and IS_TRAVIS): - raise recwarn.list[0].message From 8493cc7ba9cbce946cb42fbab3e3885ee0c34c79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mas=C5=82owski?= Date: Fri, 2 Aug 2019 14:53:00 +0200 Subject: [PATCH 5/7] Run Travis build on Python 3.8 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index aa4ac8f4..64d2add4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,7 @@ conditions: v1 python: - 3.6 - 3.7 +- 3.8-dev - pypy3 # blocklist branches branches: From 99409e00bf33980e55d28d114f6c33d7f1e33852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mas=C5=82owski?= Date: Fri, 2 Aug 2019 16:36:07 +0200 Subject: [PATCH 6/7] Xfail test failing on Python 3.8 --- pytest.ini | 1 + tests/executors/test_executor_kill.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/pytest.ini b/pytest.ini index 59bbf5e5..35532b35 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,3 +1,4 @@ [pytest] testpaths = tests/ filterwarnings = error +xfail_strict = True diff --git a/tests/executors/test_executor_kill.py b/tests/executors/test_executor_kill.py index a6b47482..e8640005 100644 --- a/tests/executors/test_executor_kill.py +++ b/tests/executors/test_executor_kill.py @@ -8,6 +8,7 @@ import os from mock import patch +import pytest from mirakuru import SimpleExecutor, HTTPExecutor from mirakuru.compat import SIGKILL @@ -49,6 +50,11 @@ def process_stopped(): assert not executor.process +@pytest.mark.xfail( + condition=sys.version_info >= (3, 8), + reason='python-daemon 2.2.3 fails with ' + '; ' + 'unxfail when a newer version is used') def test_daemons_killing(): """ Test if all subprocesses of SimpleExecutor can be killed. From e7b1f83d9362bd83255356dc8408e9904a12fa25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Mas=C5=82owski?= Date: Fri, 2 Aug 2019 16:40:55 +0200 Subject: [PATCH 7/7] Replace mock by unittest.mock --- setup.py | 1 - tests/executors/test_executor.py | 2 +- tests/executors/test_executor_kill.py | 2 +- tests/executors/test_http_executor.py | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/setup.py b/setup.py index 02f4c35a..53add338 100644 --- a/setup.py +++ b/setup.py @@ -34,7 +34,6 @@ tests_require = ( 'pytest==5.0.1', # tests framework used 'pytest-cov==2.7.1', # coverage reports to verify tests quality - 'mock==3.0.5', # tests mocking tool 'python-daemon==2.2.3', # used in test for easy creation of daemons ) extras_require = { diff --git a/tests/executors/test_executor.py b/tests/executors/test_executor.py index 910b7591..8500e4b3 100644 --- a/tests/executors/test_executor.py +++ b/tests/executors/test_executor.py @@ -5,9 +5,9 @@ import signal from subprocess import check_output import uuid +from unittest import mock import pytest -import mock from mirakuru import Executor from mirakuru.base import SimpleExecutor diff --git a/tests/executors/test_executor_kill.py b/tests/executors/test_executor_kill.py index e8640005..ce5f42e1 100644 --- a/tests/executors/test_executor_kill.py +++ b/tests/executors/test_executor_kill.py @@ -7,7 +7,7 @@ import errno import os -from mock import patch +from unittest.mock import patch import pytest from mirakuru import SimpleExecutor, HTTPExecutor diff --git a/tests/executors/test_http_executor.py b/tests/executors/test_http_executor.py index 02357dae..06c502fe 100644 --- a/tests/executors/test_http_executor.py +++ b/tests/executors/test_http_executor.py @@ -4,9 +4,9 @@ from functools import partial from http.client import HTTPConnection, OK from typing import Dict, Any +from unittest.mock import patch import pytest -from mock import patch from mirakuru import HTTPExecutor, TCPExecutor from mirakuru import TimeoutExpired, AlreadyRunning