From c0056b2d9f5175d06b39834b013d16fa5d63a485 Mon Sep 17 00:00:00 2001 From: Yuval Adam <_@yuv.al> Date: Tue, 7 May 2024 15:44:46 +0200 Subject: Setup pytest and assert stash path --- .gitignore | 3 +++ README.md | 17 +++++++++++++++++ pyproject.toml | 5 +++++ tests/test_stash.py | 9 +++++++++ ymlstash/__init__.py | 3 +++ ymlstash/stash.py | 6 ++++++ 6 files changed, 43 insertions(+) create mode 100644 tests/test_stash.py create mode 100644 ymlstash/stash.py diff --git a/.gitignore b/.gitignore index c04bc49..323ded3 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ +__pycache__/ +.pytest_cache/ + poetry.lock diff --git a/README.md b/README.md index e289a88..ee3df48 100644 --- a/README.md +++ b/README.md @@ -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) -- cgit v1.3.1