mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Compatibility with latest psutil and setuptools (#2155)
Issues don't affect Patroni code, only unit-tests
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@@ -132,12 +133,8 @@ class PyTest(Command):
|
|||||||
except Exception:
|
except Exception:
|
||||||
raise RuntimeError('py.test is not installed, run: pip install pytest')
|
raise RuntimeError('py.test is not installed, run: pip install pytest')
|
||||||
|
|
||||||
import logging
|
|
||||||
silence = logging.WARNING
|
|
||||||
logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', level=os.getenv('LOGLEVEL', silence))
|
|
||||||
|
|
||||||
args = ['--verbose', 'tests', '--doctest-modules', MAIN_PACKAGE] +\
|
args = ['--verbose', 'tests', '--doctest-modules', MAIN_PACKAGE] +\
|
||||||
['-s' if logging.getLogger().getEffectiveLevel() < silence else '--capture=fd']
|
['-s' if logging.getLogger().getEffectiveLevel() < logging.WARNING else '--capture=fd']
|
||||||
if self.cov:
|
if self.cov:
|
||||||
args += self.cov
|
args += self.cov
|
||||||
|
|
||||||
@@ -162,6 +159,8 @@ def read(fname):
|
|||||||
|
|
||||||
|
|
||||||
def setup_package(version):
|
def setup_package(version):
|
||||||
|
logging.basicConfig(format='%(message)s', level=os.getenv('LOGLEVEL', logging.WARNING))
|
||||||
|
|
||||||
# Assemble additional setup commands
|
# Assemble additional setup commands
|
||||||
cmdclass = {'test': PyTest, 'flake8': Flake8}
|
cmdclass = {'test': PyTest, 'flake8': Flake8}
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,8 @@ class TestCancellableSubprocess(unittest.TestCase):
|
|||||||
def test_cancel(self):
|
def test_cancel(self):
|
||||||
self.c._process = Mock()
|
self.c._process = Mock()
|
||||||
self.c._process.is_running.return_value = True
|
self.c._process.is_running.return_value = True
|
||||||
self.c._process.children.side_effect = psutil.Error()
|
self.c._process.children.side_effect = psutil.NoSuchProcess(123)
|
||||||
self.c._process.suspend.side_effect = psutil.Error()
|
self.c._process.suspend.side_effect = psutil.AccessDenied()
|
||||||
self.c.cancel()
|
self.c.cancel()
|
||||||
self.c._process.is_running.side_effect = [True, False]
|
self.c._process.is_running.side_effect = [True, False]
|
||||||
self.c.cancel()
|
self.c.cancel()
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ class TestPostmasterProcess(unittest.TestCase):
|
|||||||
|
|
||||||
# all processes successfully stopped
|
# all processes successfully stopped
|
||||||
mock_children.return_value = [Mock()]
|
mock_children.return_value = [Mock()]
|
||||||
mock_children.return_value[0].kill.side_effect = psutil.Error
|
mock_children.return_value[0].kill.side_effect = psutil.NoSuchProcess(123)
|
||||||
self.assertTrue(proc.signal_kill())
|
self.assertTrue(proc.signal_kill())
|
||||||
|
|
||||||
# postmaster has gone before suspend
|
# postmaster has gone before suspend
|
||||||
@@ -81,17 +81,17 @@ class TestPostmasterProcess(unittest.TestCase):
|
|||||||
self.assertTrue(proc.signal_kill())
|
self.assertTrue(proc.signal_kill())
|
||||||
|
|
||||||
# postmaster has gone before we got a list of children
|
# postmaster has gone before we got a list of children
|
||||||
mock_suspend.side_effect = psutil.Error()
|
mock_suspend.side_effect = psutil.AccessDenied()
|
||||||
mock_children.side_effect = psutil.NoSuchProcess(123)
|
mock_children.side_effect = psutil.NoSuchProcess(123)
|
||||||
self.assertTrue(proc.signal_kill())
|
self.assertTrue(proc.signal_kill())
|
||||||
|
|
||||||
# postmaster has gone after we got a list of children
|
# postmaster has gone after we got a list of children
|
||||||
mock_children.side_effect = psutil.Error()
|
mock_children.side_effect = psutil.AccessDenied()
|
||||||
mock_kill.side_effect = psutil.NoSuchProcess(123)
|
mock_kill.side_effect = psutil.NoSuchProcess(123)
|
||||||
self.assertTrue(proc.signal_kill())
|
self.assertTrue(proc.signal_kill())
|
||||||
|
|
||||||
# failed to kill postmaster
|
# failed to kill postmaster
|
||||||
mock_kill.side_effect = psutil.AccessDenied(123)
|
mock_kill.side_effect = psutil.AccessDenied()
|
||||||
self.assertFalse(proc.signal_kill())
|
self.assertFalse(proc.signal_kill())
|
||||||
|
|
||||||
@patch('psutil.Process.__init__', Mock())
|
@patch('psutil.Process.__init__', Mock())
|
||||||
|
|||||||
Reference in New Issue
Block a user