Skip to content

test(tools): comprehensive test suite for file_operations module (+51 tests) - #167

Open
manus-use wants to merge 1 commit into
mainfrom
test/file-operations
Open

test(tools): comprehensive test suite for file_operations module (+51 tests)#167
manus-use wants to merge 1 commit into
mainfrom
test/file-operations

Conversation

@manus-use

Copy link
Copy Markdown
Owner

Summary

Comprehensive test suite for the file_operations module (src/manus_agent/tools/file_operations.py), which provides five core file utility functions used throughout the agent.

Test Coverage

file_read — 10 tests

  • Text file reading (normal, multiline, empty, unicode, large 100KB)
  • Binary file fallback (returns hex representation)
  • Error handling: FileNotFoundError, ValueError for directories
  • Tilde expansion, spaces in filenames

file_write — 9 tests

  • Create new file, overwrite existing
  • Nested parent directory creation (create_dirs=True)
  • Error path when create_dirs=False with missing parent
  • Empty/unicode/multiline content
  • Tilde expansion, return message validation

file_list — 9 tests

  • Empty directory, mixed files+dirs
  • Glob patterns (*.py), recursive glob (**/*.py)
  • Error handling: missing directory, not-a-directory
  • Hidden files included, relative paths returned
  • Default "." directory argument

file_delete — 7 tests

  • File deletion, empty directory removal
  • Recursive directory deletion (force=True)
  • Non-empty directory without force raises error
  • Nonexistent path raises FileNotFoundError
  • Symlink behavior documentation (resolve follows target)
  • Sibling file preservation

file_move — 9 tests

  • Basic move, rename in same directory
  • Cross-directory move, auto-create parent dirs
  • Overwrite existing destination
  • FileExistsError when destination exists without overwrite
  • FileNotFoundError for missing source
  • Directory move, message validation

Integration — 7 tests

  • Write→read round trip
  • Write→list verification
  • Write→move→read pipeline
  • Write→delete→verify gone
  • List after delete
  • Move→read original fails
  • Write nested→list with pattern

Technical Notes

  • All tests use tmp_path fixtures (pytest-managed temp directories)
  • No real filesystem side effects outside of isolated temp dirs
  • Tests document actual behavior (e.g., resolve() follows symlinks before delete)
  • 51 tests total, all passing

Files Changed

  • tests/test_file_operations.py — new test file (51 tests)

… tests)

Add tests for all five utility functions in file_operations.py:

file_read (10 tests):
- Text/binary/empty/unicode/large file reading
- Tilde expansion, spaces in filenames
- FileNotFoundError, ValueError for directories

file_write (9 tests):
- Create new, overwrite existing, nested dir creation
- create_dirs=False error path, empty/unicode/multiline content
- Tilde expansion, return message validation

file_list (9 tests):
- Empty dir, files+dirs, glob patterns, recursive glob
- Missing dir, not-a-dir, hidden files, relative paths
- Default directory argument

file_delete (7 tests):
- Files, empty dirs, recursive (force=True)
- Non-empty without force, nonexistent path
- Symlink behavior (resolve follows target), sibling preservation

file_move (9 tests):
- Basic move, rename, cross-directory
- Parent dir creation, overwrite, existing dest no overwrite
- Missing source, directory move, message validation

Integration (7 tests):
- Write→read round trip, write→list, write→move→read
- Write→delete→verify gone, list after delete
- Move→read original fails, write nested→list pattern

All tests use tmp_path fixtures — no real filesystem side effects.
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.

1 participant