Test loading wrong saves
This commit is contained in:
@ -4,6 +4,8 @@
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from squirrelbattle.resources import ResourceManager
|
||||
|
||||
from squirrelbattle.enums import DisplayActions
|
||||
|
||||
from squirrelbattle.bootstrap import Bootstrap
|
||||
@ -43,6 +45,27 @@ class TestGame(unittest.TestCase):
|
||||
new_state = self.game.save_state()
|
||||
self.assertEqual(old_state, new_state)
|
||||
|
||||
# Error on loading save
|
||||
with open(ResourceManager.get_config_path("save.json"), "w") as f:
|
||||
f.write("I am not a JSON file")
|
||||
self.assertIsNone(self.game.message)
|
||||
self.game.load_game()
|
||||
self.assertIsNotNone(self.game.message)
|
||||
self.game.message = None
|
||||
|
||||
with open(ResourceManager.get_config_path("save.json"), "w") as f:
|
||||
f.write("{}")
|
||||
self.assertIsNone(self.game.message)
|
||||
self.game.load_game()
|
||||
self.assertIsNotNone(self.game.message)
|
||||
self.game.message = None
|
||||
|
||||
# Load game with a dead player
|
||||
self.game.map.remove_entity(self.game.player)
|
||||
self.game.save_game()
|
||||
self.game.load_game()
|
||||
self.assertIsNotNone(self.game.message)
|
||||
|
||||
def test_bootstrap_fail(self) -> None:
|
||||
"""
|
||||
Ensure that the test can't play the game,
|
||||
|
Reference in New Issue
Block a user