Example #1
0
    def test_pull_installs_ruby(self):
        plugin = ruby.RubyPlugin('test-part', self.options,
                                 self.project_options)
        with mock.patch.multiple(plugin,
                                 _ruby_tar=mock.DEFAULT,
                                 _gem_install=mock.DEFAULT) as mocks:
            with mock.patch('subprocess.check_call') as mock_check_call:
                plugin.pull()

        ruby_expected_dir = os.path.join(self.path, 'parts', 'test-part',
                                         'ruby')
        mocks['_ruby_tar'].provision.assert_called_with(ruby_expected_dir,
                                                        clean_target=False,
                                                        keep_tarball=True)
        mock_check_call.assert_has_calls([
            mock.call([
                mock.ANY, mock.ANY, './configure', '--disable-install-rdoc',
                '--prefix=/'
            ],
                      cwd=ruby_expected_dir,
                      env=mock.ANY),
            mock.call([
                mock.ANY, mock.ANY, 'make', '-j{}'.format(
                    plugin.parallel_build_count)
            ],
                      cwd=ruby_expected_dir,
                      env=mock.ANY),
            mock.call([
                mock.ANY, mock.ANY, 'make', 'install', 'DESTDIR={}'.format(
                    plugin.installdir)
            ],
                      cwd=ruby_expected_dir,
                      env=mock.ANY)
        ])
Example #2
0
    def test_pull_with_bundler(self):
        self.options.gems = ["test-gem-1", "test-gem-2"]
        plugin = ruby.RubyPlugin("test-part", self.options, self.project)
        self.options.use_bundler = True

        with mock.patch.multiple(plugin,
                                 _ruby_tar=mock.DEFAULT,
                                 _ruby_install=mock.DEFAULT):
            with mock.patch("snapcraft.internal.common.run") as mock_run:
                plugin.pull()
        test_part_dir = os.path.join(self.path, "parts", "test-part")
        mock_run.assert_has_calls([
            mock.call(
                [
                    os.path.join(test_part_dir, "install", "bin", "ruby"),
                    os.path.join(test_part_dir, "install", "bin", "gem"),
                    "install",
                    "--env-shebang",
                    "test-gem-1",
                    "test-gem-2",
                    "bundler",
                ],
                cwd=os.path.join(test_part_dir, "build"),
                env=mock.ANY,
            ),
            mock.call(
                [
                    os.path.join(test_part_dir, "install", "bin", "ruby"),
                    os.path.join(test_part_dir, "install", "bin", "bundle"),
                    "install",
                ],
                cwd=os.path.join(test_part_dir, "build"),
                env=mock.ANY,
            ),
        ])
Example #3
0
    def test_snap_fileset(self):
        expected_fileset = ["-include/", "-share/"]

        plugin = ruby.RubyPlugin("test-part", self.options, self.project)
        fileset = plugin.snap_fileset()

        self.assertThat(fileset, Equals(expected_fileset))
Example #4
0
    def test_pull_with_bundler(self):
        self.options.gems = ['test-gem-1', 'test-gem-2']
        plugin = ruby.RubyPlugin('test-part', self.options,
                                 self.project_options)
        self.options.use_bundler = True

        with mock.patch.multiple(plugin,
                                 _ruby_tar=mock.DEFAULT,
                                 _ruby_install=mock.DEFAULT):
            with mock.patch('subprocess.check_call') as mock_check_call:
                plugin.pull()
        test_part_dir = os.path.join(self.path, 'parts', 'test-part')
        mock_check_call.assert_has_calls([
            mock.call([
                mock.ANY, mock.ANY,
                os.path.join(test_part_dir, 'install', 'bin', 'ruby'),
                os.path.join(test_part_dir, 'install', 'bin',
                             'gem'), 'install', '--env-shebang', 'test-gem-1',
                'test-gem-2', 'bundler'
            ],
                      cwd=os.path.join(test_part_dir, 'build'),
                      env=mock.ANY),
            mock.call([
                mock.ANY, mock.ANY,
                os.path.join(test_part_dir, 'install', 'bin', 'ruby'),
                os.path.join(test_part_dir, 'install', 'bin', 'bundle'),
                'install'
            ],
                      cwd=os.path.join(test_part_dir, 'build'),
                      env=mock.ANY)
        ])
Example #5
0
    def test_pull_installs_ruby(self):
        plugin = ruby.RubyPlugin("test-part", self.options,
                                 self.project_options)
        with mock.patch.multiple(plugin,
                                 _ruby_tar=mock.DEFAULT,
                                 _gem_install=mock.DEFAULT) as mocks:
            with mock.patch("snapcraft.internal.common.run") as mock_run:
                plugin.pull()

        ruby_expected_dir = os.path.join(self.path, "parts", "test-part",
                                         "ruby")
        mocks["_ruby_tar"].provision.assert_called_with(ruby_expected_dir,
                                                        clean_target=False,
                                                        keep_tarball=True)
        mock_run.assert_has_calls([
            mock.call(
                ["./configure", "--disable-install-rdoc", "--prefix=/"],
                cwd=ruby_expected_dir,
                env=mock.ANY,
            ),
            mock.call(
                ["make", "-j{}".format(plugin.parallel_build_count)],
                cwd=ruby_expected_dir,
                env=mock.ANY,
            ),
            mock.call(
                ["make", "install", "DESTDIR={}".format(plugin.installdir)],
                cwd=ruby_expected_dir,
                env=mock.ANY,
            ),
        ])
Example #6
0
    def test_snap_fileset(self):
        expected_fileset = (['-include/', '-share/'])

        plugin = ruby.RubyPlugin('test-part', self.options,
                                 self.project_options)
        fileset = plugin.snap_fileset()

        self.assertThat(fileset, Equals(expected_fileset))
Example #7
0
    def test_env_with_ruby(self):
        plugin = ruby.RubyPlugin('test-part', self.options,
                                 self.project_options)
        part_dir = os.path.join(self.path, 'test-part-path')

        os.makedirs(
            os.path.join(part_dir, 'lib', 'ruby', 'gems', 'test-version'))
        env = plugin.env('test-part-path')

        expected_env = {
            'GEM_HOME="test-part-path/lib/ruby/gems/test-version"',
            'RUBYLIB="test-part-path/lib/ruby/test-version:test-part-path/'
            'lib/ruby/test-version/{}-linux"'.format(platform.machine()),
            'GEM_PATH="test-part-path/lib/ruby/gems/test-version"'
        }
        self.assertThat(set(env), Equals(expected_env))
Example #8
0
    def test_env_with_multiple_ruby(self):
        plugin = ruby.RubyPlugin("test-part", self.options, self.project)
        part_dir = os.path.join(self.path, "test-part-path")

        os.makedirs(os.path.join(part_dir, "lib", "ruby", "gems", "test-version1"))
        os.makedirs(os.path.join(part_dir, "lib", "ruby", "gems", "test-version2"))

        error = self.assertRaises(
            snapcraft.internal.errors.SnapcraftEnvironmentError,
            plugin.env,
            "test-part-path",
        )

        self.assertThat(
            str(error), Equals("Expected a single Ruby version, but found 2")
        )
Example #9
0
    def test_env_with_multiple_ruby(self):
        plugin = ruby.RubyPlugin('test-part', self.options,
                                 self.project_options)
        part_dir = os.path.join(self.path, 'test-part-path')

        os.makedirs(
            os.path.join(part_dir, 'lib', 'ruby', 'gems', 'test-version1'))
        os.makedirs(
            os.path.join(part_dir, 'lib', 'ruby', 'gems', 'test-version2'))

        error = self.assertRaises(
            snapcraft.internal.errors.SnapcraftEnvironmentError, plugin.env,
            'test-part-path')

        self.assertThat(str(error),
                        Equals('Expected a single Ruby version, but found 2'))
Example #10
0
    def test_pull_installs_gems_without_bundler(self):
        self.options.gems = ['test-gem-1', 'test-gem-2']
        plugin = ruby.RubyPlugin('test-part', self.options,
                                 self.project_options)
        with mock.patch.multiple(plugin,
                                 _ruby_tar=mock.DEFAULT,
                                 _ruby_install=mock.DEFAULT):
            with mock.patch('snapcraft.internal.common.run') as mock_run:
                plugin.pull()

        test_part_dir = os.path.join(self.path, 'parts', 'test-part')
        mock_run.assert_called_with([
            os.path.join(test_part_dir, 'install', 'bin', 'ruby'),
            os.path.join(test_part_dir, 'install', 'bin', 'gem'), 'install',
            '--env-shebang', 'test-gem-1', 'test-gem-2'
        ],
                                    cwd=os.path.join(test_part_dir, 'build'),
                                    env=mock.ANY)
Example #11
0
    def test_env_with_ruby(self):
        plugin = ruby.RubyPlugin("test-part", self.options, self.project)
        part_dir = os.path.join(self.path, "test-part-path")

        os.makedirs(os.path.join(part_dir, "lib", "ruby", "gems", "test-version"))
        libdir = os.path.join("test-part-path", "lib", "ruby", "test-version")
        arch_libdir = os.path.join(libdir, "foo-linux-bar")
        real_arch_libdir = os.path.join(self.path, arch_libdir)
        os.makedirs(real_arch_libdir)
        open(os.path.join(real_arch_libdir, "rbconfig.rb"), "w").close()
        env = plugin.env("test-part-path")

        expected_env = {
            'GEM_HOME="test-part-path/lib/ruby/gems/test-version"',
            'RUBYLIB="{}:{}"'.format(libdir, arch_libdir),
            'GEM_PATH="test-part-path/lib/ruby/gems/test-version"',
        }
        self.assertThat(set(env), Equals(expected_env))
Example #12
0
    def test_env_with_ruby(self):
        plugin = ruby.RubyPlugin('test-part', self.options,
                                 self.project_options)
        part_dir = os.path.join(self.path, 'test-part-path')

        os.makedirs(
            os.path.join(part_dir, 'lib', 'ruby', 'gems', 'test-version'))
        libdir = os.path.join('test-part-path', 'lib', 'ruby', 'test-version')
        arch_libdir = os.path.join(libdir, 'foo-linux-bar')
        real_arch_libdir = os.path.join(self.path, arch_libdir)
        os.makedirs(real_arch_libdir)
        open(os.path.join(real_arch_libdir, 'rbconfig.rb'), 'w').close()
        env = plugin.env('test-part-path')

        expected_env = {
            'GEM_HOME="test-part-path/lib/ruby/gems/test-version"',
            'RUBYLIB="{}:{}"'.format(libdir, arch_libdir),
            'GEM_PATH="test-part-path/lib/ruby/gems/test-version"'
        }
        self.assertThat(set(env), Equals(expected_env))
Example #13
0
    def test_pull_downloads_ruby(self):
        plugin = ruby.RubyPlugin(
            'test-part', self.options, self.project_options)

        self.assertThat(
            plugin._ruby_tar.source,
            Equals('https://cache.ruby-lang.org/pub/ruby/ruby-2.4.0.tar.gz'))
        self.assertThat(
            plugin._ruby_tar.source_dir,
            Equals(os.path.join(self.path, 'parts', 'test-part', 'ruby')))

        with mock.patch.multiple(
                plugin, _ruby_install=mock.DEFAULT, _gem_install=mock.DEFAULT):
            # We don't want to wait for the download to finish. It is already
            # tested in the Tar object tests.
            with mock.patch.object(
                    plugin._ruby_tar, 'download') as mock_download:
                plugin.pull()

        mock_download.assert_called_once_with()
Example #14
0
    def test_pull_downloads_ruby(self):
        plugin = ruby.RubyPlugin("test-part", self.options, self.project)

        self.assertThat(
            plugin._ruby_tar.source,
            Equals("https://cache.ruby-lang.org/pub/ruby/2.4/ruby-2.4.2.tar.gz"),
        )
        self.assertThat(
            plugin._ruby_tar.source_dir,
            Equals(os.path.join(self.path, "parts", "test-part", "ruby")),
        )

        with mock.patch.multiple(
            plugin, _ruby_install=mock.DEFAULT, _gem_install=mock.DEFAULT
        ):
            # We don't want to wait for the download to finish. It is already
            # tested in the Tar object tests.
            with mock.patch.object(plugin._ruby_tar, "download") as mock_download:
                plugin.pull()

        mock_download.assert_called_once_with()
Example #15
0
    def test_env_with_rbconfigs(self):
        plugin = ruby.RubyPlugin('test-part', self.options,
                                 self.project_options)
        part_dir = os.path.join(self.path, 'test-part-path')

        os.makedirs(
            os.path.join(part_dir, 'lib', 'ruby', 'gems', 'test-version'))
        libdir = os.path.join('test-part-path', 'lib', 'ruby', 'test-version')

        for arch in ('foo-linux-bar1', 'foo-linux-bar2'):
            arch_libdir1 = os.path.join(libdir, arch)
            real_arch_libdir1 = os.path.join(self.path, arch_libdir1)
            os.makedirs(real_arch_libdir1)
            open(os.path.join(real_arch_libdir1, 'rbconfig.rb'), 'w').close()

        error = self.assertRaises(
            snapcraft.internal.errors.SnapcraftEnvironmentError, plugin.env,
            'test-part-path')

        self.assertThat(str(error),
                        Equals('Expected a single rbconfig.rb, but found 2'))
Example #16
0
    def test_env_with_rbconfigs(self):
        plugin = ruby.RubyPlugin("test-part", self.options, self.project)
        part_dir = os.path.join(self.path, "test-part-path")

        os.makedirs(
            os.path.join(part_dir, "lib", "ruby", "gems", "test-version"))
        libdir = os.path.join("test-part-path", "lib", "ruby", "test-version")

        for arch in ("foo-linux-bar1", "foo-linux-bar2"):
            arch_libdir1 = os.path.join(libdir, arch)
            real_arch_libdir1 = os.path.join(self.path, arch_libdir1)
            os.makedirs(real_arch_libdir1)
            open(os.path.join(real_arch_libdir1, "rbconfig.rb"), "w").close()

        error = self.assertRaises(
            snapcraft.internal.errors.SnapcraftEnvironmentError,
            plugin.env,
            "test-part-path",
        )

        self.assertThat(str(error),
                        Equals("Expected a single rbconfig.rb, but found 2"))
Example #17
0
 def test_env_without_ruby(self):
     plugin = ruby.RubyPlugin('test-part', self.options,
                              self.project_options)
     env = plugin.env('dummy-path')
     self.assertThat(env, Equals([]))
Example #18
0
 def test_env_without_ruby(self):
     plugin = ruby.RubyPlugin("test-part", self.options, self.project)
     env = plugin.env("dummy-path")
     self.assertThat(env, Equals([]))