public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/util/file_copy/
@ 2023-05-26 15:45 Sam James
  0 siblings, 0 replies; 2+ messages in thread
From: Sam James @ 2023-05-26 15:45 UTC (permalink / raw
  To: gentoo-commits

commit:     c472d08dd0c41e55fbea74805768a82b095db07b
Author:     David Palao <david.palao <AT> gmail <DOT> com>
AuthorDate: Fri May  5 13:25:50 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri May 26 15:44:36 2023 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=c472d08d

tests: file_copy: port testCopyFileSparse to pytest

Signed-off-by: David Palao <david.palao <AT> gmail.com>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/portage/tests/util/file_copy/test_copyfile.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lib/portage/tests/util/file_copy/test_copyfile.py b/lib/portage/tests/util/file_copy/test_copyfile.py
index 55bdeec66..6e5ae9571 100644
--- a/lib/portage/tests/util/file_copy/test_copyfile.py
+++ b/lib/portage/tests/util/file_copy/test_copyfile.py
@@ -1,9 +1,11 @@
-# Copyright 2017 Gentoo Foundation
+# Copyright 2017, 2023 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 import shutil
 import tempfile
 
+import pytest
+
 from portage import os
 from portage.tests import TestCase
 from portage.checksum import perform_md5
@@ -56,10 +58,12 @@ class CopyFileSparseTestCase(TestCase):
             # This last part of the test is expected to fail when sparse
             # copy is not implemented, so set the todo flag in order
             # to tolerate failures.
-            self.todo = True
+            ## self.todo = True
 
             # If sparse blocks were preserved, then both files should
             # consume the same number of blocks.
+
+            pytest.xfail(reason="sparse copy is not implemented")
             self.assertEqual(os.stat(src_path).st_blocks, os.stat(dest_path).st_blocks)
         finally:
             shutil.rmtree(tempdir)


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [gentoo-commits] proj/portage:master commit in: lib/portage/tests/util/file_copy/
@ 2024-03-15 20:06 Mike Gilbert
  0 siblings, 0 replies; 2+ messages in thread
From: Mike Gilbert @ 2024-03-15 20:06 UTC (permalink / raw
  To: gentoo-commits

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)


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-15 20:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-26 15:45 [gentoo-commits] proj/portage:master commit in: lib/portage/tests/util/file_copy/ Sam James
  -- strict thread matches above, loose matches on Subject: below --
2024-03-15 20:06 Mike Gilbert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox