Log verbose rsync output one line per message
With -v, the whole output was logged as a single Python list.
This commit is contained in:
+13
-2
@@ -56,9 +56,9 @@ def out(tmp_path: Path) -> Path:
|
||||
|
||||
|
||||
def make_backup(out: Path, inputs: list[str], keep: int = -1, exclude: list[str] | None = None,
|
||||
remove_before: bool = False, progress: bool = False) -> sb.Backup:
|
||||
remove_before: bool = False, progress: bool = False, verbose: bool = False) -> sb.Backup:
|
||||
backup = sb.Backup(inputs, str(out), exclude or [], keep, OPTIONS, remove_before=remove_before,
|
||||
progress=progress)
|
||||
progress=progress, verbose=verbose)
|
||||
|
||||
assert backup.check_params() == 0
|
||||
|
||||
@@ -356,6 +356,17 @@ class TestReturnCodes:
|
||||
assert run_backup(out, [str(src)]) == 0
|
||||
assert [m[7:] for m in caplog.messages if m.startswith('rsync: ')] == logged
|
||||
|
||||
@pytest.mark.parametrize('returncode, level', [(0, 'INFO'), (23, 'WARNING'), (1, 'ERROR')])
|
||||
def test_verbose_one_line_per_message(self, src: Path, out: Path, fake_popen: type[FakePopen],
|
||||
caplog: pytest.LogCaptureFixture, returncode: int, level: str) -> None:
|
||||
fake_popen.returncode = returncode
|
||||
|
||||
run_backup(out, [str(src)], verbose=True)
|
||||
|
||||
rsync = [(r.levelname, r.getMessage()) for r in caplog.records if r.getMessage().startswith('rsync: ')]
|
||||
lines = ['sending incremental file list', 'sent 1 bytes received 2 bytes', 'total size is 3']
|
||||
assert rsync == [(level, f'rsync: {line}') for line in lines]
|
||||
|
||||
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