Keep only rsync's summary lines when not verbose
Every output line was kept in memory although only the last two were logged, and fewer than two lines (e.g. with --rsync-options q) raised an IndexError.
This commit is contained in:
+14
-1
@@ -298,12 +298,13 @@ class FakePopen:
|
||||
|
||||
returncode = 0
|
||||
calls: list[list[str]] = []
|
||||
output = b'sending incremental file list\nsent 1 bytes received 2 bytes\ntotal size is 3\n'
|
||||
|
||||
def __init__(self, args: list[str], **kwargs: Any) -> None:
|
||||
FakePopen.calls.append(args)
|
||||
os.makedirs(args[args.index('/') + 1])
|
||||
self.stdin = io.BytesIO()
|
||||
self.stdout = io.BytesIO(b'sending incremental file list\nsent 1 bytes received 2 bytes\ntotal size is 3\n')
|
||||
self.stdout = io.BytesIO(FakePopen.output)
|
||||
|
||||
def __enter__(self) -> 'FakePopen':
|
||||
return self
|
||||
@@ -343,6 +344,18 @@ class TestReturnCodes:
|
||||
assert f'--link-dest={out}/simple_backup/{old_backups[-1]}' in args
|
||||
assert args[args.index('/') + 1] == f'{out}/simple_backup/2026-10-14_10-00-00'
|
||||
|
||||
@pytest.mark.parametrize('lines, logged', [
|
||||
([f'file{n}' for n in range(5)] + ['sent 1 bytes', 'total size is 3'], ['sent 1 bytes', 'total size is 3']),
|
||||
([], []),
|
||||
(['total size is 3'], ['total size is 3']),
|
||||
])
|
||||
def test_summary_logged(self, src: Path, out: Path, fake_popen: type[FakePopen], monkeypatch: pytest.MonkeyPatch,
|
||||
caplog: pytest.LogCaptureFixture, lines: list[str], logged: list[str]) -> None:
|
||||
monkeypatch.setattr(fake_popen, 'output', ''.join(f'{line}\n' for line in lines).encode())
|
||||
|
||||
assert run_backup(out, [str(src)]) == 0
|
||||
assert [m[7:] for m in caplog.messages if m.startswith('rsync: ')] == logged
|
||||
|
||||
def test_rsync_missing(self, src: Path, out: Path, tmp_path: Path, fake_popen: type[FakePopen],
|
||||
old_backups: list[str], monkeypatch: pytest.MonkeyPatch,
|
||||
caplog: pytest.LogCaptureFixture) -> None:
|
||||
|
||||
Reference in New Issue
Block a user