From f7419ff06edf5cee8219c6620608429ce505e32c Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 21 May 2025 15:17:43 +0200 Subject: [PATCH] tests: test_sparse_file, save space on TMPDIR --- src/borg/testsuite/archiver/extract_cmd_test.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/borg/testsuite/archiver/extract_cmd_test.py b/src/borg/testsuite/archiver/extract_cmd_test.py index cd8f5d070..79c27214d 100644 --- a/src/borg/testsuite/archiver/extract_cmd_test.py +++ b/src/borg/testsuite/archiver/extract_cmd_test.py @@ -204,11 +204,11 @@ def test_sparse_file(archivers, request): sparse = False return sparse - filename = os.path.join(archiver.input_path, "sparse") + filename_in = os.path.join(archiver.input_path, "sparse") content = b"foobar" hole_size = 5 * (1 << CHUNK_MAX_EXP) # 5 full chunker buffers total_size = hole_size + len(content) + hole_size - with open(filename, "wb") as fd: + with open(filename_in, "wb") as fd: # create a file that has a hole at the beginning and end (if the # OS and filesystem supports sparse files) fd.seek(hole_size, 1) @@ -217,7 +217,7 @@ def test_sparse_file(archivers, request): pos = fd.tell() fd.truncate(pos) # we first check if we could create a sparse input file: - sparse_support = is_sparse(filename, total_size, hole_size) + sparse_support = is_sparse(filename_in, total_size, hole_size) if sparse_support: # we could create a sparse input file, so creating a backup of it and # extracting it again (as sparse) should also work: @@ -226,13 +226,15 @@ def test_sparse_file(archivers, request): with changedir(archiver.output_path): cmd(archiver, "extract", "test", "--sparse") assert_dirs_equal("input", "output/input") - filename = os.path.join(archiver.output_path, "input", "sparse") - with open(filename, "rb") as fd: + filename_out = os.path.join(archiver.output_path, "input", "sparse") + with open(filename_out, "rb") as fd: # check if file contents are as expected assert fd.read(hole_size) == b"\0" * hole_size assert fd.read(len(content)) == content assert fd.read(hole_size) == b"\0" * hole_size - assert is_sparse(filename, total_size, hole_size) + assert is_sparse(filename_out, total_size, hole_size) + os.unlink(filename_out) # save space on TMPDIR + os.unlink(filename_in) # save space on TMPDIR def test_unusual_filenames(archivers, request):