From 41967f351d07a12be3341f7f57e5273fb129ddec Mon Sep 17 00:00:00 2001 From: Adam Tyson Date: Fri, 15 Dec 2023 12:24:27 +0000 Subject: [PATCH] Fix test on Windows --- tests/tests/test_general/test_system.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/tests/test_general/test_system.py b/tests/tests/test_general/test_system.py index 34f7167..2aa878f 100644 --- a/tests/tests/test_general/test_system.py +++ b/tests/tests/test_general/test_system.py @@ -2,7 +2,7 @@ import random from pathlib import Path from random import shuffle -from unittest.mock import Mock, patch +from unittest.mock import MagicMock, Mock, patch import pytest @@ -43,10 +43,21 @@ def mock_disk_usage(): @pytest.fixture def mock_statvfs(): """Fixture to mock os.statvfs.""" - mock_stats = Mock() - mock_stats.f_frsize = 1024 # Fragment size - mock_stats.f_bavail = 1000 # Free blocks - return mock_stats + f_frsize = 1024 + f_bavail = 1000 + if not hasattr(os, "statvfs"): + # Windows doesn't have statvfs, so we need to mock it + mocked_statvfs = MagicMock() + mocked_statvfs.return_value = MagicMock( + f_frsize=f_frsize, f_bavail=f_bavail + ) + + else: + # Linux/macOS has statvfs so only the values need to be set + mocked_statvfs = Mock() + mocked_statvfs.f_frsize = f_frsize # Fragment size + mocked_statvfs.f_bavail = f_bavail # Free blocks + return mocked_statvfs def test_replace_extension():