-
Notifications
You must be signed in to change notification settings - Fork 25
add test for testing UserContextWinDisk to ensure it won't get broken #158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ff5afa4
add test for testing UserContextWinDisk to ensure it won't get broken
amgross fedce80
add in windows dependency on win32file if we are windows
amgross 9fdf60f
fix dependency
amgross 7dc99f9
fix bugs in UserContextWinDisk
amgross 6f9e3dc
win32 must exist on windows when running tests
amgross File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| pytest>=4.0.0 | ||
| tox>=3.14.0 | ||
| pywin32; sys_platform == "win32" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| """Tests for UserContextWinDisk on Windows platforms. | ||
|
|
||
| These tests are only run on Windows systems where win32file is available. | ||
| They test the Windows disk/file context for basic LittleFS operations. | ||
| """ | ||
|
|
||
| import pytest | ||
| import sys | ||
|
|
||
| # Only run these tests on Windows with win32file available | ||
| try: | ||
| import win32file | ||
| HAS_WIN32FILE = True | ||
| except ImportError: | ||
| HAS_WIN32FILE = False | ||
|
|
||
| # Import after checking for win32file | ||
| from littlefs import LittleFS | ||
| from littlefs.context import UserContextWinDisk | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| not HAS_WIN32FILE or sys.platform != "win32", | ||
| reason="win32file is required and test must run on Windows" | ||
| ) | ||
| class TestUserContextWinDisk: | ||
| """Test suite for UserContextWinDisk""" | ||
|
|
||
| @pytest.fixture | ||
| def disk_image_path(self, tmp_path): | ||
| """Create a temporary disk image file path""" | ||
| # Create a pre-allocated disk image file (2MB with 0xFF fill) | ||
| image_path = tmp_path / "disk_image.bin" | ||
| with open(image_path, "wb") as f: | ||
| # Create a 2MB disk image (0xFF filled) | ||
| f.write(b"\xff" * (2 * 1024 * 1024)) | ||
| return str(image_path) | ||
|
|
||
| def test_windisk_read_after_remount(self, disk_image_path): | ||
| """Test reading file content after remounting""" | ||
| block_size = 512 | ||
| block_count = 256 | ||
| test_content = "Hello, this is persistent data!" | ||
|
|
||
| ctx = UserContextWinDisk(disk_image_path) | ||
| try: | ||
| fs = LittleFS(context=ctx, block_size=block_size, block_count=block_count) | ||
|
|
||
| # Write file | ||
| with fs.open("persistent.txt", "w") as fh: | ||
| fh.write(test_content) | ||
|
|
||
| fs.unmount() | ||
|
|
||
| # Remount and read | ||
| fs.mount() | ||
| with fs.open("persistent.txt", "r") as fh: | ||
| content = fh.read() | ||
| assert content == test_content | ||
|
|
||
| fs.unmount() | ||
| finally: | ||
| ctx.__del__() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's remove the
HAS_WIN32FILEcheck and just have this only be conditional on if thesys.platformiswin32. I don't think we need to importwin32fileat all within this test and it should all "just work" on all platforms.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done