def test_no_python_packages_does_nothing(self): # This should be an error but given that we default to # 'source: .' and now that pip 10 has been released # we run into the need of fixing this situation. self.mock_pip.return_value.list.return_value = dict() self.useFixture(fixture_setup.CleanEnvironment()) plugin = python.PythonPlugin("test-part", self.options, self.project) setup_directories(plugin, self.options.python_version, create_setup_py=False) pip_wheel = self.mock_pip.return_value.wheel pip_wheel.return_value = [] 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( [], constraints=set(), process_dependency_links=False, requirements=set(), setup_py_dir=None, ) pip_install = self.mock_pip.return_value.install pip_install.assert_not_called()
def setUp(self): super().setUp() class Options: source = "." nodejs_version = nodejs._NODEJS_VERSION nodejs_package_manager = "npm" nodejs_yarn_version = "" source = "." self.options = Options() # always have a package.json stub under source open("package.json", "w").close() patcher = mock.patch("snapcraft.internal.common.run") self.run_mock = patcher.start() self.addCleanup(patcher.stop) patcher = mock.patch("snapcraft.internal.common.run_output") self.run_output_mock = patcher.start() self.addCleanup(patcher.stop) self.run_output_mock.return_value = '{"dependencies": []}' patcher = mock.patch("snapcraft.sources.Tar") self.tar_mock = patcher.start() self.addCleanup(patcher.stop) self.nodejs_url = nodejs.get_nodejs_release( nodejs._NODEJS_VERSION, self.project.deb_arch ) self.useFixture(fixture_setup.CleanEnvironment())
def setUp(self): super().setUp() class Options: configflags = [] source_subdir = None make_parameters = [] disable_parallel = False build_snaps = [] self.options = Options() self.project = snapcraft.project.Project( snapcraft_yaml_file_path=self.make_snapcraft_yaml( textwrap.dedent("""\ name: make-snap base: core16 """))) patcher = mock.patch("snapcraft.internal.common.run") self.run_mock = patcher.start() self.addCleanup(patcher.stop) self.useFixture(fixture_setup.CleanEnvironment())
def setUp(self): super().setUp() class Options: configflags = [] source_subdir = None # inherited from MakePlugin makefile = None make_parameters = [] make_install_var = "DESTDIR" disable_parallel = False artifacts = [] self.options = Options() self.project = snapcraft.project.Project( snapcraft_yaml_file_path=self.make_snapcraft_yaml( textwrap.dedent("""\ name: make-snap base: core16 """))) patcher = mock.patch("snapcraft.internal.common.run") self.run_mock = patcher.start() self.addCleanup(patcher.stop) patcher = mock.patch("sys.stdout") patcher.start() self.addCleanup(patcher.stop) self.useFixture(fixture_setup.CleanEnvironment())
def setUp(self): super().setUp() self.useFixture(fixture_setup.CleanEnvironment()) class Options: makefile = None make_parameters = [] rust_features = [] rust_revision = "" rust_channel = "" source_subdir = "" self.options = Options() patcher = mock.patch("snapcraft.internal.common.run") self.run_mock = patcher.start() self.addCleanup(patcher.stop) patcher = mock.patch("snapcraft.internal.common.run_output") patcher.start() self.addCleanup(patcher.stop) original_exists = os.path.exists def exists_mock(*args, **kwargs): if args[0].endswith("rustup"): return False else: return original_exists(args[0]) patcher = mock.patch("os.path.exists", side_effect=exists_mock) patcher.start() self.addCleanup(patcher.stop)
def setUp(self): super().setUp() self.useFixture(fixture_setup.CleanEnvironment()) patcher = mock.patch("sys.stdout") patcher.start() self.addCleanup(patcher.stop)
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_options) 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=plugin.builddir, ) pip_install = self.mock_pip.return_value.install pip_install.assert_called_once_with( ["foo", "bar"], process_dependency_links=False, upgrade=True, install_deps=False, )
def test_build_with_provider_stage_dir(self): self.useFixture(fixture_setup.CleanEnvironment()) plugin = plainbox_provider.PlainboxProviderPlugin( 'test-part', self.options, self.project_options) os.makedirs(plugin.sourcedir) provider_path = os.path.join(self.project_options.stage_dir, 'providers', 'test-provider') os.makedirs(provider_path) # Place a few files with bad shebangs, and some files that shouldn't be # changed. files = [{ 'path': os.path.join(plugin.installdir, 'baz'), 'contents': '#!/foo/bar/baz/python3', 'expected': '#!/usr/bin/env python3', }, { 'path': os.path.join(plugin.installdir, 'bin', 'foobar'), 'contents': '#!/foo/baz/python3.5', 'expected': '#!/usr/bin/env python3.5', }, { 'path': os.path.join(plugin.installdir, 'foo'), 'contents': 'foo', 'expected': 'foo', }, { 'path': os.path.join(plugin.installdir, 'bar'), 'contents': 'bar\n#!/usr/bin/python3', 'expected': 'bar\n#!/usr/bin/python3', }] for file_info in files: os.makedirs(os.path.dirname(file_info['path']), exist_ok=True) with open(file_info['path'], 'w') as f: f.write(file_info['contents']) plugin.build() calls = [ mock.call(['python3', 'manage.py', 'validate'], env={'PROVIDERPATH': provider_path}), mock.call(['python3', 'manage.py', 'build']), mock.call(['python3', 'manage.py', 'i18n']), mock.call([ 'python3', 'manage.py', 'install', '--layout=relocatable', '--prefix=/providers/test-part', '--root={}'.format(plugin.installdir) ]), ] self.mock_run.assert_has_calls(calls) for file_info in files: with open(os.path.join(plugin.installdir, file_info['path']), 'r') as f: self.assertThat(f.read(), Equals(file_info['expected']))
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_options) 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=plugin.builddir) pip_install = self.mock_pip.return_value.install pip_install.assert_called_once_with(['foo', 'bar'], process_dependency_links=False, upgrade=True, install_deps=False)
def test_build(self, platform_machine_mock, platform_architecture_mock): self.useFixture(fixture_setup.CleanEnvironment()) self.useFixture(fixtures.EnvironmentVariable("PATH", "/bin")) class Options: source = "." gulp_tasks = [] node_engine = "4" platform_machine_mock.return_value = "x86_64" platform_architecture_mock.return_value = ("64bit", "ELF") plugin = gulp.GulpPlugin("test-part", Options(), self.project_options) os.makedirs(plugin.builddir) open(os.path.join(plugin.builddir, "package.json"), "w").close() plugin.build() path = "{}:/bin".format(os.path.join(plugin._npm_dir, "bin")) self.run_mock.assert_has_calls([ mock.call( ["npm", "install", "-g", "gulp-cli"], cwd=plugin.builddir, env={ "PATH": path, "NPM_CONFIG_PREFIX": plugin._npm_dir }, ), mock.call( ["npm", "install", "--only-development"], cwd=plugin.builddir, env={ "PATH": path, "NPM_CONFIG_PREFIX": plugin._npm_dir }, ), ]) self.tar_mock.assert_has_calls([ mock.call( nodejs.get_nodejs_release(plugin.options.node_engine, plugin.project.deb_arch), os.path.join(plugin._npm_dir), ), mock.call().provision(plugin._npm_dir, clean_target=False, keep_tarball=True), ])
def setUp(self): super().setUp() self.useFixture(fixture_setup.CleanEnvironment()) class Options: makefile = None make_parameters = [] rust_features = [] rust_revision = "" rust_channel = "" source_subdir = "" self.options = Options() patcher = mock.patch("snapcraft.internal.common.run") self.run_mock = patcher.start() self.addCleanup(patcher.stop) patcher = mock.patch("snapcraft.internal.common.run_output") patcher.start() self.addCleanup(patcher.stop) original_exists = os.path.exists def exists_mock(*args, **kwargs): if args[0].endswith("rustup"): return False else: return original_exists(args[0]) patcher = mock.patch("os.path.exists", side_effect=exists_mock) patcher.start() self.addCleanup(patcher.stop) self.project = snapcraft.project.Project( snapcraft_yaml_file_path=self.make_snapcraft_yaml( textwrap.dedent("""\ name: test-snap base: core16 """))) self.plugin = rust.RustPlugin("test-part", self.options, self.project) os.makedirs(self.plugin.sourcedir) os.makedirs(self.plugin.builddir) open(Path(self.plugin.builddir, "Cargo.toml"), "w").write("")
def setUp(self): super().setUp() self.useFixture(fixture_setup.CleanEnvironment()) self.project_options = snapcraft.ProjectOptions() patcher = mock.patch("snapcraft.internal.common.run") self.run_mock = patcher.start() self.addCleanup(patcher.stop) patcher = mock.patch("snapcraft.internal.common.run_output") self.run_output_mock = patcher.start() self.addCleanup(patcher.stop) patcher = mock.patch("sys.stdout") patcher.start() self.addCleanup(patcher.stop)
def setUp(self): super().setUp() class Options: configflags = [] source_subdir = None make_parameters = [] disable_parallel = False build_snaps = [] self.options = Options() patcher = mock.patch("snapcraft.internal.common.run") self.run_mock = patcher.start() self.addCleanup(patcher.stop) self.useFixture(fixture_setup.CleanEnvironment())
def test_build(self, platform_machine_mock, platform_architecture_mock): self.useFixture(fixture_setup.CleanEnvironment()) self.useFixture(fixtures.EnvironmentVariable( 'PATH', '/bin')) class Options: source = '.' gulp_tasks = [] node_engine = '4' platform_machine_mock.return_value = 'x86_64' platform_architecture_mock.return_value = ('64bit', 'ELF') plugin = gulp.GulpPlugin('test-part', Options(), self.project_options) os.makedirs(plugin.builddir) open(os.path.join(plugin.builddir, 'package.json'), 'w').close() plugin.build() path = '{}:/bin'.format(os.path.join(plugin._npm_dir, 'bin')) self.run_mock.assert_has_calls([ mock.call(['npm', 'install', '-g', 'gulp-cli'], cwd=plugin.builddir, env={'PATH': path, 'NPM_CONFIG_PREFIX': plugin._npm_dir}), mock.call(['npm', 'install', '--only-development'], cwd=plugin.builddir, env={'PATH': path, 'NPM_CONFIG_PREFIX': plugin._npm_dir}), ]) self.tar_mock.assert_has_calls([ mock.call( nodejs.get_nodejs_release( plugin.options.node_engine, plugin.project.deb_arch), os.path.join(plugin._npm_dir)), mock.call().provision( plugin._npm_dir, clean_target=False, keep_tarball=True)])
def setUp(self): super().setUp() class Options: source = '.' node_packages = [] node_engine = nodejs._NODEJS_VERSION npm_run = [] npm_flags = [] node_package_manager = 'npm' source = '.' self.options = Options() self.project_options = snapcraft.ProjectOptions() self.useFixture(fixture_setup.CleanEnvironment()) patcher = mock.patch('snapcraft.internal.common.run') self.run_mock = patcher.start() self.addCleanup(patcher.stop) patcher = mock.patch('snapcraft.internal.common.run_output') self.run_output_mock = patcher.start() self.addCleanup(patcher.stop) self.run_output_mock.return_value = '{"dependencies": []}' patcher = mock.patch('snapcraft.sources.Tar') self.tar_mock = patcher.start() self.addCleanup(patcher.stop) patcher = mock.patch('sys.stdout') patcher.start() self.addCleanup(patcher.stop) self.nodejs_url = nodejs.get_nodejs_release( nodejs._NODEJS_VERSION, self.project_options.deb_arch)
def test_build_with_provider_stage_dir(self): self.useFixture(fixture_setup.CleanEnvironment()) plugin = plainbox_provider.PlainboxProviderPlugin( "test-part", self.options, self.project) os.makedirs(plugin.sourcedir) provider_path = os.path.join(self.project.stage_dir, "providers", "test-provider") os.makedirs(provider_path) # Place a few files with bad shebangs, and some files that shouldn't be # changed. files = [ { "path": os.path.join(plugin.installdir, "baz"), "contents": "#!/foo/bar/baz/python3", "expected": "#!/usr/bin/env python3", }, { "path": os.path.join(plugin.installdir, "bin", "foobar"), "contents": "#!/foo/baz/python3.5", "expected": "#!/usr/bin/env python3.5", }, { "path": os.path.join(plugin.installdir, "foo"), "contents": "foo", "expected": "foo", }, { "path": os.path.join(plugin.installdir, "bar"), "contents": "bar\n#!/usr/bin/python3", "expected": "bar\n#!/usr/bin/python3", }, ] for file_info in files: os.makedirs(os.path.dirname(file_info["path"]), exist_ok=True) with open(file_info["path"], "w") as f: f.write(file_info["contents"]) plugin.build() calls = [ mock.call( ["python3", "manage.py", "validate"], env={"PROVIDERPATH": provider_path}, ), mock.call(["python3", "manage.py", "build"]), mock.call(["python3", "manage.py", "i18n"]), mock.call([ "python3", "manage.py", "install", "--layout=relocatable", "--prefix=/providers/test-part", "--root={}".format(plugin.installdir), ]), ] self.mock_run.assert_has_calls(calls) for file_info in files: with open(os.path.join(plugin.installdir, file_info["path"]), "r") as f: self.assertThat(f.read(), Equals(file_info["expected"]))