summaryrefslogtreecommitdiff
path: root/tests/test_stash.py
blob: defdd7ed67592b6a50caea7d1a9176d601a1bde3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from pathlib import Path
from ymlstash import YmlStash
from dataclasses import dataclass


@dataclass
class User:
    name: str
    age: int


def test_stash_path():
    stash = YmlStash(User, "foo")
    assert stash.path == Path("foo")
    stash = YmlStash(User, Path("foo"))
    assert stash.path == Path("foo")


def test_stash():
    stash = YmlStash(User, "/tmp/")
    yuval = User(name="yuval", age=42)
    stash.save("foo", yuval)
    assert stash.list_all_keys() == ["foo"]
    obj = stash.load("foo")
    assert obj == yuval
    stash.drop()
    assert stash.list_all_keys() == []