test_mavexpression.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 
4 """
5 Unit tests for the mavexpression library
6 """
7 
8 from __future__ import print_function
9 import unittest
10 import random
11 
12 from pymavlink import mavexpression
13 
14 class ExpressionTest(unittest.TestCase):
15 
16  """
17  Class to test evaluate_expression
18  """
19 
20  def __init__(self, *args, **kwargs):
21  """Constructor, set up some data that is reused in many tests"""
22  self.varsDict = {}
23  self.varsDict['lat'] = 5.67
24  self.varsDict['speed'] = 8
25  super(ExpressionTest, self).__init__(*args, **kwargs)
26 
27 
28  def test_novars(self):
29  """Test the evaluate_expression functionality"""
30  assert mavexpression.evaluate_expression('1+2', {}) == 3
31  assert mavexpression.evaluate_expression('4/0', {}) is None
32  assert mavexpression.evaluate_expression('A+4', {}) is None
33 
34  def test_vars(self):
35  """Test the evaluate_expression functionality with local vars"""
36  assert mavexpression.evaluate_expression('lat+10', self.varsDict) == 15.67
37  assert mavexpression.evaluate_expression('4.0/speed', self.varsDict) == 0.5
38  assert mavexpression.evaluate_expression('speed+lat+wrong', self.varsDict) is None
39 
40  def test_mavextra(self):
41  """Test evaluate_expression using the functions in mavextra.py"""
42  assert mavexpression.evaluate_expression('kmh(10)', {}) == 36
43  assert mavexpression.evaluate_expression('angle_diff(170, -90)', {}) == -100
44 
45 if __name__ == '__main__':
46  unittest.main()
def __init__(self, args, kwargs)


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