def test_sparse_copy(self): with ExitStack() as resources: tmpdir = resources.enter_context(TemporaryDirectory()) sparse_file = os.path.join(tmpdir, 'sparse.dat') fp = resources.enter_context(open(sparse_file, 'w')) os.truncate(fp.fileno(), 1000000) # This file is sparse. self.assertTrue(is_sparse(sparse_file)) copied_file = os.path.join(tmpdir, 'copied.dat') sparse_copy(sparse_file, copied_file) self.assertTrue(is_sparse(copied_file))
def test_copy_symlink(self): with ExitStack() as resources: tmpdir = resources.enter_context(TemporaryDirectory()) sparse_file = os.path.join(tmpdir, 'sparse.dat') fp = resources.enter_context(open(sparse_file, 'w')) os.truncate(fp.fileno(), 1000000) # This file is sparse. self.assertTrue(is_sparse(sparse_file)) # Create a symlink to the sparse file. linked_file = os.path.join(tmpdir, 'linked.dat') os.symlink(sparse_file, linked_file) self.assertTrue(os.path.islink(linked_file)) copied_link = os.path.join(tmpdir, 'copied.dat') sparse_copy(linked_file, copied_link, follow_symlinks=False) self.assertTrue(os.path.islink(copied_link))