|
| 1 | +"""Tests for UserContextWinDisk on Windows platforms. |
| 2 | +
|
| 3 | +These tests are only run on Windows systems where win32file is available. |
| 4 | +They test the Windows disk/file context for basic LittleFS operations. |
| 5 | +""" |
| 6 | + |
| 7 | +import pytest |
| 8 | +import sys |
| 9 | + |
| 10 | +# Only run these tests on Windows |
| 11 | +if sys.platform == "win32": |
| 12 | + import win32file |
| 13 | + |
| 14 | +# Import after checking for win32file |
| 15 | +from littlefs import LittleFS |
| 16 | +from littlefs.context import UserContextWinDisk |
| 17 | + |
| 18 | + |
| 19 | +@pytest.mark.skipif( |
| 20 | + sys.platform != "win32", |
| 21 | + reason="test must run on Windows" |
| 22 | +) |
| 23 | +class TestUserContextWinDisk: |
| 24 | + """Test suite for UserContextWinDisk""" |
| 25 | + |
| 26 | + @pytest.fixture |
| 27 | + def disk_image_path(self, tmp_path): |
| 28 | + """Create a temporary disk image file path""" |
| 29 | + # Create a pre-allocated disk image file (2MB with 0xFF fill) |
| 30 | + image_path = tmp_path / "disk_image.bin" |
| 31 | + with open(image_path, "wb") as f: |
| 32 | + # Create a 2MB disk image (0xFF filled) |
| 33 | + f.write(b"\xff" * (2 * 1024 * 1024)) |
| 34 | + return str(image_path) |
| 35 | + |
| 36 | + def test_windisk_read_after_remount(self, disk_image_path): |
| 37 | + """Test reading file content after remounting""" |
| 38 | + block_size = 512 |
| 39 | + block_count = 256 |
| 40 | + test_content = "Hello, this is persistent data!" |
| 41 | + |
| 42 | + ctx = UserContextWinDisk(disk_image_path) |
| 43 | + try: |
| 44 | + fs = LittleFS(context=ctx, block_size=block_size, block_count=block_count) |
| 45 | + |
| 46 | + # Write file |
| 47 | + with fs.open("persistent.txt", "w") as fh: |
| 48 | + fh.write(test_content) |
| 49 | + |
| 50 | + fs.unmount() |
| 51 | + |
| 52 | + # Remount and read |
| 53 | + fs.mount() |
| 54 | + with fs.open("persistent.txt", "r") as fh: |
| 55 | + content = fh.read() |
| 56 | + assert content == test_content |
| 57 | + |
| 58 | + fs.unmount() |
| 59 | + finally: |
| 60 | + ctx.__del__() |
0 commit comments