Exemple #1
0
 def test_process_dependency_links(self, run_mock):
     self.options.process_dependency_links = True
     plugin = python3.Python3Plugin('test-part', self.options,
                                    self.project_options)
     setup_directories(plugin)
     plugin.pull()
     self.assertIn('--process-dependency-links', run_mock.call_args[0][0])
Exemple #2
0
    def test_build_fixes_python_shebangs(self, run_mock):
        plugin = python3.Python3Plugin('test-part', self.options,
                                       self.project_options)
        os.makedirs(plugin.sourcedir)
        open(os.path.join(plugin.sourcedir, 'setup.py'), 'w').close()
        os.makedirs(os.path.join(plugin.installdir, 'bin'))

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

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

        plugin.build()

        for file_info in files:
            with open(os.path.join(plugin.installdir, file_info['path']),
                      'r') as f:
                self.assertEqual(f.read(), file_info['expected'])
Exemple #3
0
    def test_pip(self, mock_run):
        self.options.requirements = 'requirements.txt'
        self.options.constraints = 'constraints.txt'
        self.options.python_packages = ['test', 'packages']

        plugin = python3.Python3Plugin('test-part', self.options,
                                       self.project_options)
        setup_directories(plugin)

        pip_install = [
            'pip', 'install', '--user', '--no-compile',
            '--disable-pip-version-check'
        ]
        requirements_path = os.path.join(plugin.sourcedir, 'requirements.txt')
        constraints_path = os.path.join(plugin.sourcedir, 'constraints.txt')
        pip_install = pip_install + ['--constraint', constraints_path]

        calls = [
            mock.call(pip_install + ['--requirement', requirements_path],
                      env=mock.ANY),
            mock.call(pip_install + ['test', 'packages'], env=mock.ANY),
            mock.call(pip_install + ['.'], cwd=plugin.sourcedir, env=mock.ANY),
        ]
        plugin.pull()
        mock_run.assert_has_calls(calls)
    def test_pip(self, mock_run):
        self.options.requirements = 'requirements.txt'
        self.options.python_packages = ['test', 'packages']

        plugin = python3.Python3Plugin('test-part', self.options,
                                       self.project_options)

        easy_install = os.path.join(plugin.installdir, 'usr', 'bin',
                                    'easy_install3')
        prefix = os.path.join(plugin.installdir, 'usr')

        pip3 = os.path.join(plugin.installdir, 'usr', 'bin', 'pip3')
        pip_install = [
            'python3', pip3, 'install', '--root', plugin.installdir,
            '--install-option=--prefix=usr'
        ]
        requirements_path = os.path.join(plugin.sourcedir, 'requirements.txt')
        calls = [
            mock.call(['python3', easy_install, '--prefix', prefix, 'pip']),
            mock.call(pip_install + ['--requirement', requirements_path]),
            mock.call(pip_install + ['--upgrade', 'test', 'packages']),
            mock.call(pip_install + ['.'], cwd=plugin.sourcedir)
        ]
        setup_directories(plugin)
        plugin._pip()
        mock_run.assert_has_calls(calls)
Exemple #5
0
 def test_pull(self, mock_pip):
     plugin = python3.Python3Plugin('test-part', self.options,
                                    self.project_options)
     plugin.pull()
     # mock_pip should not be called as there is no setup.py,
     # requirements or python-packages defined.
     self.assertFalse(mock_pip.called)
 def test_fileset_ignores(self):
     plugin = python3.Python3Plugin('test-part', self.options,
                                    self.project_options)
     expected_fileset = [
         '-usr/bin/pip*',
         '-**/*.pth',
         '-**/__pycache__',
     ]
     fileset = plugin.snap_fileset()
     self.assertListEqual(expected_fileset, fileset)
Exemple #7
0
    def test_env(self):
        plugin = python3.Python3Plugin('test-part', self.options,
                                       self.project_options)
        expected_env = [
            'PYTHONUSERBASE=/testpath',
            'PYTHONHOME=/testpath/usr',
        ]
        env = plugin.env('/testpath')
        self.assertListEqual(expected_env, env)

        env_missing_path = plugin.env('/testpath')
        self.assertTrue('PYTHONPATH=/testpath' not in env_missing_path)
    def test_env(self):
        plugin = python3.Python3Plugin('test-part', self.options,
                                       self.project_options)
        expected_env = [
            'PYTHONPATH=/testpath/usr/lib/python3.5/dist-packages',
            'CPPFLAGS="-I/testpath/usr/include $CPPFLAGS"',
            'CFLAGS="-I/testpath/usr/include $CFLAGS"',
        ]
        env = plugin.env('/testpath')
        self.assertListEqual(expected_env, env)

        env_missing_path = plugin.env('/testpath')
        self.assertTrue('PYTHONPATH=/testpath' not in env_missing_path)
Exemple #9
0
    def test_pip_relative_site_packages_symlink(self, run_output_mock,
                                                run_mock):
        plugin = python3.Python3Plugin('test-part', self.options)
        os.makedirs(plugin.sourcedir)
        os.makedirs(os.path.join(plugin.installdir, 'usr', 'lib', 'python3.4'))
        os.makedirs(
            os.path.join(plugin.installdir, 'usr', 'lib', 'python3',
                         'dist-packages'))

        open(os.path.join(plugin.sourcedir, 'setup.py'), 'w').close()

        plugin._pip()

        link = os.readlink(
            os.path.join(plugin.installdir, 'usr', 'lib', 'python3.4',
                         'site-packages'))
        expected = os.path.join('..', 'python3', 'dist-packages')
        self.assertEqual(
            link, expected, 'Expected site-packages to be a relative link to '
            '"{}", but it was a link to "{}"'.format(expected, link))
Exemple #10
0
 def test_check_version(self):
     plugin = python3.Python3Plugin('test-part', self.options,
                                    self.project_options)
     self.assertThat(plugin.options.python_version, Equals('python3'))
Exemple #11
0
 def test_missing_setup_path(self, mock_path_exists, mock_run):
     plugin = python3.Python3Plugin('test-part', self.options,
                                    self.project_options)
     setup_directories(plugin)
     plugin.pull()
     self.assertFalse(mock_run.called)
Exemple #12
0
 def test_pull(self, mock_pip):
     plugin = python3.Python3Plugin('test-part', self.options,
                                    self.project_options)
     plugin.pull()
     self.assertTrue(mock_pip.called)