From bb1ec912821e3d385ffb881e2d90cabb0645999a Mon Sep 17 00:00:00 2001 From: Ruben Vandamme Date: Sat, 18 May 2024 11:59:38 +0000 Subject: [PATCH] Add tests for improved JSON state parsing #6 --- tests/state_store_test.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/state_store_test.py diff --git a/tests/state_store_test.py b/tests/state_store_test.py new file mode 100644 index 0000000..bb72b63 --- /dev/null +++ b/tests/state_store_test.py @@ -0,0 +1,34 @@ +import unittest +import comfospot40 + +from pathlib import Path + + +class TestStateLoad(unittest.TestCase): + def test_empty_file(self): + state = comfospot40.State(60, False) + state_default = comfospot40.State(60, False) + hal = comfospot40.Hal(state, 60) + with open( + Path(__file__).parent / "state_store_test/empty.json", "r" + ) as storefile: + hal.loadState(storefile, state) + self.assertEqual(state, state_default) + + def test_broken_file(self): + state = comfospot40.State(60, False) + state_default = comfospot40.State(60, False) + hal = comfospot40.Hal(state, 60) + with open( + Path(__file__).parent / "state_store_test/broken.json", "r" + ) as storefile: + hal.loadState(storefile, state) + self.assertEqual(state, state_default) + + def test_v2_file(self): + state = comfospot40.State(60, False) + state_default = comfospot40.State(60, False) + hal = comfospot40.Hal(state, 60) + with open(Path(__file__).parent / "state_store_test/v2.json", "r") as storefile: + hal.loadState(storefile, state) + self.assertEqual(state, state_default)