test_mavparm.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python
  2. """
  3. Unit tests for the mavparm library
  4. """
  5. from __future__ import print_function
  6. import unittest
  7. import os
  8. from pymavlink import mavparm
  9. class MAVParmDictTest(unittest.TestCase):
  10. """
  11. Class to test MAVParmDict
  12. """
  13. def __init__(self, *args, **kwargs):
  14. """Constructor, set up some data that is reused in many tests"""
  15. self.parms = mavparm.MAVParmDict()
  16. self.parms['AFS_ACTION'] = 42
  17. self.parms['PARAM1'] = 34.45
  18. self.parms['PARAM2'] = 0
  19. self.parms['PARAM3'] = -13.4
  20. super(MAVParmDictTest, self).__init__(*args, **kwargs)
  21. def test_dict(self):
  22. """Test simple dict operations"""
  23. self.parms['AFS_ACTION'] = 34
  24. assert self.parms['AFS_ACTION'] == 34
  25. assert self.parms['PARAM1'] == 34.45
  26. def test_saveload(self):
  27. """Test the saving and loading to file"""
  28. self.parms.save('prms.txt')
  29. assert os.path.isfile('prms.txt')
  30. newparms = mavparm.MAVParmDict()
  31. newparms.load('prms.txt')
  32. os.remove('prms.txt')
  33. assert newparms['AFS_ACTION'] == self.parms['AFS_ACTION']
  34. assert newparms['PARAM3'] == self.parms['PARAM3']
  35. def test_showdiff(self):
  36. """Test show and diff functions"""
  37. self.parms.save('prms.txt')
  38. self.parms.show()
  39. self.parms.diff('prms.txt')
  40. if __name__ == '__main__':
  41. unittest.main()