Ejemplo n.º 1
0
    def test_do_not_follow_links(self, mock_check):
        mock_check.side_effect = None
        options = tests.MockOptions(source='.')
        plugin = snapcraft.BasePlugin('test_plugin', options)

        os.makedirs(plugin.partdir)
        os.symlink(os.path.abspath('.'), plugin.sourcedir)

        # Create a file and a symlink to it
        open('file', mode='w').close()
        os.symlink('file', 'symlinkfile')

        # Create a directory and a symlink to it
        os.mkdir('dir')
        os.symlink('dir', 'symlinkdir')
        plugin.build()

        # Make sure this is still a link
        self.assertTrue(os.path.islink(plugin.sourcedir))

        build_file_path = os.path.join(
            plugin.builddir, 'file')
        build_symlinkfile_path = os.path.join(
            plugin.builddir, 'symlinkfile')

        self.assertTrue(os.path.isfile(build_file_path))
        self.assertTrue(os.path.islink(build_symlinkfile_path))

        build_dir_path = os.path.join(
            plugin.builddir, 'dir')
        build_symlinkdir_path = os.path.join(
            plugin.builddir, 'symlinkdir')

        self.assertTrue(os.path.isdir(build_dir_path))
        self.assertTrue(os.path.islink(build_symlinkdir_path))
Ejemplo n.º 2
0
 def test_parallel_build_count_returns_build_count_from_project(self):
     options = tests.MockOptions(disable_parallel=False)
     plugin = snapcraft.BasePlugin('test_plugin', options,
                                   self.project_options)
     unittest.mock.patch.object(self.project_options,
                                'parallel_build_count', 2)
     self.assertThat(plugin.parallel_build_count, Equals(2))
Ejemplo n.º 3
0
    def test_get_source_with_unrecognized_source_must_raise_exception(self):
        options = MockOptions('unrecognized://test_source')
        plugin = snapcraft.BasePlugin('test_plugin', options)
        with self.assertRaises(ValueError) as raised:
            plugin.pull()

        self.assertEqual(raised.exception.__str__(),
                         'no handler to manage source')
Ejemplo n.º 4
0
    def test_get_source_with_branch_and_tag_must_raise_error(self):
        options = tests.MockOptions('lp:source', self.source_type,
                                    self.source_branch, self.source_tag)
        plugin = snapcraft.BasePlugin('test_plugin', options)
        with self.assertRaises(sources.IncompatibleOptionsError) as raised:
            plugin.pull()

        self.assertEqual(
            raised.exception.__str__(),
            'can\'t specify both source-tag and source-branch for a {} '
            'source'.format(self.source_type))
Ejemplo n.º 5
0
    def test_local_non_dir_source_path_must_raise_exception(self, mock_isdir):
        options = MockOptions('file')
        mock_isdir.return_value = False
        plugin = snapcraft.BasePlugin('test_plugin', options)
        with self.assertRaises(ValueError) as raised:
            plugin.pull()

        mock_isdir.assert_called_once_with('file')

        self.assertEqual(raised.exception.__str__(),
                         'local source is not a directory')
Ejemplo n.º 6
0
    def test_build_without_subdir_copies_sourcedir(self):
        plugin = snapcraft.BasePlugin('test-part', options=None)

        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, 'file'), 'w').close()

        self.assertEqual(plugin.build_basedir, plugin.builddir)

        plugin.build()

        self.assertTrue(
            os.path.exists(os.path.join(plugin.build_basedir, 'file')))
Ejemplo n.º 7
0
    def test_clean_pull_directory(self):
        options = tests.MockOptions(source='src')
        plugin = snapcraft.BasePlugin('test_plugin', options)

        os.makedirs(plugin.sourcedir)
        source_file = os.path.join(plugin.sourcedir, 'source')
        open(source_file, 'w').close()

        plugin.clean_pull()

        # The source directory should now be gone
        self.assertFalse(os.path.exists(plugin.sourcedir))
Ejemplo n.º 8
0
    def test_get_source_with_branch_must_raise_error(self, mock_check):
        mock_check.side_effect = None
        options = tests.MockOptions('lp:this', self.source_type,
                                    self.source_branch, self.source_tag,
                                    None, None, self.source_commit)
        plugin = snapcraft.BasePlugin('test_plugin', options)

        with self.assertRaises(sources.IncompatibleOptionsError) as raised:
            plugin.pull()

        self.assertEqual(
            raised.exception.__str__(),
            'can\'t specify a {} for a {} source'.format(
                self.error, self.source_type))
Ejemplo n.º 9
0
    def test_clean_pull_symlink(self):
        options = tests.MockOptions(source='src')
        plugin = snapcraft.BasePlugin('test_plugin', options)

        real_source_directory = os.path.join(os.getcwd(), 'src')
        os.mkdir(real_source_directory)
        os.makedirs(plugin.partdir)
        os.symlink(real_source_directory, plugin.sourcedir)

        plugin.clean_pull()

        # The source symlink should now be gone, but the real source should
        # still be there.
        self.assertFalse(os.path.exists(plugin.sourcedir))
        self.assertTrue(os.path.isdir(real_source_directory))
Ejemplo n.º 10
0
    def test_build_ignores_snapcraft_files_in_source_dir(self):
        plugin = snapcraft.BasePlugin('test-part', options=None)

        tmpdir = tempfile.TemporaryDirectory()
        self.addCleanup(tmpdir.cleanup)
        plugin.sourcedir = tmpdir.name
        for file_ in common.SNAPCRAFT_FILES:
            open(os.path.join(plugin.sourcedir, file_), 'w').close()

        tmpdir = tempfile.TemporaryDirectory()
        self.addCleanup(tmpdir.cleanup)
        plugin.builddir = tmpdir.name

        plugin.build()

        for file_ in common.SNAPCRAFT_FILES:
            self.assertFalse(
                os.path.exists(os.path.join(plugin.builddir, file_)))
Ejemplo n.º 11
0
    def test_build_without_subdir_copies_sourcedir(self):
        plugin = snapcraft.BasePlugin('test-part', options=None)

        tmpdir = tempfile.TemporaryDirectory()
        self.addCleanup(tmpdir.cleanup)
        plugin.sourcedir = tmpdir.name
        subdir = os.path.join(plugin.sourcedir, 'src')
        os.mkdir(subdir)
        open(os.path.join(subdir, 'file'), 'w').close()

        tmpdir = tempfile.TemporaryDirectory()
        self.addCleanup(tmpdir.cleanup)
        plugin.builddir = tmpdir.name

        plugin.build()

        self.assertTrue(
            os.path.exists(os.path.join(plugin.builddir, 'src', 'file')))
Ejemplo n.º 12
0
    def test_build_with_subdir_copies_sourcedir(self):
        options = tests.MockOptions(source_subdir='src')
        plugin = snapcraft.BasePlugin('test-part', options)

        subdir = os.path.join(plugin.sourcedir, plugin.options.source_subdir)
        os.makedirs(subdir)
        open(os.path.join(plugin.sourcedir, 'file1'), 'w').close()
        open(os.path.join(subdir, 'file2'), 'w').close()

        self.assertEqual(
            os.path.join(plugin.build_basedir, options.source_subdir),
            plugin.builddir)

        plugin.build()

        self.assertTrue(
            os.path.exists(os.path.join(plugin.build_basedir, 'file1')))
        self.assertTrue(os.path.exists(os.path.join(plugin.builddir, 'file2')))
Ejemplo n.º 13
0
    def test_build_ignores_snapcraft_files_in_source_dir(self):
        plugin = snapcraft.BasePlugin('test-part', options=None)

        os.makedirs(plugin.sourcedir)
        os.makedirs(plugin.builddir)

        for file_ in common.SNAPCRAFT_FILES:
            open(os.path.join(plugin.sourcedir, file_), 'w').close()
        open(os.path.join(plugin.sourcedir, 'my-snap.snap'), 'w').close()
        open(os.path.join(plugin.sourcedir, 'my-snap'), 'w').close()

        plugin.build()

        for file_ in common.SNAPCRAFT_FILES:
            self.assertFalse(
                os.path.exists(os.path.join(plugin.builddir, file_)))
        self.assertFalse(
            os.path.exists(os.path.join(plugin.builddir, 'my-snap.snap')),
            os.listdir(plugin.builddir))

        # Make sure we don't filter things out incorrectly
        self.assertTrue(
            os.path.exists(os.path.join(plugin.builddir, 'my-snap')),
            os.listdir(plugin.builddir))
Ejemplo n.º 14
0
    def test_clean_build(self):
        options = tests.MockOptions(source='src')
        plugin = snapcraft.BasePlugin('test_plugin', options)

        os.makedirs(plugin.sourcedir)
        source_file = os.path.join(plugin.sourcedir, 'source')
        open(source_file, 'w').close()

        os.makedirs(plugin.build_basedir)
        open(os.path.join(plugin.build_basedir, 'built'), 'w').close()

        os.makedirs(plugin.installdir)
        open(os.path.join(plugin.installdir, 'installed'), 'w').close()

        plugin.clean_build()

        # Make sure the source file hasn't been touched
        self.assertTrue(os.path.isfile(source_file))

        # Make sure the build directory is gone
        self.assertFalse(os.path.exists(plugin.build_basedir))

        # Make sure the install directory is gone
        self.assertFalse(os.path.exists(plugin.installdir))
Ejemplo n.º 15
0
    def test_run_output_specifying_a_cwd(self, mock_run):
        plugin = snapcraft.BasePlugin('test/part', options=None)
        plugin.run_output(['ls'], cwd=plugin.sourcedir)

        mock_run.assert_called_once_with(['ls'], cwd=plugin.sourcedir)
Ejemplo n.º 16
0
    def test_run_without_specifying_cwd(self, mock_run):
        plugin = snapcraft.BasePlugin('test/part', options=None)
        plugin.run(['ls'])

        mock_run.assert_called_once_with(['ls'], cwd=plugin.builddir)
Ejemplo n.º 17
0
    def test_part_name_with_forward_slash_is_one_directory(self):
        plugin = snapcraft.BasePlugin('test/part', options=None)

        os.makedirs(plugin.sourcedir)

        self.assertIn('test\N{BIG SOLIDUS}part', os.listdir('parts'))
Ejemplo n.º 18
0
 def test_cross_compilation_raises(self):
     options = unit.MockOptions(disable_parallel=True)
     plugin = snapcraft.BasePlugin("test_plugin", options,
                                   self.project_options)
     self.assertRaises(errors.CrossCompilationNotSupported,
                       plugin.enable_cross_compilation)
Ejemplo n.º 19
0
 def test_parallel_build_count_returns_1_when_disabled(self):
     options = tests.MockOptions(disable_parallel=True)
     plugin = snapcraft.BasePlugin('test_plugin', options,
                                   self.project_options)
     self.assertThat(plugin.parallel_build_count, Equals(1))
Ejemplo n.º 20
0
    def test_run_specifying_a_cwd(self, mock_run):
        plugin = snapcraft.BasePlugin("test/part", options=None)
        plugin.run(["ls"], cwd=plugin.sourcedir)

        mock_run.assert_called_once_with(["ls"], cwd=plugin.sourcedir)
Ejemplo n.º 21
0
    def test_run_output_without_specifying_cwd(self, mock_run):
        plugin = snapcraft.BasePlugin("test/part", options=None)
        plugin.run_output(["ls"])

        mock_run.assert_called_once_with(["ls"], cwd=plugin.builddir)