Skip to content

Commit

Permalink
Add tests for improved JSON state parsing #6
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenbe committed May 18, 2024
1 parent 1647a27 commit bb1ec91
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/state_store_test.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit bb1ec91

Please sign in to comment.