Example #1
0
    def test_get_source_with_unrecognized_source_must_raise_exception(self):
        options = tests.MockOptions('unrecognized://test_source')
        plugin = snapcraft.BasePlugin('test_plugin', options,
                                      self.project_options)
        with self.assertRaises(ValueError) as raised:
            plugin.pull()

        self.assertEqual(raised.exception.__str__(),
                         'no handler to manage source')
Example #2
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))
Example #3
0
    def test_local_non_dir_source_path_must_raise_exception(self, mock_isdir):
        options = tests.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')
Example #4
0
    def test_get_bzr_source_from_uri(self, mock_pull):
        sources = ['lp:snapcraft_test_source', 'bzr:dummy-source']

        for source in sources:
            with self.subTest(key=source):
                options = tests.MockOptions(source=source)
                snapcraft.sources.get(sourcedir='dummy',
                                      builddir='dummy',
                                      options=options)

                mock_pull.assert_called_once_with()
                mock_pull.reset_mock()
Example #5
0
    def test_get_svn_source_from_uri(self, mock_pull):
        test_sources = ['svn://sylpheed.sraoss.jp/sylpheed/trunk']

        for source in test_sources:
            with self.subTest(key=source):
                options = tests.MockOptions(source=source)
                sources.get(sourcedir='dummy',
                            builddir='dummy',
                            options=options)

                mock_pull.assert_called_once_with()
                mock_pull.reset_mock()
Example #6
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))
Example #7
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))
Example #8
0
    def test_get_git_source_from_uri(self, mock_pull):
        sources = [
            'git://github.com:ubuntu-core/snapcraft.git',
            '[email protected]:ubuntu-core/snapcraft.git'
        ]

        for source in sources:
            with self.subTest(key=source):
                options = tests.MockOptions(source=source)
                snapcraft.sources.get(sourcedir='dummy',
                                      builddir='dummy',
                                      options=options)

                mock_pull.assert_called_once_with()
                mock_pull.reset_mock()
Example #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))
Example #10
0
    def test_get_git_source_from_uri(self, mock_pull, mock_check):
        mock_check.side_effect = None
        test_sources = [
            'git://github.com:ubuntu-core/snapcraft.git',
            '[email protected]:ubuntu-core/snapcraft.git',
            'https://github.com:ubuntu-core/snapcraft.git',
        ]

        for source in test_sources:
            with self.subTest(key=source):
                options = tests.MockOptions(source=source)
                sources.get(sourcedir='dummy',
                            builddir='dummy',
                            options=options)

                mock_pull.assert_called_once_with()
                mock_pull.reset_mock()
Example #11
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')))
Example #12
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))
Example #13
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))