Пример #1
0
def test_wait_for_services():
    c = CapabilitiesClient()
    with assert_raises(ValueError):
        c.wait_for_services(0.1, ['invalid_service'])
    assert c.wait_for_services(0.1) is False
    c.establish_bond(0.1)
    c._used_capabilities.add('some_pkg/SomeCap')
    c.free_capability('some_pkg/SomeCap', 0.1)
Пример #2
0
 def test_client_module(self):
     c = CapabilitiesClient()
     c.wait_for_services(3)
     c.use_capability('minimal_pkg/Minimal', 'minimal_pkg/minimal')
     c.use_capability('minimal_pkg/Minimal', 'minimal_pkg/minimal')
     c.free_capability('minimal_pkg/Minimal')
     with self.assertRaises(CapabilityNotRunningException):
         c.free_capability('not_a_pkg/NotACap')
     c.shutdown()
Пример #3
0
 def test_use_and_free_dependent_capability(self):
     c = CapabilitiesClient()
     c.wait_for_services(timeout=3.0)
     # Use a cap with dependencies and wait for it to be running
     c.use_capability('navigation_capability/Navigation', 'navigation_capability/faux_navigation')
     expected = ['navigation_capability/Navigation', 'differential_mobile_base_capability/DifferentialMobileBase']
     result = wait_for_result_to_happen(expected, [])
     assert sorted(result) == sorted(expected), (sorted(result), sorted(expected))
     # Use its dependency and free its dependency, assert it is still there
     c.use_capability('differential_mobile_base_capability/DifferentialMobileBase', 'differential_mobile_base_capability/faux_differential_mobile_base')
     c.free_capability('differential_mobile_base_capability/DifferentialMobileBase')
     expected = []
     result = wait_for_result_to_happen(expected, ['navigation_capability/Navigation', 'differential_mobile_base_capability/DifferentialMobileBase'], tries=5)
     assert sorted(result) != sorted(expected), (sorted(result), sorted(expected))
     # Free it and assert it goes down
     c.free_capability('navigation_capability/Navigation')
     expected = []
     result = wait_for_result_to_happen(expected, ['navigation_capability/Navigation', 'differential_mobile_base_capability/DifferentialMobileBase'])
     assert sorted(result) == sorted(expected), (sorted(result), sorted(expected))
Пример #4
0
 def test_use_and_free_capability(self):
     assert wait_for_capability_server(10)
     c = CapabilitiesClient()
     c.wait_for_services(timeout=3.0)
     # Give invalid bond id to use_capability
     with assert_raises(ServiceException):
         call_service('/capability_server/use_capability', 'minimal_pkg/Minimal', '', 'invalid_bond_id')
     # Try to use a non-existent cap
     with assert_raises(ServiceException):
         c.use_capability('not_a_pkg/NotACap')
     # Use cap and wait for it to be running
     c.use_capability('minimal_pkg/Minimal', 'minimal_pkg/minimal')
     expected = ['minimal_pkg/Minimal']
     result = wait_for_result_to_happen(expected, [])
     assert sorted(result) == sorted(expected), (sorted(result), sorted(expected))
     # Try to use it with a different provider
     with assert_raises(ServiceException):
         c.use_capability('minimal_pkg/Minimal', 'minimal_pkg/specific_minimal')
     # Use it a second time, free it once, assert it is stil there
     c.use_capability('minimal_pkg/Minimal')
     c.free_capability('minimal_pkg/Minimal')
     expected = []
     result = wait_for_result_to_happen(expected, ['minimal_pkg/Minimal'], tries=5)
     assert sorted(result) != sorted(expected), (sorted(result), sorted(expected))
     # Directly call ~free_capability with an invalid bond_id
     with assert_raises(ServiceException):
         call_service('/capability_server/free_capability', 'minimal_pkg/Minimal', 'invalid_bond_id')
     # Free it again and assert it goes down
     c.free_capability('minimal_pkg/Minimal')
     expected = []
     result = wait_for_result_to_happen(expected, ['minimal_pkg/Minimal'])
     assert sorted(result) == sorted(expected), (sorted(result), sorted(expected))
     # Try to over free it and get an exception
     with assert_raises(CapabilityNotRunningException):
         c.free_capability('minimal_pkg/Minimal')
     # Use it again, then break the bond and assert it goes down because of that
     c.use_capability('minimal_pkg/Minimal')
     expected = ['minimal_pkg/Minimal']
     result = wait_for_result_to_happen(expected, [])
     assert sorted(result) == sorted(expected), (sorted(result), sorted(expected))
     c._bond.break_bond()
     expected = []
     result = wait_for_result_to_happen(expected, ['minimal_pkg/Minimal'])
     assert sorted(result) == sorted(expected), (sorted(result), sorted(expected))
Пример #5
0
 def test_use_and_free_capability(self):
     assert wait_for_capability_server(10)
     c = CapabilitiesClient()
     c.wait_for_services(timeout=3.0)
     # Give invalid bond id to use_capability
     with assert_raises(ServiceException):
         call_service('/capability_server/use_capability',
                      'minimal_pkg/Minimal', '', 'invalid_bond_id')
     # Try to use a non-existent cap
     with assert_raises(ServiceException):
         c.use_capability('not_a_pkg/NotACap')
     # Use cap and wait for it to be running
     c.use_capability('minimal_pkg/Minimal', 'minimal_pkg/minimal')
     expected = ['minimal_pkg/Minimal']
     result = wait_for_result_to_happen(expected, [])
     assert sorted(result) == sorted(expected), (sorted(result),
                                                 sorted(expected))
     # Try to use it with a different provider
     with assert_raises(ServiceException):
         c.use_capability('minimal_pkg/Minimal',
                          'minimal_pkg/specific_minimal')
     # Use it a second time, free it once, assert it is stil there
     c.use_capability('minimal_pkg/Minimal')
     c.free_capability('minimal_pkg/Minimal')
     expected = []
     result = wait_for_result_to_happen(expected, ['minimal_pkg/Minimal'],
                                        tries=5)
     assert sorted(result) != sorted(expected), (sorted(result),
                                                 sorted(expected))
     # Directly call ~free_capability with an invalid bond_id
     with assert_raises(ServiceException):
         call_service('/capability_server/free_capability',
                      'minimal_pkg/Minimal', 'invalid_bond_id')
     # Free it again and assert it goes down
     c.free_capability('minimal_pkg/Minimal')
     expected = []
     result = wait_for_result_to_happen(expected, ['minimal_pkg/Minimal'])
     assert sorted(result) == sorted(expected), (sorted(result),
                                                 sorted(expected))
     # Try to over free it and get an exception
     with assert_raises(ServiceException):
         c.free_capability('minimal_pkg/Minimal')
     # Use it again, then break the bond and assert it goes down because of that
     c.use_capability('minimal_pkg/Minimal')
     expected = ['minimal_pkg/Minimal']
     result = wait_for_result_to_happen(expected, [])
     assert sorted(result) == sorted(expected), (sorted(result),
                                                 sorted(expected))
     c._bond.break_bond()
     expected = []
     result = wait_for_result_to_happen(expected, ['minimal_pkg/Minimal'])
     assert sorted(result) == sorted(expected), (sorted(result),
                                                 sorted(expected))
 def test_client_module(self):
     c = CapabilitiesClient()
     c.wait_for_services(3)
     c.use_capability('minimal_pkg/Minimal', 'minimal_pkg/minimal')
     c.use_capability('minimal_pkg/Minimal', 'minimal_pkg/minimal')
     c.free_capability('minimal_pkg/Minimal')
     c.free_capability('not_a_pkg/NotACap')
     c.shutdown()
 def test_client_module(self):
     c = CapabilitiesClient()
     c.wait_for_services(3)
     c.use_capability('minimal_pkg/Minimal', 'minimal_pkg/minimal')
     c.use_capability('minimal_pkg/Minimal', 'minimal_pkg/minimal')
     c.free_capability('minimal_pkg/Minimal')
     c.free_capability('not_a_pkg/NotACap')
     c.shutdown()