From aa181a564fe6f8beaf7b968cf3e6194b18c378b0 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 24 Mar 2025 19:50:54 -0700 Subject: [PATCH] storage: tests: Fix a test failure for psutils >= 7.0 - We are using a private data structure that lead to failure. psutil 7.0 removed two fields from the partition class. Just update the code to work with 7.0 instead of emulating psutil completely as that is a better test. - The primary code is unaffected in is_partition_read_only() and get_filesystem_type() due to not having any changes in the fields we use. Tests: - Run unit tests on testing and unstable VMs. Signed-off-by: Sunil Mohan Adapa --- plinth/modules/storage/tests/test_storage.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/plinth/modules/storage/tests/test_storage.py b/plinth/modules/storage/tests/test_storage.py index 2ad7fbf33..fcce70101 100644 --- a/plinth/modules/storage/tests/test_storage.py +++ b/plinth/modules/storage/tests/test_storage.py @@ -375,7 +375,16 @@ def test_validate_directory_creatable(path, error): @patch('psutil.disk_partitions') def test_is_partition_read_only(disk_partitions): """Test whether checking for ro partition works.""" - partition = psutil._common.sdiskpart # pylint: disable=protected-access + + def partition(*args): + try: + # psutil <= 5.9.8 + # pylint: disable=protected-access + return psutil._common.sdiskpart(*args) + except TypeError: + # psutil >= 7.0 + return psutil._common.sdiskpart(*args[:-2]) + disk_partitions.return_value = [ partition('/dev/root', '/', 'btrfs', 'rw,nosuid', 42, 42), partition('/dev/root', '/foo', 'btrfs', 'rw', 321, 321),