Skip to content

Conversation

@amgross
Copy link
Contributor

@amgross amgross commented Jan 12, 2026

Added easy option to test CLI from python (it may be used also by users).
This is first step for changes we planned to do in #150 , to have good option to test it.

@BrianPugh
Copy link
Collaborator

thank you!

@BrianPugh BrianPugh merged commit a697539 into jrast:master Jan 12, 2026
25 checks passed
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds the ability to test the CLI from Python by making the main() function accept an optional argv parameter. This enables programmatic testing of CLI commands, which is particularly useful for automated testing.

Changes:

  • Modified main() function to accept an optional argv parameter (defaults to sys.argv if not provided)
  • Added comprehensive tests for the _walk_all utility function
  • Added integration test for create and extract CLI commands

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/littlefs/main.py Modified main() to accept optional argv parameter for testability
test/cli/test_walk_all.py Added unit tests for _walk_all function covering basic traversal, symlinks, empty directories, and nested structures
test/cli/test_create_and_extract.py Added integration test for create and extract CLI commands with directory comparison

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +41 to +45
# Compare directories
comparison = filecmp.dircmp(source_dir, extract_dir)
assert not comparison.diff_files
assert not comparison.left_only
assert not comparison.right_only
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filecmp.dircmp comparison only performs a shallow comparison and doesn't recursively check subdirectories. This means that differences in files within subdirectories (like "subdir/file2.txt") may not be caught by the assertions on diff_files, left_only, and right_only. While the explicit file content checks on lines 47-49 will catch this specific case, consider using filecmp.dircmp recursively or using a recursive comparison function to make the test more robust and comprehensive.

Copilot uses AI. Check for mistakes.


def main():
# Getting argv optionally from the caller to enable call from python (generally for testing, but could be used for other purposes)
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment should start with a capital letter and use proper sentence structure. Consider revising to: "Getting argv optionally from the caller to enable calls from Python (generally for testing, but could be used for other purposes)."

Suggested change
# Getting argv optionally from the caller to enable call from python (generally for testing, but could be used for other purposes)
# Getting argv optionally from the caller to enable calls from Python (generally for testing, but could be used for other purposes).

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,49 @@
from pathlib import Path
Copy link

Copilot AI Jan 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'Path' is not used.

Suggested change
from pathlib import Path

Copilot uses AI. Check for mistakes.
@BrianPugh
Copy link
Collaborator

@amgross you can determine what's valuable/not from copilot and follow it up in your next PR (no need to separate it from the feature you are working on). At somepoint I need to setup Ruff for this repo to catch things like unused imports. Maybe i'll revisit that once your feature is complete!

@amgross
Copy link
Contributor Author

amgross commented Jan 13, 2026

Great REPO
Thank you very much for the fast responses 😃
I will try to remember to remove this import

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants