import pytest from untitled import content, migration, model, persistence, rules 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(): v1 = { "version": 1, "cat": { "name": "Fry", "traits": { "size": "tiny", "color": "tuxedo", "eyes": "blue", "personality": "judges you silently", }, }, } result = migration.migrate(v1) assert result["version"] == content.SAVE_VERSION assert result["cat"]["fullness"] == 100 assert "last_updated" in result["cat"] def test_decay_and_replenish(): cat = model.Save( version=content.SAVE_VERSION, cat=model.Cat( "Fry", { "size": "tiny", "color": "tuxedo", "eyes": "blue", "personality": "judges you silently", }, last_updated=0, ), ) rules.reconcile(cat.cat, 3600 * 2) assert cat.cat.happiness < 98 assert cat.cat.fullness < 98 rules.feed(cat.cat) assert cat.cat.fullness == pytest.approx(100) rules.reconcile(cat.cat, 7200 + 20 * 3600) assert cat.cat.happiness < 96 - (content.BASE_HAPPINESS_DECAY_PER_HOUR * 20) 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