Fix file utilities and add basic tests#4960
Conversation
There was a problem hiding this comment.
Pull Request Overview
This pull request fixes file utilities in the NVNMD module and adds basic regression tests. The changes address a bug in path checking logic and improve the robustness of text file handling methods.
- Fixes a critical bug in
Fio.get_file_listwhereself.is_pathwas called without arguments - Improves documentation and parameter handling in
FioDicandFioTxtclasses - Adds comprehensive test coverage for the fixed file utility functions
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
deepmd/tf/nvnmd/utils/fio.py |
Fixes get_file_list path check bug and improves text file utility methods with better documentation and default parameter handling |
source/tests/tf/test_fio_utils.py |
Adds new test file with regression tests for Fio.get_file_list and FioTxt.load methods |
doc/model/train-fitting-tensor.md |
Corrects grammar in error message documentation from "mismatch it's name" to "mismatches its name" |
Comments suppressed due to low confidence (1)
deepmd/tf/nvnmd/utils/fio.py:204
- The parameter type annotation
list | str | Nonelacks specificity for the list type. Consider usinglist[str] | str | Noneto clearly indicate that the list should contain strings, which matches the function's behavior of converting strings to lists and adding newlines.
def save(self, file_name: str = "", data: list | str | None = None) -> None:
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughUpdates Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant Fio
participant FS as FileSystem
rect rgba(230,240,255,0.5)
note over Caller,Fio: Fio.get_file_list(path)
Caller->>Fio: get_file_list(path)
Fio->>Fio: is_path(path)?
alt path exists and is dir
Fio->>FS: listdir(path) / recurse
FS-->>Fio: entries
Fio-->>Caller: [file paths]
else path missing or not dir
Fio-->>Caller: []
end
end
sequenceDiagram
autonumber
actor Caller
participant FioTxt
participant FS as FileSystem
rect rgba(235,255,235,0.5)
note over Caller,FioTxt: FioTxt.load(file_name, default_value=None)
Caller->>FioTxt: load(file_name, None)
FioTxt->>FioTxt: default_value := []
FioTxt->>FS: exists(file_name)?
alt file exists
FS-->>FioTxt: open/read lines
FioTxt-->>Caller: [lines]
else missing
FioTxt-->>Caller: []
end
end
rect rgba(255,245,230,0.5)
note over Caller,FioTxt: FioTxt.save(file_name, data)
Caller->>FioTxt: save(file_name, list | str | None)
FioTxt->>FioTxt: normalize to list of strings with \\n
FioTxt->>FS: write lines
FS-->>FioTxt: ok
FioTxt-->>Caller: None/return
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes 📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (3)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## devel #4960 +/- ##
==========================================
+ Coverage 84.29% 84.81% +0.52%
==========================================
Files 704 705 +1
Lines 68875 74498 +5623
Branches 3572 3573 +1
==========================================
+ Hits 58057 63187 +5130
- Misses 9678 10170 +492
- Partials 1140 1141 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Summary
Fio.get_file_listpath check and improve text file helpersTesting
pre-commit run --files doc/model/train-fitting-tensor.md deepmd/tf/nvnmd/utils/fio.py source/tests/tf/test_fio_utils.pyPYTHONPATH=$PWD pytest source/tests/tf/test_fio_utils.py(fails: ModuleNotFoundError: No module named 'deepmd.about')https://chatgpt.com/codex/tasks/task_e_68b3566011908323bb35035b903814f0
Summary by CodeRabbit