Commit ef9021de authored by Guilhem Saurel's avatar Guilhem Saurel
Browse files

[Tests] Add a ServerManager util

Otherwise, if a test fails, an exception is raised, and `process.kill()`
is never called.
parent 4f62f50e
......@@ -82,6 +82,7 @@ SET(${PROJECT_NAME}_PYTHON_FILES
rbprmfullbody.py
rbprmstate.py
state_alg.py
utils.py
)
SET(${PROJECT_NAME}_PYTHON_TOOLS
......
# Copyright (c) 2020, CNRS
# Authors: Guilhem Saurel <guilhem.saurel@laas.fr>
import subprocess
import time
class ServerManager:
"""A context to ensure a server is running."""
def __init__(self, server):
self.server = server
subprocess.run(['killall', self.server])
def __enter__(self):
self.process = subprocess.Popen(self.server)
# give it some time to start
time.sleep(3)
def __exit__(self, exc_type, exc_value, exc_traceback):
self.process.kill()
# Copyright (c) 2020, CNRS
# Authors: Pierre Fernbach <pfernbac@laas.fr>
import unittest
import subprocess
import time
from hpp.corbaserver.rbprm.rbprmstate import State, StateHelper
from hpp.corbaserver.rbprm.hyq import Robot
from hpp.corbaserver.rbprm.rbprmstate import State, StateHelper
from hpp.corbaserver.rbprm.utils import ServerManager
class TestRBPRMstate3D(unittest.TestCase):
def test_contacts_3d(self):
subprocess.run(["killall", "hpp-rbprm-server"])
process = subprocess.Popen("hpp-rbprm-server")
time.sleep(3)
with ServerManager('hpp-rbprm-server'):
fullbody = Robot()
fullbody.client.robot.setDimensionExtraConfigSpace(6)
fullbody.setJointBounds("root_joint", [-10, 10, -10, 10, -10, 10])
......@@ -52,8 +51,6 @@ class TestRBPRMstate3D(unittest.TestCase):
p_real, n_real = state2.getCenterOfContactForLimb(fullbody.rLegId)
self.assertEqual(n, n_real)
process.kill()
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2020, CNRS
# Authors: Pierre Fernbach <pfernbac@laas.fr>
import unittest
import subprocess
import time
from hpp.corbaserver.rbprm.rbprmstate import State, StateHelper
from talos_rbprm.talos import Robot
from hpp.corbaserver.rbprm.utils import ServerManager
class TestRBPRMstate6D(unittest.TestCase):
def test_contacts_6d(self):
subprocess.run(["killall", "hpp-rbprm-server"])
process = subprocess.Popen("hpp-rbprm-server")
time.sleep(3)
with ServerManager('hpp-rbprm-server'):
fullbody = Robot()
fullbody.client.robot.setDimensionExtraConfigSpace(6)
fullbody.setJointBounds("root_joint", [-10, 10, -10, 10, -10, 10])
......@@ -57,7 +56,7 @@ class TestRBPRMstate6D(unittest.TestCase):
self.assertTrue(state3.isLimbInContact(fullbody.lLegId))
self.assertTrue(state3.isBalanced())
## try com projection:
# try com projection:
com_target = com[::]
com_target[2] -= 0.08
success = state.projectToCOM(com_target)
......@@ -92,8 +91,6 @@ class TestRBPRMstate6D(unittest.TestCase):
for i in range(4):
self.assertAlmostEqual(rf_pose[i + 3], rot[i], 3)
process.kill()
if __name__ == '__main__':
unittest.main()
# Copyright (c) 2020, CNRS
# Authors: Pierre Fernbach <pfernbac@laas.fr>
import subprocess
from importlib import import_module
import unittest
import time
from importlib import import_module
from hpp.corbaserver.rbprm.utils import ServerManager
PATH = "hpp.corbaserver.rbprm.scenarios.demos"
class TestTalosWalkContact(unittest.TestCase):
def test_talos_walk_contacts(self):
subprocess.run(["killall", "hpp-rbprm-server"])
process = subprocess.Popen("hpp-rbprm-server")
time.sleep(3)
with ServerManager('hpp-rbprm-server'):
module_scenario = import_module(PATH + ".talos_flatGround")
if not hasattr(module_scenario, 'ContactGenerator'):
self.assertTrue(False)
......@@ -23,7 +21,6 @@ class TestTalosWalkContact(unittest.TestCase):
self.assertTrue(len(cg.configs) < 10)
self.assertEqual(cg.q_init, cg.configs[0])
self.assertEqual(cg.q_goal, cg.configs[-1])
process.kill()
if __name__ == '__main__':
......
# Copyright (c) 2020, CNRS
# Authors: Pierre Fernbach <pfernbac@laas.fr>
import subprocess
from importlib import import_module
import os
import unittest
import time
from importlib import import_module
from hpp.corbaserver.rbprm.utils import ServerManager
PATH = "hpp.corbaserver.rbprm.scenarios.demos"
class TestTalosWalkPath(unittest.TestCase):
def test_talos_walk_path(self):
subprocess.run(["killall", "hpp-rbprm-server"])
process = subprocess.Popen("hpp-rbprm-server")
time.sleep(3)
with ServerManager('hpp-rbprm-server'):
module_scenario = import_module(PATH + ".talos_flatGround_path")
if not hasattr(module_scenario, 'PathPlanner'):
self.assertTrue(False)
......@@ -27,7 +25,6 @@ class TestTalosWalkPath(unittest.TestCase):
self.assertTrue(ps.pathLength(1) < 7.)
self.assertEqual(planner.q_init, ps.configAtParam(1, 0))
self.assertEqual(planner.q_goal, ps.configAtParam(1, ps.pathLength(1)))
process.kill()
if __name__ == '__main__':
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment