Example #1
0
    def test_run_environment(self, run_mock):
        plugin = catkin.CatkinPlugin('test-part', self.properties,
                                     self.project_options)

        python_path = os.path.join(
            plugin.installdir, 'usr', 'lib', 'python2.7', 'dist-packages')
        os.makedirs(python_path)

        environment = plugin.env(plugin.installdir)

        self.assertTrue(
            'PYTHONPATH={}:$PYTHONPATH'.format(python_path) in
            environment, environment)

        self.assertTrue('ROS_MASTER_URI=http://localhost:11311' in environment)

        self.assertTrue('ROS_HOME=$SNAP_USER_DATA/ros' in environment)

        self.assertTrue('LC_ALL=C.UTF-8' in environment)

        self.assertTrue('_CATKIN_SETUP_DIR={}'.format(os.path.join(
            plugin.installdir, 'opt', 'ros', self.properties.rosdistro))
            in environment)

        self.assertTrue(
            '. {}'.format(plugin.installdir, 'opt', 'ros', 'setup.sh') in
            '\n'.join(environment), 'Expected ROS\'s setup.sh to be sourced')
Example #2
0
    def test_pull_local_dependencies(self):
        self.properties.catkin_packages.append('package_2')

        plugin = catkin.CatkinPlugin('test-part', self.properties,
                                     self.project_options)
        os.makedirs(os.path.join(plugin.sourcedir, 'src'))

        # No system dependencies (only local)
        self.dependencies_mock.return_value = set()

        plugin.pull()

        self.verify_rosdep_setup(self.properties.rosdistro,
                                 os.path.join(plugin.sourcedir, 'src'),
                                 os.path.join(plugin.partdir, 'rosdep'),
                                 plugin.PLUGIN_STAGE_SOURCES)

        # Verify that dependencies were found as expected. TODO: Would really
        # like to use ANY here instead of verifying explicit arguments, but
        # Python issue #25195 won't let me.
        self.assertEqual(1, self.dependencies_mock.call_count)
        self.assertEqual({'my_package', 'package_2'},
                         self.dependencies_mock.call_args[0][0])

        # Verify that no .deb packages were installed
        self.assertTrue(mock.call().unpack(plugin.installdir) not in
                        self.ubuntu_mock.mock_calls)
Example #3
0
    def test_pull_debian_dependencies(self):
        plugin = catkin.CatkinPlugin('test-part', self.properties,
                                     self.project_options)
        os.makedirs(os.path.join(plugin.sourcedir, 'src'))

        self.dependencies_mock.return_value = {'foo', 'bar', 'baz'}

        plugin.pull()

        self.verify_rosdep_setup(self.properties.rosdistro,
                                 os.path.join(plugin.sourcedir, 'src'),
                                 os.path.join(plugin.partdir, 'rosdep'),
                                 plugin.PLUGIN_STAGE_SOURCES)

        # Verify that dependencies were found as expected. TODO: Would really
        # like to use ANY here instead of verifying explicit arguments, but
        # Python issue #25195 won't let me.
        self.assertEqual(1, self.dependencies_mock.call_count)
        self.assertEqual({'my_package'},
                         self.dependencies_mock.call_args[0][0])

        # Verify that the dependencies were installed
        self.ubuntu_mock.return_value.get.assert_called_with(
            _CompareContainers(self, ['foo', 'bar', 'baz']))
        self.ubuntu_mock.return_value.unpack.assert_called_with(
            plugin.installdir)
Example #4
0
    def test_build(self, finish_build_mock, prepare_build_mock,
                   run_output_mock, bashrun_mock, run_mock, compilers_mock):
        plugin = catkin.CatkinPlugin('test-part', self.properties,
                                     self.project_options)
        os.makedirs(os.path.join(plugin.sourcedir, 'src'))

        plugin.build()

        prepare_build_mock.assert_called_once_with()

        # Matching like this for order independence (otherwise it would be
        # quite fragile)
        class check_build_command():
            def __eq__(self, args):
                command = ' '.join(args)
                return (
                    args[0] == 'catkin_make_isolated'
                    and '--install' in command
                    and '--pkg my_package' in command
                    and '--directory {}'.format(plugin.builddir) in command
                    and '--install-space {}'.format(plugin.rosdir) in command
                    and '--source-space {}'.format(
                        os.path.join(plugin.builddir,
                                     plugin.options.source_space)) in command)

        bashrun_mock.assert_called_with(check_build_command(), env=mock.ANY)

        self.assertFalse(
            self.dependencies_mock.called,
            'Dependencies should have been discovered in the pull() step')

        finish_build_mock.assert_called_once_with()
Example #5
0
    def test_pull_with_roscore(self):
        self.properties.include_roscore = True
        plugin = catkin.CatkinPlugin('test-part', self.properties,
                                     self.project_options)
        os.makedirs(os.path.join(plugin.sourcedir, 'src'))

        # No system dependencies
        self.dependencies_mock.return_value = set()

        def resolve(package_name):
            if package_name == 'ros_core':
                return ['ros-core-dependency']

        self.rosdep_mock.return_value.resolve_dependency = resolve

        plugin.pull()

        self.verify_rosdep_setup(self.properties.rosdistro,
                                 os.path.join(plugin.sourcedir, 'src'),
                                 os.path.join(plugin.partdir, 'rosdep'),
                                 plugin.PLUGIN_STAGE_SOURCES)

        # Verify that roscore was installed
        self.ubuntu_mock.return_value.get.assert_called_with(
            {'ros-core-dependency'})
        self.ubuntu_mock.return_value.unpack.assert_called_with(
            plugin.installdir)
Example #6
0
    def test_build_multiple(self, finish_build_mock, prepare_build_mock,
                            run_output_mock, bashrun_mock, run_mock,
                            compilers_mock):
        self.properties.catkin_packages.append('package_2')

        plugin = catkin.CatkinPlugin('test-part', self.properties,
                                     self.project_options)
        os.makedirs(os.path.join(plugin.sourcedir, 'src'))

        plugin.build()

        class check_pkg_arguments():
            def __init__(self, test):
                self.test = test

            def __eq__(self, args):
                index = args.index('--pkg')
                packages = args[index + 1:index + 3]
                self.test.assertIn('my_package', packages)
                self.test.assertIn('package_2', packages)
                return True

        bashrun_mock.assert_called_with(check_pkg_arguments(self),
                                        env=mock.ANY)

        self.assertFalse(
            self.dependencies_mock.called,
            'Dependencies should have been discovered in the pull() step')

        finish_build_mock.assert_called_once_with()
Example #7
0
    def test_build_multiple(self, finish_build_mock, prepare_build_mock,
                            run_output_mock, bashrun_mock, run_mock):
        self.properties.catkin_packages.append('package_2')

        plugin = catkin.CatkinPlugin('test-part', self.properties,
                                     self.project_options)
        os.makedirs(os.path.join(plugin.sourcedir, 'src'))

        plugin.build()

        class check_pkg_arguments():
            def __init__(self, test):
                self.test = test

            def __eq__(self, args):
                index = args.index('--pkg')
                packages = args[index+1:index+3]
                if 'my_package' not in packages:
                    self.test.fail('Expected "my_package" to be installed '
                                   'within the same command as "package_2"')

                if 'package_2' not in packages:
                    self.test.fail('Expected "package_2" to be installed '
                                   'within the same command as "my_package"')

                return True

        bashrun_mock.assert_called_with(check_pkg_arguments(self))

        self.assertFalse(
            self.dependencies_mock.called,
            'Dependencies should have been discovered in the pull() step')

        finish_build_mock.assert_called_once_with()
Example #8
0
    def test_use_in_snap_python_rewrites_shebangs(self):
        plugin = catkin.CatkinPlugin('test-part', self.properties,
                                     self.project_options)
        os.makedirs(os.path.join(plugin.rosdir, 'bin'))

        # Place a few files with bad shebangs, and some files that shouldn't be
        # changed.
        files = [{
            'path': os.path.join(plugin.rosdir, '_setup_util.py'),
            'contents': '#!/foo/bar/baz/python',
            'expected': '#!/usr/bin/env python',
        }, {
            'path': os.path.join(plugin.rosdir, 'bin/catkin_find'),
            'contents': '#!/foo/baz/python',
            'expected': '#!/usr/bin/env python',
        }, {
            'path': os.path.join(plugin.rosdir, 'foo'),
            'contents': 'foo',
            'expected': 'foo',
        }]

        for file_info in files:
            with open(file_info['path'], 'w') as f:
                f.write(file_info['contents'])

        plugin._use_in_snap_python()

        for file_info in files:
            with open(os.path.join(plugin.rosdir, file_info['path']),
                      'r') as f:
                self.assertEqual(f.read(), file_info['expected'])
Example #9
0
    def test_build_encompasses_source_space(self, finish_mock, prepare_mock):
        self.properties.catkin_packages = []
        plugin = catkin.CatkinPlugin('test-part', self.properties)
        os.makedirs(os.path.join(plugin.sourcedir, 'src'))

        plugin.build()

        self.assertTrue(os.path.isdir(os.path.join(plugin.builddir, 'src')))
Example #10
0
    def test_build_runs_in_bash(self, run_output_mock, run_mock):
        plugin = catkin.CatkinPlugin('test-part', self.properties)
        os.makedirs(os.path.join(plugin.sourcedir, 'src'))

        plugin.build()

        run_mock.assert_has_calls(
            [mock.call(['/bin/bash', mock.ANY], cwd=mock.ANY)])
Example #11
0
 def test_valid_catkin_workspace_src(self):
     # sourcedir is expected to be the root of the Catkin workspace. Since
     # it contains a 'src' directory, this is a valid Catkin workspace.
     plugin = catkin.CatkinPlugin('test-part', self.properties,
                                  self.project_options)
     os.makedirs(os.path.join(plugin.sourcedir, 'src'))
     # An exception will be raised if pull can't handle the valid workspace.
     plugin.pull()
Example #12
0
    def test_invalid_rosdistro(self):
        self.properties.rosdistro = 'invalid'
        with self.assertRaises(RuntimeError) as raised:
            catkin.CatkinPlugin('test-part', self.properties,
                                self.project_options)

        self.assertEqual(str(raised.exception),
                         "Unsupported rosdistro: 'invalid'. The supported ROS "
                         "distributions are 'indigo', 'jade', and 'kinetic'")
    def test_finish_build_file_missing(self, run_output_mock, run_mock):
        plugin = catkin.CatkinPlugin('test-part', self.properties)
        os.makedirs(plugin.rosdir)

        try:
            plugin._finish_build()
        except FileNotFoundError:
            self.fail('Unexpectedly raised an exception when files were '
                      'missing')
Example #14
0
    def test_log_warning_when_unable_to_find_a_catkin_package(self):
        fake_logger = fixtures.FakeLogger()
        self.useFixture(fake_logger)

        plugin = catkin.CatkinPlugin('test-part', self.properties)
        plugin._find_package_deps()

        self.assertEqual('Unable to find "package.xml" for "my_package"\n',
                         fake_logger.output)
Example #15
0
    def test_build_accounts_for_source_subdir(self, finish_mock, prepare_mock):
        self.properties.catkin_packages = []
        self.properties.source_subdir = 'workspace'
        self.properties.source_space = 'foo'
        plugin = catkin.CatkinPlugin('test-part', self.properties)
        os.makedirs(os.path.join(plugin.sourcedir, 'workspace', 'foo'))

        plugin.build()

        self.assertTrue(os.path.isdir(os.path.join(plugin.builddir, 'foo')))
Example #16
0
 def test_valid_catkin_workspace_src(self):
     # sourcedir is expected to be the root of the Catkin workspace. Since
     # it contains a 'src' directory, this is a valid Catkin workspace.
     try:
         plugin = catkin.CatkinPlugin('test-part', self.properties)
         os.makedirs(os.path.join(plugin.sourcedir, 'src'))
         plugin.pull()
     except FileNotFoundError:
         self.fail('Unexpectedly raised an exception when the Catkin '
                   'workspace was valid')
Example #17
0
    def test_run_environment_no_python(self, run_mock):
        plugin = catkin.CatkinPlugin('test-part', self.properties)

        python_path = os.path.join(plugin.installdir, 'usr', 'lib',
                                   'python2.7', 'dist-packages')

        environment = plugin.env(plugin.installdir)

        self.assertFalse('PYTHONPATH={}'.format(python_path) in environment,
                         environment)
Example #18
0
    def test_build_encompasses_remapped_source_space(self, finish_mock,
                                                     prepare_mock):
        self.properties.catkin_packages = []
        self.properties.source_space = 'foo'
        plugin = catkin.CatkinPlugin('test-part', self.properties,
                                     self.project_options)
        os.makedirs(os.path.join(plugin.sourcedir, 'foo'))

        plugin.build()

        self.assertTrue(os.path.isdir(os.path.join(plugin.builddir, 'foo')))
Example #19
0
    def test_invalid_catkin_workspace_no_src(self):
        # sourcedir is expected to be the root of the Catkin workspace. Since
        # it does not contain a `src` folder and `source-space` is 'src', this
        # should fail.
        plugin = catkin.CatkinPlugin('test-part', self.properties,
                                     self.project_options)
        raised = self.assertRaises(FileNotFoundError, plugin.pull)

        self.assertEqual(
            str(raised), 'Unable to find package path: "{}"'.format(
                os.path.join(plugin.sourcedir, 'src')))
    def test_invalid_catkin_workspace_source_space_same_as_source(self):
        self.properties.source_space = '.'

        # sourcedir is expected to be the root of the Catkin workspace. Since
        # source_space was specified to be the same as the root, this should
        # fail.
        with self.assertRaises(RuntimeError) as raised:
            catkin.CatkinPlugin('test-part', self.properties).pull()

        self.assertEqual(str(raised.exception),
                         'source-space cannot be the root of the Catkin '
                         'workspace')
Example #21
0
    def test_valid_catkin_workspace_source_space(self):
        self.properties.source_space = 'foo'

        # sourcedir is expected to be the root of the Catkin workspace.
        # Normally this would mean it contained a `src` directory, but it can
        # be remapped via the `source-space` key.
        plugin = catkin.CatkinPlugin('test-part', self.properties,
                                     self.project_options)
        os.makedirs(
            os.path.join(plugin.sourcedir, self.properties.source_space))
        # An exception will be raised if pull can't handle the source space.
        plugin.pull()
Example #22
0
    def test_clean_pull(self):
        plugin = catkin.CatkinPlugin('test-part', self.properties,
                                     self.project_options)
        os.makedirs(os.path.join(plugin.sourcedir, 'src'))

        self.dependencies_mock.return_value = {'foo', 'bar', 'baz'}

        plugin.pull()
        os.makedirs(plugin._rosdep_path)

        plugin.clean_pull()
        self.assertFalse(os.path.exists(plugin._rosdep_path))
Example #23
0
    def test_exception_raised_when_package_definition_cannot_be_read(
            self, mock_open):
        mock_open.side_effect = _IOError()
        plugin = catkin.CatkinPlugin('test-part', self.properties)
        with self.assertRaises(IOError) as raised:
            plugin._find_package_deps()

        self.assertEqual(raised.exception.errno, os.errno.EACCES)
        xml_to_open = os.path.join(
            os.path.abspath(os.curdir), 'parts', 'test-part', 'build', 'src',
            'my_package', 'package.xml')
        mock_open.assert_called_once_with(xml_to_open, 'r')
    def test_finish_build_raise_errors(self, run_output_mock, run_mock):
        plugin = catkin.CatkinPlugin('test-part', self.properties)
        os.makedirs(plugin.rosdir)

        with open(os.path.join(plugin.rosdir, '_setup_util.py'), 'w') as f:
            f.write('#!/foo/bar/baz/python')

        with mock.patch.object(builtins, 'open',
                               side_effect=RuntimeError('foo')):
            with self.assertRaises(RuntimeError) as raised:
                plugin._finish_build()

        self.assertEqual(raised.exception.args[0], 'foo')
Example #25
0
    def test_invalid_catkin_workspace_invalid_source_space(self):
        self.properties.source_space = 'foo'

        # sourcedir is expected to be the root of the Catkin workspace. Since
        # it does not contain a `src` folder and source_space wasn't
        # specified, this should fail.
        plugin = catkin.CatkinPlugin('test-part', self.properties,
                                     self.project_options)
        raised = self.assertRaises(FileNotFoundError, plugin.pull)

        self.assertEqual(
            str(raised), 'Unable to find package path: "{}"'.format(
                os.path.join(plugin.sourcedir, self.properties.source_space)))
Example #26
0
    def test_valid_catkin_workspace_source_space(self):
        self.properties.source_space = 'foo'

        # sourcedir is expected to be the root of the Catkin workspace.
        # Normally this would mean it contained a `src` directory, but it can
        # be remapped via the `source-space` key.
        try:
            plugin = catkin.CatkinPlugin('test-part', self.properties)
            os.makedirs(
                os.path.join(plugin.sourcedir, self.properties.source_space))
            plugin.pull()
        except FileNotFoundError:
            self.fail('Unexpectedly raised an exception when the Catkin '
                      'src was remapped in a valid manner')
Example #27
0
    def test_prepare_build(self, use_in_snap_python_mock):
        plugin = catkin.CatkinPlugin('test-part', self.properties,
                                     self.project_options)
        os.makedirs(os.path.join(plugin.rosdir, 'test'))

        # Place a few .cmake files with incorrect paths, and some files that
        # shouldn't be changed.
        files = [
            {
                'path': 'fooConfig.cmake',
                'contents': '"/usr/lib/foo"',
                'expected': '"{}/usr/lib/foo"'.format(plugin.installdir),
            },
            {
                'path': 'bar.cmake',
                'contents': '"/usr/lib/bar"',
                'expected': '"/usr/lib/bar"',
            },
            {
                'path': 'test/bazConfig.cmake',
                'contents': '"/test/baz;/usr/lib/baz"',
                'expected': '"{0}/test/baz;{0}/usr/lib/baz"'.format(
                    plugin.installdir),
            },
            {
                'path': 'test/quxConfig.cmake',
                'contents': 'qux',
                'expected': 'qux',
            },
            {
                'path': 'test/installedConfig.cmake',
                'contents': '"{}/foo"'.format(plugin.installdir),
                'expected': '"{}/foo"'.format(plugin.installdir),
            }
        ]

        for file_info in files:
            path = os.path.join(plugin.rosdir, file_info['path'])
            with open(path, 'w') as f:
                f.write(file_info['contents'])

        plugin._prepare_build()

        self.assertTrue(use_in_snap_python_mock.called)

        for file_info in files:
            path = os.path.join(plugin.rosdir, file_info['path'])
            with open(path, 'r') as f:
                self.assertEqual(f.read(), file_info['expected'])
Example #28
0
    def test_pull_unable_to_resolve_roscore(self):
        self.properties.include_roscore = True
        plugin = catkin.CatkinPlugin('test-part', self.properties,
                                     self.project_options)
        os.makedirs(os.path.join(plugin.sourcedir, 'src'))

        # No system dependencies
        self.dependencies_mock.return_value = set()

        self.rosdep_mock.return_value.resolve_dependency.return_value = None

        raised = self.assertRaises(RuntimeError, plugin.pull)

        self.assertEqual(str(raised),
                         'Unable to determine system dependency for roscore')
Example #29
0
    def test_pull_invalid_dependency(self, compilers_mock):
        plugin = catkin.CatkinPlugin('test-part', self.properties,
                                     self.project_options)
        os.makedirs(os.path.join(plugin.sourcedir, 'src'))

        self.dependencies_mock.return_value = ['foo']

        mock_instance = self.ubuntu_mock.return_value
        mock_instance.get.side_effect = repo.PackageNotFoundError('foo')

        raised = self.assertRaises(RuntimeError, plugin.pull)

        self.assertEqual(
            str(raised), 'Failed to fetch system dependencies: The Ubuntu '
            "package 'foo' was not found.")
Example #30
0
    def test_pull_invalid_dependency(self):
        plugin = catkin.CatkinPlugin('test-part', self.properties)
        os.makedirs(os.path.join(plugin.sourcedir, 'src'))

        self.dependencies_mock.return_value = ['foo']

        mock_instance = self.ubuntu_mock.return_value
        mock_instance.get.side_effect = repo.PackageNotFoundError('foo')

        with self.assertRaises(RuntimeError) as raised:
            plugin.pull()

        self.assertEqual(
            str(raised.exception),
            'Failed to fetch system dependencies: The Ubuntu '
            'package "foo" was not found')