From 4c18061049c70c2691be8e15fd961b88dba38a6e Mon Sep 17 00:00:00 2001 From: R1kaB3rN <100738684+R1kaB3rN@users.noreply.github.com> Date: Fri, 1 Mar 2024 10:46:56 -0800 Subject: [PATCH] ulwgl_test: update copy tests --- ULWGL/ulwgl_test.py | 91 ++------------------------------------------- 1 file changed, 4 insertions(+), 87 deletions(-) diff --git a/ULWGL/ulwgl_test.py b/ULWGL/ulwgl_test.py index d5f4d6087..75602feed 100644 --- a/ULWGL/ulwgl_test.py +++ b/ULWGL/ulwgl_test.py @@ -12,7 +12,6 @@ import tarfile import ulwgl_util import hashlib -import errno import json @@ -798,7 +797,7 @@ def test_copy_tree_link(self): result = ulwgl_util.copyfile_tree(test_dir, self.test_local_share) # Confirm the state of the dest dir - self.assertTrue(result, "Expected False after calling copyfile_tree") + self.assertFalse(result, "Expected None after calling copyfile_tree") self.assertTrue( any(self.test_local_share.iterdir()), "Expected destination dir to not be empty", @@ -841,7 +840,7 @@ def test_copy_tree(self): result = ulwgl_util.copyfile_tree(test_dir, self.test_local_share) # Confirm the state of the dest dir - self.assertTrue(result, "Expected False after calling copyfile_tree") + self.assertFalse(result, "Expected None after calling copyfile_tree") self.assertTrue( any(self.test_local_share.iterdir()), "Expected destination dir to not be empty", @@ -858,94 +857,12 @@ def test_copy_tree(self): test_dir.joinpath("ULWGL_VERSION.json").unlink() test_dir.rmdir() - def test_copy_err(self): - """Test copyfile_reflink for error. - - An OSError is expected to be raised if the error number is not: EXDEV, ENOSYS, EINVAL - """ - self.assertTrue( - self.test_user_share.joinpath("ULWGL_VERSION.json").exists(), - "Expected ULWGL_VERSION.json to exist in test /usr/share/ULWGL", - ) - - with patch("os.copy_file_range") as mock_function: - # Mock the OS error that is not EXDEV ENOSYS EINVAL - # We want to fallback to normal copy - mock_function.side_effect = OSError(errno.EPERM, "") - - with self.assertRaisesRegex(OSError, "Errno 1"): - ulwgl_util.copyfile_reflink( - self.test_user_share.joinpath("ULWGL_VERSION.json"), - self.test_local_share.joinpath("ULWGL_VERSION.json"), - ) - - def test_copy_fallback(self): - """Test copyfile_reflink in the case of error. - - For systems that do not support copy_file_range, we fallback to normal copy - """ - result = None - src = b"" - dst = b"" - - self.assertTrue( - self.test_user_share.joinpath("ULWGL_VERSION.json").exists(), - "Expected ULWGL_VERSION.json to exist in test /usr/share/ULWGL", - ) - self.assertFalse( - self.test_local_share.joinpath("ULWGL_VERSION.json").exists(), - "Expected ULWGL_VERSION.json to not exist in test .local/share/ULWGL", - ) - - with patch("os.copy_file_range") as mock_function: - # Mock the OS error - # We want to fallback to normal copy - mock_function.side_effect = OSError(errno.ENOSYS, "") - - # Copy ULWGL_VERSION.json to the mocked .local/share/ULWGL - result = ulwgl_util.copyfile_reflink( - self.test_user_share.joinpath("ULWGL_VERSION.json"), - self.test_local_share.joinpath("ULWGL_VERSION.json"), - ) - - self.assertFalse(result, "Expected None when calling copyfile_reflink") - self.assertTrue( - self.test_local_share.joinpath("ULWGL_VERSION.json").exists(), - "Expected ULWGL_VERSION.json to be copied to local share", - ) - - # Verify the integrity of data and metadata - with self.test_user_share.joinpath("ULWGL_VERSION.json").open( - mode="rb" - ) as file: - src = file.read() - - with self.test_local_share.joinpath("ULWGL_VERSION.json").open( - mode="rb" - ) as file: - dst = file.read() - - self.assertEqual( - hashlib.blake2b(src).digest(), - hashlib.blake2b(dst).digest(), - "Expected the same files", - ) - self.assertEqual( - self.test_user_share.joinpath("ULWGL_VERSION.json").stat().st_mode, - self.test_local_share.joinpath("ULWGL_VERSION.json").stat().st_mode, - "Expected metadata to be equal", - ) def test_copy(self): """Test copyfile_reflink. - If the filesystem supports reflink, we try to create a shallow copy of files. Otherwise, we fallback to normal copy - An error should not be raised in the process of copying a source file to a destination - The test assumes that there is only one filesystem on the host. - However, in the real usage, it's possible for the root partition filesystem to be different than the home partition (e.g. Steam Deck) - - NOTE: We do not test if the file is a shallow copy as it's not easily verifiable through Python and depends on the user's system - Therefore, when running the test locally, most likely only one branch is effectively tested + An error should not be raised when copying a file + A subset of metadata as well as the integrity of the file data are verified """ result = None src = b""