test_fgFDM.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 
4 """
5 Unit tests for the fgFDM library
6 """
7 
8 from __future__ import print_function
9 import unittest
10 
11 from pymavlink.fgFDM import fgFDMError, fgFDMVariable, fgFDMVariableList, fgFDM
12 
13 
14 class fgFDMErrorTest(unittest.TestCase):
15  """
16  Class to test fgFDMError
17  """
18  def __init__(self, *args, **kwargs):
19  """Constructor, set up some data that is reused in many tests"""
20  super(fgFDMErrorTest, self).__init__(*args, **kwargs)
21 
22  def test_constructor(self):
23  ex = fgFDMError("Test Exception {0}".format(1))
24 
25  assert ex.message == "fgFDMError: Test Exception 1"
26 
27 class fgFDMVariableTest(unittest.TestCase):
28  """
29  Class to test fgFDMVariable
30  """
31  def __init__(self, *args, **kwargs):
32  """Constructor, set up some data that is reused in many tests"""
33  super(fgFDMVariableTest, self).__init__(*args, **kwargs)
34 
35  def test_constructor(self):
36  """Test the constructor"""
37  varry = fgFDMVariable(0, 3, 'radians')
38 
39  assert varry.index == 0
40  assert varry.arraylength == 3
41  assert varry.units == 'radians'
42 
43 
44 class fgFDMVariableListTest(unittest.TestCase):
45  """
46  Class to test fgFDMVariableList
47  """
48  def __init__(self, *args, **kwargs):
49  """Constructor, set up some data that is reused in many tests"""
50  super(fgFDMVariableListTest, self).__init__(*args, **kwargs)
51 
52  def test_constructor(self):
53  """Test the constructor and adding variables"""
54  mapping = fgFDMVariableList()
55  mapping.add('longitude', units='radians')
56  mapping.add('stall_warning')
57  mapping.add('rpm', 4)
58 
59  assert mapping._nextidx == 6
60  assert mapping.vars['longitude'].index == 0
61  assert mapping.vars['longitude'].units == 'radians'
62  assert mapping.vars['rpm'].index == 2
63  assert mapping.vars['rpm'].units is None
64 
65 
66 class fgFDMTest(unittest.TestCase):
67  """
68  Class to test fgFDM
69  """
70  def __init__(self, *args, **kwargs):
71  """Constructor, set up some data that is reused in many tests"""
72  super(fgFDMTest, self).__init__(*args, **kwargs)
73 
74  def test_constructor(self):
75  """Test the constructor"""
76  fdm = fgFDM()
77 
78  assert fdm.FG_NET_FDM_VERSION == 24
79 
80  def test_getset(self):
81  """Test the getting and setting and unit conversion of variables"""
82  fdm = fgFDM()
83 
84  fdm.set('latitude', 67.4, units='degrees')
85  fdm.set('longitude', 120.6, units='degrees')
86  fdm.set('num_engines', 1)
87  fdm.set('vcas', 44, units='mps')
88 
89  assert fdm.get('latitude', units='degrees') == 67.4
90  assert round(fdm.get('vcas', units='knots'), 2) == 85.53
91 
92  def test_packparse(self):
93  """Test the packing and parsing of an fgFDM packet"""
94  fdm = fgFDM()
95 
96  fdm.set('latitude', 67.4, units='degrees')
97  fdm.set('longitude', 120.6, units='degrees')
98  fdm.set('num_engines', 1)
99  fdm.set('vcas', 44, units='mps')
100 
101  packedBytes = fdm.pack()
102 
103  parsedObj = fgFDM()
104  parsedObj.parse(packedBytes)
105 
106  assert parsedObj.get('latitude', units='degrees') == 67.4
107  assert round(parsedObj.get('vcas', units='knots'), 2) == 85.53
108 
109 if __name__ == '__main__':
110  unittest.main()
def test_packparse(self)
Definition: test_fgFDM.py:92
def __init__(self, args, kwargs)
Definition: test_fgFDM.py:18
def test_constructor(self)
Definition: test_fgFDM.py:74
def __init__(self, args, kwargs)
Definition: test_fgFDM.py:31
def test_getset(self)
Definition: test_fgFDM.py:80
def __init__(self, args, kwargs)
Definition: test_fgFDM.py:70
def __init__(self, args, kwargs)
Definition: test_fgFDM.py:48


mavlink
Author(s): Lorenz Meier
autogenerated on Sun Apr 7 2019 02:06:02