Fix deps compatibility, increase tests coverage i(#3233)

* Compatibility with python-json-logger>=3.1

After refactoring the old API is still working, but producing warnings
and pyright also fails.

Besides that improve coverage of watchdog/base.py and ctl.py

* Stick to ubuntu 22.04

* Please pyright
This commit is contained in:
Alexander Kukushkin
2024-12-24 09:11:17 +01:00
committed by GitHub
parent e73f2044c8
commit 836e527e6d
5 changed files with 28 additions and 15 deletions
+7
View File
@@ -399,6 +399,13 @@ class TestCtl(unittest.TestCase):
result = self.runner.invoke(ctl, ctl_args, input='y')
assert result.exit_code == 0
ctl_args = ['restart', 'alpha', '--pg-version', '99.0', '--pending', '--scheduled', '2300-10-01T14:30']
# normal restart, the schedule is actually parsed, but not validated in patronictl
mock_post.return_value.status = 200
result = self.runner.invoke(ctl, ctl_args, input='y')
assert result.exit_code == 0
assert 'might be different from the ones' in result.output
# get restart with the non-200 return code
# normal restart, the schedule is actually parsed, but not validated in patronictl
mock_post.return_value.status = 204
+7 -2
View File
@@ -13,9 +13,13 @@ from patroni.config import Config
from patroni.log import PatroniLogger
try:
from pythonjsonlogger import jsonlogger
try:
from pythonjsonlogger import json as jsonlogger
except ImportError:
from pythonjsonlogger import jsonlogger
jsonlogger.JsonFormatter(None, None, rename_fields={}, static_fields={})
jsonlogger.JsonFormatter(None, None, rename_fields={}, static_fields={})
json_formatter_is_available = True
import json # we need json.loads() function
@@ -274,6 +278,7 @@ class TestPatroniLogger(unittest.TestCase):
with self.assertLogs() as captured_log:
logger = PatroniLogger()
pythonjsonlogger = Mock()
pythonjsonlogger.json.JsonFormatter = Mock(side_effect=Exception)
pythonjsonlogger.jsonlogger.JsonFormatter = Mock(side_effect=Exception)
with patch('builtins.__import__', Mock(return_value=pythonjsonlogger)):
logger.reload_config({'type': 'json'})