Skip to content

Commit 658bb30

Browse files
committed
add a unit test for pickling and unpickling databases
since `Database` does not provide a comparison operator, we compare the `repr()` strings of the fresh and the unpickled database. thanks to [at]kayoub5 for suggesting this. Signed-off-by: Andreas Lauser <[email protected]>
1 parent 4704f74 commit 658bb30

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/test_pickle_db.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# SPDX-License-Identifier: MIT
2+
import pickle
3+
import unittest
4+
5+
from odxtools.loadfile import load_pdx_file
6+
7+
8+
class TestPickleDatabase(unittest.TestCase):
9+
10+
def test_state_chart(self) -> None:
11+
fresh_db = load_pdx_file("./examples/somersault.pdx")
12+
pickled_db = pickle.dumps(fresh_db)
13+
unpickled_db = pickle.loads(pickled_db)
14+
15+
self.assertEqual(repr(fresh_db), repr(unpickled_db))
16+
17+
18+
if __name__ == "__main__":
19+
unittest.main()

0 commit comments

Comments
 (0)