Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/littlefs/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,13 @@ def add_command(handler, name="", help=""):

return parser


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.
def main(argv=None):
if argv is None:
argv = sys.argv
parser = get_parser()
parser.parse_known_args(sys.argv[1:]) # Allows for ``littlefs-python --version``
args = parser.parse_args(sys.argv[1:])
parser.parse_known_args(argv[1:]) # Allows for ``littlefs-python --version``
args = parser.parse_args(argv[1:])
return args.func(parser, args)


Expand Down
49 changes: 49 additions & 0 deletions test/cli/test_create_and_extract.py
Original file line number Diff line number Diff line change
@@ -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.
import filecmp

from littlefs.__main__ import main


def test_create_and_extract(tmp_path):
"""Test creating a filesystem image and extracting it."""
# Create test directory with files
source_dir = tmp_path / "source"
source_dir.mkdir()
(source_dir / "file1.txt").write_text("hello world")
(source_dir / "subdir").mkdir()
(source_dir / "subdir" / "file2.txt").write_text("test content")

# Create filesystem image
image_file = tmp_path / "test_image.bin"
create_argv = [
"littlefs",
"create",
str(source_dir),
str(image_file),
"--block-size", "512",
"--fs-size", "64KB",
]
assert main(create_argv) == 0
assert image_file.exists()

# Extract filesystem image
extract_dir = tmp_path / "extracted"
extract_argv = [
"littlefs",
"extract",
str(image_file),
str(extract_dir),
"--block-size", "512",
]
assert main(extract_argv) == 0
assert extract_dir.exists()

# Compare directories
comparison = filecmp.dircmp(source_dir, extract_dir)
assert not comparison.diff_files
assert not comparison.left_only
assert not comparison.right_only
Comment on lines +41 to +45
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.

# Verify file contents
assert (extract_dir / "file1.txt").read_text() == "hello world"
assert (extract_dir / "subdir" / "file2.txt").read_text() == "test content"
File renamed without changes.
Loading