Skip to content

Commit a903438

Browse files
authored
Compatibility with ydiff==1.4.2 (patroni#3216)
1. Implemented compatibility. 2. Constrained the upper version in requirements.txt to avoid future failures. 3. Setup an additional pipeline to check with the latest ydiff. Close patroni#3209 Close patroni#3212 Close patroni#3218
1 parent 19f75b4 commit a903438

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

.github/workflows/tests.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,23 @@ jobs:
188188
with:
189189
version: 1.1.385
190190

191+
ydiff:
192+
name: Test compatibility with the latest version of ydiff
193+
runs-on: ubuntu-latest
194+
steps:
195+
- uses: actions/checkout@v4
196+
197+
- name: Set up Python 3.12
198+
uses: actions/setup-python@v5
199+
with:
200+
python-version: 3.12
201+
- name: Install dependencies
202+
run: python .github/workflows/install_deps.py
203+
- name: Update ydiff
204+
run: python -m pip install -U ydiff
205+
- name: Run tests
206+
run: python -m pytest tests/test_ctl.py -v
207+
191208
docs:
192209
runs-on: ubuntu-latest
193210
steps:

patroni/ctl.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,12 +1896,13 @@ def listify(string: str) -> List[str]:
18961896
unified_diff = difflib.unified_diff(listify(before_editing), listify(after_editing))
18971897

18981898
if sys.stdout.isatty():
1899-
buf = io.StringIO()
1899+
buf = io.BytesIO()
19001900
for line in unified_diff:
1901-
buf.write(str(line))
1901+
buf.write(line.encode('utf-8'))
19021902
buf.seek(0)
19031903

19041904
class opts:
1905+
theme = 'default'
19051906
side_by_side = False
19061907
width = 80
19071908
tab_width = 8

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ python-dateutil
1010
pysyncobj>=0.3.8
1111
cryptography>=1.4
1212
psutil>=2.0.0
13-
ydiff>=1.2.0
13+
ydiff>=1.2.0,<1.5,!=1.4.0,!=1.4.1
1414
python-json-logger>=2.0.2

tests/test_ctl.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,17 @@ def test_show_diff(self, mock_which, mock_env_get, mock_markup_to_pager, mock_is
689689
show_diff(b"foo:\n bar: \xc3\xb6\xc3\xb6\n".decode('utf-8'),
690690
b"foo:\n bar: \xc3\xbc\xc3\xbc\n".decode('utf-8'))
691691

692+
@patch('subprocess.Popen')
693+
@patch('os.environ.get', Mock(return_value='cat'))
694+
@patch('sys.stdout.isatty', Mock(return_value=True))
695+
@patch('shutil.which', Mock(return_value='cat'))
696+
def test_show_diff_pager(self, mock_popen):
697+
show_diff("foo:\n bar: 1\n", "foo:\n bar: 2\n")
698+
self.assertEqual(mock_popen.return_value.stdin.write.call_count, 6)
699+
self.assertIn(b' bar: ', mock_popen.return_value.stdin.write.call_args_list[5][0][0])
700+
self.assertIn(b' bar: ', mock_popen.return_value.stdin.write.call_args_list[4][0][0])
701+
self.assertIn(b' foo:', mock_popen.return_value.stdin.write.call_args_list[3][0][0])
702+
692703
@patch('subprocess.call', return_value=1)
693704
def test_invoke_editor(self, mock_subprocess_call):
694705
os.environ.pop('EDITOR', None)

typings/cdiff/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import io
22
from typing import Any
33
class PatchStream:
4-
def __init__(self, diff_hdl: io.TextIOBase) -> None: ...
4+
def __init__(self, diff_hdl: io.BytesIOBase) -> None: ...
55
def markup_to_pager(stream: Any, opts: Any) -> None: ...

typings/ydiff/__init__.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import io
22
from typing import Any
33
class PatchStream:
4-
def __init__(self, diff_hdl: io.TextIOBase) -> None: ...
4+
def __init__(self, diff_hdl: io.BytesIOBase) -> None: ...
55
def markup_to_pager(stream: Any, opts: Any) -> None: ...

0 commit comments

Comments
 (0)