Skip to content
This repository was archived by the owner on Apr 13, 2021. It is now read-only.

Commit b5f5919

Browse files
committed
Add unit tests for NavMsg
1 parent 9fafd97 commit b5f5919

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

python/swiftnav/nav_msg.pyx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ cdef class NavMsg:
3232
self._thisptr = d
3333

3434
def __reduce__(self):
35-
return (rebuild_NavMsg, tuple([tuple(self.to_dict().items())]))
35+
return (rebuild_NavMsg, tuple(self.to_dict().items()))
3636

3737
def update(self, bit_val):
3838
return nav_msg_update(&self._thisptr, bit_val)
@@ -46,7 +46,7 @@ cdef class NavMsg:
4646

4747
def __richcmp__(self, other, op):
4848
"""
49-
Weird Cython comparison method. See
49+
Weird Cython comparison method. See
5050
http://docs.cython.org/src/userguide/special_methods.html.
5151
"""
5252
if op == 2:
@@ -73,13 +73,13 @@ cdef class NavMsg:
7373
"""
7474
if self.to_dict().keys() != other.to_dict().keys():
7575
return False
76-
76+
7777
for k in self.to_dict().keys():
7878
if self.to_dict()[k] != other.to_dict()[k]:
7979
return False
8080

8181
return True
82-
82+
8383

8484
def rebuild_NavMsg(reduced):
8585
"""

python/tests/test_nav_msg.py

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,46 @@ def test_imports():
1515
"""Verify that distributed packages survive setuptools installation.
1616
1717
"""
18-
assert True
18+
assert True
19+
20+
def build_nav_msg():
21+
""" Instantiate NavMsg with known attribute values. """
22+
nm = swiftnav.nav_msg.NavMsg()
23+
nm.from_dict(
24+
{
25+
'bit_polarity': -1,
26+
'frame_words': [[0, 0, 0, 0, 0, 0, 0, 0],
27+
[0, 0, 0, 0, 0, 0, 0, 0],
28+
[0, 0, 0, 0, 0, 0, 0, 0]],
29+
'next_subframe_id': 1,
30+
'overrun': False,
31+
'subframe_bit_index': 0,
32+
'subframe_bits': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
33+
'subframe_start_index': 0
34+
}
35+
)
36+
return nm
37+
38+
def test_instantiate():
39+
nm = swiftnav.nav_msg.NavMsg()
40+
41+
def test_richcmp():
42+
nm_a = build_nav_msg()
43+
nm_b = build_nav_msg()
44+
45+
# Change nm_b's fields slightly.
46+
nm_b_dict = nm_b.to_dict()
47+
nm_b_dict['bit_polarity'] = 1
48+
nm_b.from_dict(nm_b_dict)
49+
50+
assert nm_a == nm_a
51+
assert not(nm_a != nm_a)
52+
assert nm_a != nm_b
53+
assert not(nm_a == nm_b)
54+
55+
def test_rebuild():
56+
nm = build_nav_msg()
57+
58+
rebuild, args = nm.__reduce__()
59+
60+
assert rebuild(args) == nm

0 commit comments

Comments
 (0)