https://github.com/wdhongtw/minidir
Minimal abstraction about directories and files
https://github.com/wdhongtw/minidir
filesystem python testing
Last synced: 5 months ago
JSON representation
Minimal abstraction about directories and files
- Host: GitHub
- URL: https://github.com/wdhongtw/minidir
- Owner: wdhongtw
- Created: 2022-10-14T17:43:44.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-07T03:14:01.000Z (about 2 years ago)
- Last Synced: 2025-09-28T14:17:17.886Z (9 months ago)
- Topics: filesystem, python, testing
- Language: Python
- Homepage: https://pypi.org/project/minidir/
- Size: 16.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# minidir: Minimal directory interface and implementation
The minimal interface for directories and files and
two implementations: in-memory and real file system versions.
It's a good choice when we want to separate file-access side effects from
pure functional part of our code base.
## Installation
Already published on Pypi
```shell
pip install minidir
```
## Usage
- Interface: `Directory` -> `Path`, `File`
- `Directory` is the container where we access `File` by `Path`
- Implementation
- `SystemDirectory`: a `Directory` backed by real file system.
- `FakeDirectory`: a `Directory` only exists in-memory.
Some error like `NameCollision` and `NotFound` will be raised in corresponding situations.
Example:
```python
import minidir
class SomeClass:
folder: minidir.Directory
def __init__(self, folder: minidir.Directory) -> None:
# inject directory to separate side effect from core logic
pass
def main():
# use actual file system during production
instance = SomeClass(minidir.SystemDirectory("/path/to/root"))
def test_some_class():
# use in-memory implementation during test
instance = SomeClass(minidir.FakeDirectory())
```
## Future Work
- Implementations for network-oriented storage, e.g. WebDAV, S3, Dropbox ...
- Stream based file read / write interface.