Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_git(self):
if snapcraft.ProjectOptions().deb_arch == 'armhf':
self.skipTest("Snaps can't yet be installed in a lxc container.")
# Building classic snaps require the core snap to be installed
self.install_store_snap('core')
self.build_snap(self.snap_content_dir)
# TODO reenable git once snap-confine and snapd bits are in place
def run_test(self):
lifecycle.execute(
self.initial_step, self.project_config, part_names=self.initial_parts
)
initial_order = self.get_run_order()
self.assert_run_order_equal(initial_order, self.expected_initial, "(initial)")
lifecycle.execute(
self.test_step, self.project_config, part_names=self.test_parts
)
current_order = self.get_run_order()
test_order = [o for o in current_order if o not in initial_order]
self.assert_run_order_equal(test_order, self.expected_test, "(test)")
self.assert_parts_cleaned(
initial_order, current_order, self.expected_test_cleaned, "(cleaned)"
def test_no_name(self):
release = os_release.OsRelease(
os_release_file=self._write_os_release(
dedent(
"""\
ID=arch
PRETTY_NAME="Arch Linux"
ID_LIKE=archlinux
VERSION_ID="foo"
VERSION_CODENAME="bar"
"""
)
)
)
self.assertRaises(errors.OsReleaseNameError, release.name)
def test_prime_with_invalid_image_info_raises_exception(self):
self.useFixture(fixtures.EnvironmentVariable("SNAPCRAFT_BUILD_INFO", "1"))
self.useFixture(
fixtures.EnvironmentVariable("SNAPCRAFT_IMAGE_INFO", "not-json")
)
project_config = self.make_snapcraft_project(
textwrap.dedent(
"""\
parts:
test-part:
plugin: nil
"""
)
)
raised = self.assertRaises(
errors.InvalidContainerImageInfoError,
lifecycle.execute,
steps.PRIME,
project_config,
)
self.assertThat(raised.image_info, Equals("not-json"))
def test_unsupported_base(self):
project = snapcraft.project.Project(
snapcraft_yaml_file_path=self.make_snapcraft_yaml(
textwrap.dedent(
"""\
name: make-snap
base: unsupported-base
"""
)
)
)
raised = self.assertRaises(
errors.PluginBaseError, make.MakePlugin, "test-part", self.options, project
)
self.assertThat(raised.part_name, Equals("test-part"))
self.assertThat(raised.base, Equals("unsupported-base"))
def test_unsupported_base_raises(self):
self.assertRaises(
errors.PluginBaseError,
meson.MesonPlugin,
"test-part",
self.options,
self.project,
)
def test_known_module_but_unknown_plugin_must_raise_exception(self):
fake_logger = fixtures.FakeLogger(level=logging.ERROR)
self.useFixture(fake_logger)
path = copy.copy(sys.path)
# "_ros" is a valid module within the plugin path, but contains no
# plugins.
raised = self.assertRaises(
errors.PluginError, self.load_part, "fake-part", "_ros"
)
self.assertThat(raised.message, Equals("no plugin found in module '_ros'"))
# Make sure that nothing was added to sys.path.
self.assertThat(path, Equals(sys.path))
def setUp(self):
super().setUp()
patcher = mock.patch("snapcraft.project.Project")
patcher.start()
self.addCleanup(patcher.stop)
# Special handling is required as ProjectOptions attributes are
# handled with the @property decorator.
project_options_t = type(snapcraft.project.Project.return_value)
for key in self._kwargs:
setattr(project_options_t, key, self._kwargs[key])
base: core18
version: "1.0"
summary: test
description: test
confinement: strict
grade: stable
{type}
{parts}
"""
)
self.snapcraft_yaml_file_path = self.make_snapcraft_yaml(
yaml.format(parts=parts, type=snap_type)
)
project = snapcraft.project.Project(
snapcraft_yaml_file_path=self.snapcraft_yaml_file_path
)
return project_loader.load_config(project)
def _make_snapcraft_project(self):
yaml = textwrap.dedent(
"""\
name: test
base: core18
version: "1.0"
summary: test
description: test
confinement: strict
grade: stable
"""
)
snapcraft_yaml_file_path = self.make_snapcraft_yaml(yaml)
project = snapcraft.project.Project(
snapcraft_yaml_file_path=snapcraft_yaml_file_path
)
return project