54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
from untitled import content, model, persistence
|
|
|
|
|
|
def test_save_load_roundtrip(tmp_path):
|
|
original = model.Save(
|
|
version=content.SAVE_VERSION,
|
|
cat=model.Cat(
|
|
"Fry",
|
|
{
|
|
"size": "tiny",
|
|
"color": "tuxedo",
|
|
"eyes": "blue",
|
|
"personality": "judges you silently",
|
|
},
|
|
),
|
|
)
|
|
persistence.save(original, tmp_path)
|
|
loaded = persistence.load("Fry", tmp_path)
|
|
assert loaded.cat.name == "Fry"
|
|
assert loaded.cat.traits == {
|
|
"size": "tiny",
|
|
"color": "tuxedo",
|
|
"eyes": "blue",
|
|
"personality": "judges you silently",
|
|
}
|
|
assert loaded.version == content.SAVE_VERSION
|
|
|
|
|
|
def test_migration(tmp_path):
|
|
cat = model.Save(
|
|
version=1,
|
|
cat=model.Cat(
|
|
"Fry",
|
|
{
|
|
"size": "tiny",
|
|
"color": "tuxedo",
|
|
"eyes": "blue",
|
|
"personality": "judges you silently",
|
|
},
|
|
),
|
|
)
|
|
persistence.save(cat, tmp_path)
|
|
loaded = persistence.load("Fry", tmp_path)
|
|
assert loaded.cat.fullness
|
|
assert loaded.cat.last_updated
|
|
|
|
|
|
def test_list_saves(tmp_path):
|
|
open(tmp_path / "test.kitten", "w").close()
|
|
open(tmp_path / "test2.kitten", "w").close()
|
|
saves = persistence.list_saves(tmp_path)
|
|
assert "test" in saves
|
|
assert "test2" in saves
|