-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for improved JSON state parsing #6
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |