def test_pull_with_requirements(self): self.options.requirements = ["requirements.txt"] self.options.python_packages = ["test", "packages"] plugin = python.PythonPlugin("test-part", self.options, self.project) setup_directories(plugin, self.options.python_version) requirements_path = os.path.join(plugin.sourcedir, "requirements.txt") open(requirements_path, "w").close() plugin.pull() pip_download = self.mock_pip.return_value.download pip_download.assert_called_once_with( ["test", "packages"], constraints=set(), process_dependency_links=False, requirements={requirements_path}, setup_py_dir=None, ) self.mock_pip.return_value.wheel.assert_not_called() self.mock_pip.return_value.install.assert_not_called()
def test_plugin_stage_packages_python3(self): self.options.python_version = "python3" plugin = python.PythonPlugin("test-part", self.options, self.project) self.assertThat(plugin.plugin_stage_packages, Equals(["python3"]))
def test_build(self, mock_base_build): self.options.requirements = ["requirements.txt"] self.options.constraints = ["constraints.txt"] self.options.python_packages = ["test", "packages"] packages = collections.OrderedDict() packages["yaml"] = "1.2" packages["extras"] = "1.0" self.mock_pip.return_value.list.return_value = packages self.useFixture(fixture_setup.CleanEnvironment()) plugin = python.PythonPlugin("test-part", self.options, self.project) setup_directories(plugin, self.options.python_version) for file_name in self.options.requirements + self.options.constraints: path = os.path.join(plugin.sourcedir, file_name) open(path, "w").close() requirements_path = os.path.join(plugin.builddir, "requirements.txt") constraints_path = os.path.join(plugin.builddir, "constraints.txt") def build_side_effect(): open(os.path.join(plugin.builddir, "setup.py"), "w").close() os.mkdir(os.path.join(plugin.builddir, "dist")) open(os.path.join(plugin.builddir, "dist", "package.tar"), "w").close() open(requirements_path, "w").close() open(constraints_path, "w").close() mock_base_build.side_effect = build_side_effect pip_wheel = self.mock_pip.return_value.wheel pip_wheel.return_value = ["foo", "bar"] plugin.build() # Pip should not attempt to download again in build (only pull) pip_download = self.mock_pip.return_value.download pip_download.assert_not_called() pip_wheel.assert_called_once_with( ["test", "packages"], constraints={constraints_path}, process_dependency_links=False, requirements={requirements_path}, setup_py_dir=None, ) pip_install = self.mock_pip.return_value.install self.assertThat(pip_install.call_count, Equals(2)) pip_install.assert_has_calls([ mock.call( ["foo", "bar"], process_dependency_links=False, upgrade=True, install_deps=False, ), mock.call( [], setup_py_dir=plugin.builddir, constraints={constraints_path}, process_dependency_links=False, upgrade=True, ), ])