summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Adam <_@yuv.al>2024-05-07 15:44:46 +0200
committerYuval Adam <_@yuv.al>2024-05-07 15:44:46 +0200
commitc0056b2d9f5175d06b39834b013d16fa5d63a485 (patch)
tree6391068bf0738b8e988db8d8e2ebe2c1ccda5396
parent7bb5dc320e12ecdbb6cf514b11306df130e8a24c (diff)
Setup pytest and assert stash path
-rw-r--r--.gitignore3
-rw-r--r--README.md17
-rw-r--r--pyproject.toml5
-rw-r--r--tests/test_stash.py9
-rw-r--r--ymlstash/__init__.py3
-rw-r--r--ymlstash/stash.py6
6 files changed, 43 insertions, 0 deletions
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)