public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Mike Gilbert" <floppym@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/tests/util/file_copy/
Date: Fri, 15 Mar 2024 20:06:47 +0000 (UTC)	[thread overview]
Message-ID: <1710533134.0cc3f9e269b26173c2f81d731c5fe208b758270b.floppym@gentoo> (raw)

commit:     0cc3f9e269b26173c2f81d731c5fe208b758270b
Author:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
AuthorDate: Sun Mar  3 02:28:42 2024 +0000
Commit:     Mike Gilbert <floppym <AT> gentoo <DOT> org>
CommitDate: Fri Mar 15 20:05:34 2024 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=0cc3f9e2

Improve testCopyFileSparse

Actually create sparse blocks at the start and end.
Check file size before/after copying.
Ensure sparse output when _fastcopy succeeds.

Signed-off-by: Mike Gilbert <floppym <AT> gentoo.org>

 lib/portage/tests/util/file_copy/test_copyfile.py | 35 ++++++++++++++++-------
 1 file changed, 24 insertions(+), 11 deletions(-)

diff --git a/lib/portage/tests/util/file_copy/test_copyfile.py b/lib/portage/tests/util/file_copy/test_copyfile.py
index e91a47bed8..e114e6ae35 100644
--- a/lib/portage/tests/util/file_copy/test_copyfile.py
+++ b/lib/portage/tests/util/file_copy/test_copyfile.py
@@ -3,13 +3,14 @@
 
 import shutil
 import tempfile
+from unittest.mock import patch
 
 import pytest
 
 from portage import os
 from portage.tests import TestCase
 from portage.checksum import perform_md5
-from portage.util.file_copy import copyfile
+from portage.util.file_copy import copyfile, _fastcopy
 
 
 class CopyFileTestCase(TestCase):
@@ -42,25 +43,37 @@ class CopyFileSparseTestCase(TestCase):
             # files too big, in case the filesystem doesn't support
             # sparse files.
             with open(src_path, "wb") as f:
+                f.seek(2**16, os.SEEK_SET)
                 f.write(content)
-                f.seek(2**17, 1)
-                f.write(content)
-                f.seek(2**18, 1)
+                f.seek(2**17, os.SEEK_SET)
                 f.write(content)
                 # Test that sparse blocks are handled correctly at
-                # the end of the file (involves seek and truncate).
-                f.seek(2**17, 1)
+                # the end of the file.
+                f.truncate(2**18)
 
-            copyfile(src_path, dest_path)
+            fastcopy_success = False
+
+            def mock_fastcopy(src, dst):
+                nonlocal fastcopy_success
+                _fastcopy(src, dst)
+                fastcopy_success = True
+
+            with patch("portage.util.file_copy._fastcopy", new=mock_fastcopy):
+                copyfile(src_path, dest_path)
 
             self.assertEqual(perform_md5(src_path), perform_md5(dest_path))
 
-            # This last part of the test is expected to fail when sparse
-            # copy is not implemented, so mark it xfail:
-            pytest.xfail(reason="sparse copy is not implemented")
+            src_stat = os.stat(src_path)
+            dest_stat = os.stat(dest_path)
+
+            self.assertEqual(src_stat.st_size, dest_stat.st_size)
 
             # If sparse blocks were preserved, then both files should
             # consume the same number of blocks.
-            self.assertEqual(os.stat(src_path).st_blocks, os.stat(dest_path).st_blocks)
+            # This is expected to fail when sparse copy is not implemented.
+            if src_stat.st_blocks != dest_stat.st_blocks:
+                if fastcopy_success:
+                    pytest.fail(reason="sparse copy failed with _fastcopy")
+                pytest.xfail(reason="sparse copy is not implemented")
         finally:
             shutil.rmtree(tempdir)


             reply	other threads:[~2024-03-15 20:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-15 20:06 Mike Gilbert [this message]
  -- strict thread matches above, loose matches on Subject: below --
2023-05-26 15:45 [gentoo-commits] proj/portage:master commit in: lib/portage/tests/util/file_copy/ Sam James

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1710533134.0cc3f9e269b26173c2f81d731c5fe208b758270b.floppym@gentoo \
    --to=floppym@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox