def test_process_dependency_links(self, run_mock): self.options.process_dependency_links = True plugin = python2.Python2Plugin('test-part', self.options, self.project_options) setup_directories(plugin) plugin.pull() self.assertIn('--process-dependency-links', run_mock.call_args[0][0])
def test_pip(self, mock_run, mock_setup_pip): self.options.requirements = 'requirements.txt' self.options.constraints = 'constraints.txt' self.options.python_packages = ['test', 'packages'] plugin = python2.Python2Plugin('test-part', self.options, self.project_options) setup_directories(plugin) pip2 = os.path.join(plugin.installdir, 'usr', 'bin', 'pip2') include = os.path.join(plugin.installdir, 'usr', 'include', 'python2.7') target = os.path.join(plugin.installdir, 'usr', 'lib', 'python2.7', 'site-packages') pip_install = [ 'python2', pip2, 'install', '--global-option=build_ext', '--global-option=-I{}'.format(include), '--target', target ] 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]), mock.call(pip_install + ['--upgrade', 'test', 'packages']), mock.call(pip_install + ['.'], cwd=plugin.sourcedir) ] plugin.pull() mock_run.assert_has_calls(calls)
def test_pip(self, mock_run): self.options.requirements = 'requirements.txt' self.options.constraints = 'constraints.txt' self.options.python_packages = ['test', 'packages'] plugin = python2.Python2Plugin('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') 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_pull(self, mock_pip): plugin = python2.Python2Plugin('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_setup_pip(self, mock_run): plugin = python2.Python2Plugin('test-part', self.options, self.project_options) easy_install = os.path.join(plugin.installdir, 'usr', 'bin', 'easy_install') prefix = os.path.join(plugin.installdir, 'usr') plugin._setup_pip() mock_run.assert_called_with( ['python2', easy_install, '--prefix', prefix, 'pip'])
def test_fileset_ignores(self): plugin = python2.Python2Plugin('test-part', self.options, self.project_options) expected_fileset = [ '-usr/bin/pip*', '-**/*.pth', '-**/*.pyc', ] fileset = plugin.snap_fileset() self.assertListEqual(expected_fileset, fileset)
def test_pip_relative_site_packages_symlink(self, run_output_mock, run_mock): plugin = python2.Python2Plugin('test-part', self.options, self.project_options) setup_directories(plugin) plugin._pip() link = os.readlink(os.path.join(plugin.installdir, 'usr', 'lib', 'python2.7', 'site-packages')) self.assertEqual(link, 'dist-packages', 'Expected site-packages to be a relative link to ' '"dist-packages", but it was a link to "{}"' .format(link))
def test_pip_relative_site_packages_symlink(self, run_output_mock, run_mock): plugin = python2.Python2Plugin('test-part', self.options) os.makedirs(plugin.sourcedir) os.makedirs(os.path.join(plugin.installdir, 'usr', 'lib', 'python2.7', 'dist-packages')) open(os.path.join(plugin.sourcedir, 'setup.py'), 'w').close() plugin._pip() link = os.readlink(os.path.join(plugin.installdir, 'usr', 'lib', 'python2.7', 'site-packages')) self.assertEqual(link, 'dist-packages', 'Expected site-packages to be a relative link to ' '"dist-packages", but it was a link to "{}"' .format(link))
def test_env(self, mock_path): mock_path.side_effect = [ '/testpath', EnvironmentError('test path does not exist'), ] plugin = python2.Python2Plugin('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_fileset_ignores(self): plugin = python2.Python2Plugin('test-part', self.options, self.project_options) expected_fileset = [ '-usr/bin/pip*', '-usr/lib/python*/dist-packages/easy-install.pth', '-usr/lib/python*/dist-packages/__pycache__/*.pyc', '-usr/lib/python*/*.pyc', '-usr/lib/python*/*/*.pyc', '-usr/lib/python*/*/*/*.pyc', '-usr/lib/python*/*/*/*/*.pyc', '-usr/lib/python*/*/*/*/*/*.pyc', '-usr/lib/python*/*/*/*/*/*/*.pyc', '-usr/lib/python*/*/*/*/*/*/*/*.pyc', '-usr/lib/python*/*/*/*/*/*/*/*/*.pyc', '-usr/lib/python*/*/*/*/*/*/*/*/*/*.pyc', '-usr/lib/python*/*/*/*/*/*/*/*/*/*/*.pyc', ] fileset = plugin.snap_fileset() self.assertListEqual(expected_fileset, fileset)
def test_build_fixes_python_shebangs(self, run_mock): plugin = python2.Python2Plugin('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')) os.makedirs(os.path.join( plugin.installdir, 'usr', 'lib', 'python2', 'dist-packages')) os.makedirs(os.path.join( plugin.installdir, 'usr', 'include', 'python2')) # 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'])
def test_check_version(self): plugin = python2.Python2Plugin('test-part', self.options, self.project_options) self.assertEqual(plugin.options.python_version, 'python2')
def test_missing_setup_path(self, mock_path_exists, mock_run): plugin = python2.Python2Plugin('test-part', self.options, self.project_options) setup_directories(plugin) plugin.pull() self.assertFalse(mock_run.called)
def test_pull(self, mock_pip): plugin = python2.Python2Plugin('test-part', self.options, self.project_options) plugin.pull() self.assertTrue(mock_pip.called)
def test_check_version(self): plugin = python2.Python2Plugin("test-part", self.options, self.project_options) self.assertThat(plugin.options.python_version, Equals("python2"))