Ejemplo n.º 1
0
def test_load_duplicate_names_multi_package():
    workspaces = [os.path.join(test_data_dir, 'duplicate_names_multi_package')]
    package_index = package_index_from_package_path(workspaces)
    spec_file_index = spec_file_index_from_package_index(package_index)
    spec_index, errors = spec_index_from_spec_file_index(spec_file_index)
    error_types = [type(x) for x in errors]
    assert discovery.DuplicateNameException in error_types, error_types
Ejemplo n.º 2
0
 def test_launch_manager_quiet(self):
     with redirected_stdio():
         workspaces = [
             os.path.join(TEST_DIR, 'unit', 'discovery_workspaces',
                          'minimal')
         ]
         package_index = package_index_from_package_path(workspaces)
         spec_file_index = spec_file_index_from_package_index(package_index)
         spec_index, errors = spec_index_from_spec_file_index(
             spec_file_index)
         assert not errors, errors
         provider = 'minimal_pkg/minimal'
         assert provider in spec_index.providers
         lm = launch_manager.LaunchManager()
         lm._LaunchManager__quiet = True
         lm.run_capability_provider(spec_index.providers[provider],
                                    spec_index.provider_paths[provider])
         with assert_raises_regex(RuntimeError, 'is already running'):
             lm.run_capability_provider(spec_index.providers[provider],
                                        spec_index.provider_paths[provider])
         with assert_raises_regex(RuntimeError,
                                  'No running launch file with PID of'):
             lm._LaunchManager__stop_by_pid(-1)
         time.sleep(1)  # Allow time for output to be produced
         lm.stop()
Ejemplo n.º 3
0
def test_load_duplicate_names_semantic():
    print('Testing duplicate_names_semantic workspace')
    workspaces = [os.path.join(test_data_dir, 'duplicate_names_semantic')]
    package_index = package_index_from_package_path(workspaces)
    spec_file_index = spec_file_index_from_package_index(package_index)
    spec_index, errors = spec_index_from_spec_file_index(spec_file_index)
    error_types = [type(x) for x in errors]
    assert discovery.DuplicateNameException in error_types, error_types
Ejemplo n.º 4
0
def test_load_minimal():
    workspaces = [os.path.join(test_data_dir, 'minimal')]
    package_index = package_index_from_package_path(workspaces)
    spec_file_index = spec_file_index_from_package_index(package_index)
    spec_index, errors = spec_index_from_spec_file_index(spec_file_index)
    assert not errors
    expected = sorted(['Minimal', 'minimal', 'SpecificMinimal', 'specific_minimal'])
    assert sorted(spec_index.specs.keys()) == expected
    assert spec_index.get_containing_package_name('Minimal') == 'minimal_pkg'
    with assert_raises(RuntimeError):
        spec_index.get_containing_package_name('NotASpecName')
    assert sorted(spec_index.provider_names) == ['minimal', 'specific_minimal']
 def test_launch_manager_no_launch_file_provider(self):
     with redirected_stdio():
         workspaces = [os.path.join(THIS_DIR, 'no_launch_file')]
         package_index = package_index_from_package_path(workspaces)
         spec_file_index = spec_file_index_from_package_index(package_index)
         spec_index, errors = spec_index_from_spec_file_index(spec_file_index)
         assert not errors, errors
         provider = 'minimal_pkg/minimal'
         assert provider in spec_index.providers
         lm = launch_manager.LaunchManager()
         lm._LaunchManager__quiet = True
         lm.run_capability_provider(spec_index.providers[provider], spec_index.provider_paths[provider])
         time.sleep(1)  # Allow time for output to be produced
         lm.stop()
Ejemplo n.º 6
0
 def __load_capabilities(self):
     package_index = package_index_from_package_path(self.__package_paths)
     self.spec_file_index = spec_file_index_from_package_index(
         package_index)
     # Prune packages by black and white list
     for package in self.spec_file_index.keys():
         if self.__package_whitelist and package not in self.__package_whitelist:
             rospy.loginfo(
                 "Package '{0}' not in whitelist, skipping.".format(
                     package))
             del self.spec_file_index[package]
         if self.__package_blacklist and package in self.__package_blacklist:
             rospy.loginfo(
                 "Package '{0}' in blacklist, skipping.".format(package))
             del self.spec_file_index[package]
     # Generate spec_index from spec file index
     spec_index, errors = spec_index_from_spec_file_index(
         self.spec_file_index)
     if errors:
         rospy.logerr("Errors were encountered loading capabilities:")
         for error in errors:
             rospy.logerr("  " + str(error.__class__.__name__) + ": " +
                          str(error))
     # Prune specific capabilities based on black and white lists
     removed_interfaces = []
     for specs, remove_func in [
         (spec_index.interfaces, spec_index.remove_interface),
         (spec_index.semantic_interfaces,
          spec_index.remove_semantic_interface),
         (spec_index.providers, spec_index.remove_provider)
     ]:
         for spec in specs.keys():
             if self.__whitelist and spec not in self.__whitelist:
                 removed_interfaces.append(spec)
                 remove_func(spec)
                 rospy.loginfo(
                     "Spec '{0}' is not in the whitelist, skipping.".format(
                         spec))
             if self.__blacklist and spec in self.__blacklist:
                 removed_interfaces.append(spec)
                 remove_func(spec)
                 rospy.loginfo(
                     "Spec '{0}' is in the blacklist, skipping.".format(
                         spec))
     # Remove providers which no longer have an interface
     for interface in removed_interfaces:
         for provider in spec_index.providers.values():
             if provider.implements == interface:
                 spec_index.remove_provider(provider.name)
     self.__spec_index = spec_index
Ejemplo n.º 7
0
 def __load_capabilities(self):
     package_index = package_index_from_package_path(self.__package_paths)
     spec_file_index = spec_file_index_from_package_index(package_index)
     spec_index, errors = spec_index_from_spec_file_index(spec_file_index)
     if errors:
         rospy.logerr("Errors were encountered loading capabilities:")
         for error in errors:
             if type(error) == DuplicateNameException:
                 rospy.logerr("  DuplicateNameException: " + str(error))
             elif type(error) == InterfaceNameNotFoundException:
                 rospy.logerr("  InterfaceNameNotFoundException: " +
                              str(error))
             else:
                 rospy.logerr("  " + str(type(error)) + ": " + str(error))
     self.__spec_index = spec_index
Ejemplo n.º 8
0
 def __load_capabilities(self):
     package_index = package_index_from_package_path(self.__package_paths)
     self.spec_file_index = spec_file_index_from_package_index(package_index)
     # Prune packages by black and white list
     for package in self.spec_file_index.keys():
         if self.__package_whitelist and package not in self.__package_whitelist:
             rospy.loginfo("Package '{0}' not in whitelist, skipping.".format(package))
             del self.spec_file_index[package]
         elif self.__package_blacklist and package in self.__package_blacklist:
             rospy.loginfo("Package '{0}' in blacklist, skipping.".format(package))
             del self.spec_file_index[package]
     # Generate spec_index from spec file index
     spec_index, errors = spec_index_from_spec_file_index(self.spec_file_index)
     if errors:
         rospy.logerr("Errors were encountered loading capabilities:")
         for error in errors:
             rospy.logerr("  " + str(error.__class__.__name__) + ": " + str(error))
     # Prune specific capabilities based on black and white lists
     removed_interfaces = []
     for specs, remove_func in [
         (spec_index.interfaces, spec_index.remove_interface),
         (spec_index.semantic_interfaces, spec_index.remove_semantic_interface),
         (spec_index.providers, spec_index.remove_provider)
     ]:
         for spec in specs.keys():
             if self.__whitelist and spec not in self.__whitelist:
                 removed_interfaces.append(spec)
                 remove_func(spec)
                 rospy.loginfo("Spec '{0}' is not in the whitelist, skipping.".format(spec))
             elif self.__blacklist and spec in self.__blacklist:
                 removed_interfaces.append(spec)
                 remove_func(spec)
                 rospy.loginfo("Spec '{0}' is in the blacklist, skipping.".format(spec))
     # Remove providers which no longer have an interface
     for interface in removed_interfaces:
         for provider in spec_index.providers.values():
             if provider.implements == interface:
                 spec_index.remove_provider(provider.name)
     self.__spec_index = spec_index
     # Prune spec_file_index
     spec_paths = spec_index.interface_paths.values() + \
         spec_index.semantic_interface_paths.values() + \
         spec_index.provider_paths.values()
     for package_name, package_dict in self.spec_file_index.items():
         for spec_type in ['capability_interface', 'semantic_capability_interface', 'capability_provider']:
             package_dict[spec_type][:] = [path for path in package_dict[spec_type] if path in spec_paths]
Ejemplo n.º 9
0
def test_load_minimal():
    print('Testing minimal workspace')
    workspaces = [os.path.join(test_data_dir, 'minimal')]
    package_index = package_index_from_package_path(workspaces)
    spec_file_index = spec_file_index_from_package_index(package_index)
    spec_index, errors = spec_index_from_spec_file_index(spec_file_index)
    assert not errors, errors
    expected = sorted([
        'minimal_pkg/Minimal', 'minimal_pkg/minimal',
        'minimal_pkg/SpecificMinimal', 'minimal_pkg/specific_minimal'
    ])
    assert sorted(spec_index.specs.keys()) == expected
    assert sorted(spec_index.provider_names) == [
        'minimal_pkg/minimal', 'minimal_pkg/specific_minimal'
    ]
    assert 'minimal_pkg/Minimal' in spec_index.interface_paths
    assert 'minimal_pkg/minimal' in spec_index.provider_paths
    assert 'minimal_pkg/SpecificMinimal' in spec_index.semantic_interface_paths
 def test_launch_manager_quiet(self):
     with redirected_stdio():
         workspaces = [os.path.join(TEST_DIR, 'unit', 'discovery_workspaces', 'minimal')]
         package_index = package_index_from_package_path(workspaces)
         spec_file_index = spec_file_index_from_package_index(package_index)
         spec_index, errors = spec_index_from_spec_file_index(spec_file_index)
         assert not errors, errors
         provider = 'minimal_pkg/minimal'
         assert provider in spec_index.providers
         lm = launch_manager.LaunchManager()
         lm._LaunchManager__quiet = True
         lm.run_capability_provider(spec_index.providers[provider], spec_index.provider_paths[provider])
         with assert_raises_regex(RuntimeError, 'is already running'):
             lm.run_capability_provider(spec_index.providers[provider], spec_index.provider_paths[provider])
         with assert_raises_regex(RuntimeError, 'No running launch file with PID of'):
             lm._LaunchManager__stop_by_pid(-1)
         time.sleep(1)  # Allow time for output to be produced
         lm.stop()
Ejemplo n.º 11
0
def test_load_minimal():
    print('Testing minimal workspace')
    workspaces = [os.path.join(test_data_dir, 'minimal')]
    package_index = package_index_from_package_path(workspaces)
    spec_file_index = spec_file_index_from_package_index(package_index)
    spec_index, errors = spec_index_from_spec_file_index(spec_file_index)
    assert not errors, errors
    expected = sorted([
        'minimal_pkg/Minimal',
        'minimal_pkg/minimal',
        'minimal_pkg/SpecificMinimal',
        'minimal_pkg/specific_minimal'
    ])
    assert sorted(spec_index.specs.keys()) == expected
    assert sorted(spec_index.provider_names) == ['minimal_pkg/minimal', 'minimal_pkg/specific_minimal']
    assert 'minimal_pkg/Minimal' in spec_index.interface_paths
    assert 'minimal_pkg/minimal' in spec_index.provider_paths
    assert 'minimal_pkg/SpecificMinimal' in spec_index.semantic_interface_paths
Ejemplo n.º 12
0
def test_load_missing_interface():
    print('Testing missing_interface workspace')
    workspaces = [os.path.join(test_data_dir, 'missing_interface')]
    package_index = package_index_from_package_path(workspaces)
    spec_file_index = spec_file_index_from_package_index(package_index)
    spec_index, errors = spec_index_from_spec_file_index(spec_file_index)
Ejemplo n.º 13
0
def test_load_invalid_specs():
    print('Testing invalid_specs workspace')
    workspaces = [os.path.join(test_data_dir, 'invalid_specs')]
    package_index = package_index_from_package_path(workspaces)
    spec_file_index = spec_file_index_from_package_index(package_index)
    spec_index, errors = spec_index_from_spec_file_index(spec_file_index)
Ejemplo n.º 14
0
def test_load_missing_interface():
    print('Testing missing_interface workspace')
    workspaces = [os.path.join(test_data_dir, 'missing_interface')]
    package_index = package_index_from_package_path(workspaces)
    spec_file_index = spec_file_index_from_package_index(package_index)
    spec_index, errors = spec_index_from_spec_file_index(spec_file_index)
Ejemplo n.º 15
0
def test_load_invalid_specs():
    print('Testing invalid_specs workspace')
    workspaces = [os.path.join(test_data_dir, 'invalid_specs')]
    package_index = package_index_from_package_path(workspaces)
    spec_file_index = spec_file_index_from_package_index(package_index)
    spec_index, errors = spec_index_from_spec_file_index(spec_file_index)
Ejemplo n.º 16
0
def test_load_invalid_specs():
    workspaces = [os.path.join(test_data_dir, 'invalid_specs')]
    package_index = package_index_from_package_path(workspaces)
    spec_file_index = spec_file_index_from_package_index(package_index)
    spec_index, errors = spec_index_from_spec_file_index(spec_file_index)
    assert discovery.InterfaceNameNotFoundException in [type(x) for x in errors]