diff options
| author | Yuval Adam <_@yuv.al> | 2024-05-07 15:44:46 +0200 |
|---|---|---|
| committer | Yuval Adam <_@yuv.al> | 2024-05-07 15:44:46 +0200 |
| commit | c0056b2d9f5175d06b39834b013d16fa5d63a485 (patch) | |
| tree | 6391068bf0738b8e988db8d8e2ebe2c1ccda5396 | |
| parent | 7bb5dc320e12ecdbb6cf514b11306df130e8a24c (diff) | |
Setup pytest and assert stash path
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | README.md | 17 | ||||
| -rw-r--r-- | pyproject.toml | 5 | ||||
| -rw-r--r-- | tests/test_stash.py | 9 | ||||
| -rw-r--r-- | ymlstash/__init__.py | 3 | ||||
| -rw-r--r-- | ymlstash/stash.py | 6 |
6 files changed, 43 insertions, 0 deletions
@@ -1 +1,4 @@ +__pycache__/ +.pytest_cache/ + poetry.lock @@ -5,9 +5,26 @@ A simple ORM-like utility for operating on local YAML files via Python dataclass Define a dataclass: ```python +from dataclasses import dataclass + @dataclass class User: name: str age: int active: bool ``` + +Instantiate a new object: + +```python +user = User(name="yuval", age=42, active=True) +``` + +Save it to file: + +```python +from ymlstash import YmlStash + +stash = YmlStash("path/to/db") +stash.save(user) +``` diff --git a/pyproject.toml b/pyproject.toml index 39965ac..ed4e580 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,12 @@ license = "MIT" python = "^3.8" pyyaml = "^6.0.1" +[tool.poetry.group.dev.dependencies] +pytest = "^8.2.0" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" + +[tool.pytest.ini_options] +testpaths = ["tests"] diff --git a/tests/test_stash.py b/tests/test_stash.py new file mode 100644 index 0000000..b87c882 --- /dev/null +++ b/tests/test_stash.py @@ -0,0 +1,9 @@ +from pathlib import Path +from ymlstash import YmlStash + + +def test_stash_path(): + stash = YmlStash("foo") + assert stash.path == Path("foo") + stash = YmlStash(Path("foo")) + assert stash.path == Path("foo") diff --git a/ymlstash/__init__.py b/ymlstash/__init__.py index e69de29..337b0b1 100644 --- a/ymlstash/__init__.py +++ b/ymlstash/__init__.py @@ -0,0 +1,3 @@ +from .stash import YmlStash + +__all__ = [YmlStash] diff --git a/ymlstash/stash.py b/ymlstash/stash.py new file mode 100644 index 0000000..f2839ef --- /dev/null +++ b/ymlstash/stash.py @@ -0,0 +1,6 @@ +from pathlib import Path + + +class YmlStash: + def __init__(self, path): + self.path = Path(path) |
