Skip to content

Commit fea4669

Browse files
authored
Add a test for non-utf8 (#2)
1 parent 4e86cdd commit fea4669

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

rsync_time_machine.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,15 @@ def run_cmd(
363363
shell=True,
364364
capture_output=True,
365365
text=True,
366+
errors="surrogateescape",
366367
)
367368
else:
368369
result = subprocess.run(
369370
cmd,
370371
shell=True,
371372
capture_output=True,
372373
text=True,
374+
errors="surrogateescape",
373375
)
374376
if VERBOSE:
375377
if result.stdout:

tests/test_app.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,3 +430,48 @@ def test_backup(tmp_path: Path, capsys: pytest.CaptureFixture) -> None:
430430
assert not (dest_folder / "latest" / "file2.txt").exists()
431431
assert (dest_folder / "latest" / "file3.txt").exists()
432432
assert_n_backups(dest_folder, 2)
433+
434+
435+
def test_backup_with_non_utf8_filename(tmp_path: Path) -> None:
436+
"""Test the backup function with a non-UTF8 filename.
437+
438+
Reproduces https://github.com/basnijholt/rsync-time-machine.py/issues/1
439+
"""
440+
src_folder = tmp_path / "src"
441+
dest_folder = tmp_path / "dest"
442+
src_folder.mkdir()
443+
dest_folder.mkdir()
444+
445+
# Create a folder and file with a non-UTF8 filename
446+
folder = "TEST-UTF8"
447+
(src_folder / folder).mkdir()
448+
non_utf8_filename = "Mîso.rtf"
449+
(src_folder / folder / non_utf8_filename).write_text("Hello, World!")
450+
451+
kw = {
452+
"src_folder": str(src_folder),
453+
"dest_folder": str(dest_folder),
454+
"exclusion_file": "",
455+
"log_dir": str(tmp_path / "logs"),
456+
"auto_delete_log": True,
457+
"expiration_strategy": "1:1",
458+
"auto_expire": True,
459+
"port": "22",
460+
"id_rsa": "",
461+
"rsync_set_flags": "",
462+
"rsync_append_flags": "",
463+
"rsync_get_flags": False,
464+
"allow_host_only": False,
465+
}
466+
467+
# Create a backup.marker file
468+
Path(backup_marker_path(str(dest_folder))).touch()
469+
470+
# Run the backup
471+
backup(**kw) # type: ignore[arg-type]
472+
473+
# Check that the backup was created
474+
assert (dest_folder / "latest" / folder / non_utf8_filename).exists()
475+
assert (
476+
dest_folder / "latest" / folder / non_utf8_filename
477+
).read_text() == "Hello, World!"

0 commit comments

Comments
 (0)