test_hand_calibration.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Copyright 2020 Shadow Robot Company Ltd.
4 #
5 # This program is free software: you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation version 2 of the License.
8 #
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 # more details.
13 #
14 # You should have received a copy of the GNU General Public License along
15 # with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 # This file contains an alternate approach to pedal connection, that falls victim to Ubuntu suspending USB devices.
18 # Try as I might, I couldn't make Ubuntu leave it alone, so switched to the input events approach seen in
19 # sr_triple_pedal.py. I'll leave this here in case it might be useful later.
20 
21 import sys
22 import os
23 import rospy
24 import rospkg
25 import unittest
26 import rostest
27 import tempfile
28 from mock import patch
29 
30 from sr_gui_hand_calibration.sr_hand_calibration_model import HandCalibration
31 
32 from PyQt5.uic import loadUi
33 from PyQt5.QtWidgets import QWidget, QApplication
34 
35 NAME = "test_hand_calibration"
36 PKG = "sr_gui_hand_calibration"
37 
38 
39 class TestHandCalibration(unittest.TestCase):
40 
41  def setUp(self):
42  self.app = QApplication(sys.argv)
43  self._widget = QWidget()
44  ui_file = os.path.join(rospkg.RosPack().get_path('sr_gui_hand_calibration'), 'uis', 'SrHandCalibration.ui')
45  loadUi(ui_file, self._widget)
46 
47  self.mock_file = tempfile.NamedTemporaryFile(delete=False)
48  self.mock_file.write("""sr_calibrations: [\n""" +
49  """["mock", [[0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0], [0.0, 0.0]]],\n""" +
50  """]""")
51  self.mock_file.write("""\n\nsr_calibrations_coupled: [\n""" +
52  """[["mock_1", "mock_2"], [[[0.0, 0.0], 0.0, 0.0]]],\n""" +
53  """]""")
54  self.mock_file.close()
55 
56  def tearDown(self):
57  os.remove(self.mock_file.name)
58 
59  @patch('sr_gui_hand_calibration.sr_hand_calibration_model.EtherCAT_Hand_Lib')
60  def test_progress_bar(self, EtherCAT_Hand_Lib):
61  self.hand_model = HandCalibration(tree_widget=self._widget.tree_calibration,
62  progress_bar=self._widget.progress)
63 
64  self.assertEquals(self.hand_model.progress_bar.value(), 0)
65  self.hand_model.load(self.mock_file.name)
66  self.assertEquals(self.hand_model.progress_bar.value(), 100)
67 
68 if __name__ == "__main__":
69  rospy.init_node("test_hand_calibration")
70  rostest.rosrun(PKG, NAME, TestHandCalibration)
def test_progress_bar(self, EtherCAT_Hand_Lib)


sr_gui_hand_calibration
Author(s): Ugo Cupcic
autogenerated on Wed Oct 14 2020 03:22:44