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 test_on_statement_invalid_grammar(self):
with testtools.ExpectedException(
grammar.errors.OnStatementSyntaxError, self.expected_exception
):
processor = grammar.GrammarProcessor(
None, snapcraft.ProjectOptions(), self.checker
)
statement = on.OnStatement(on=self.on, body=self.body, processor=processor)
for else_body in self.else_bodies:
statement.add_else(else_body)
statement.process()
def setUp(self):
super().setUp()
self.mock_options = Mock()
self.mock_options.source = "."
self.mock_options.source_subdir = None
self.mock_options.files = {}
# setup the expected target dir in our tempdir
self.dst_prefix = "parts/copy/install/"
os.makedirs(self.dst_prefix)
self.project_options = snapcraft.ProjectOptions()
def setUp(self):
super().setUp()
class props:
version = "release-beta3"
self.properties = props()
self.project = snapcraft.ProjectOptions()
patcher = mock.patch("snapcraft.plugins._ros.ros2.Bootstrapper")
self.bootstrapper_mock = patcher.start()
self.addCleanup(patcher.stop)
def test_user_agent(self):
arch = ProjectOptions().deb_arch
expected_pre = "snapcraft/{} ".format(snapcraft_version)
expected_post = " {} ({})".format(
"/".join(platform.dist()[0:2]), arch # i.e. Ubuntu/16.04
)
actual = storeapi._agent.get_user_agent()
self.assertTrue(actual.startswith(expected_pre))
self.assertTrue(actual.endswith(expected_post))
def setUp(self):
super().setUp()
self.project_options = snapcraft.ProjectOptions()
# setup the expected target dir in our tempdir
part_dir = os.path.join(self.parts_dir, "tar_content")
self.build_prefix = os.path.join(part_dir, "build")
os.makedirs(self.build_prefix)
self.install_prefix = os.path.join(part_dir, "install")
os.makedirs(self.install_prefix)
def setUp(self):
super().setUp()
self.project = snapcraft.ProjectOptions()
self.wstool = wstool.Wstool(
"package_path", "wstool_path", "sources", ["keyring"], self.project
)
patcher = mock.patch("snapcraft.repo.Ubuntu")
self.ubuntu_mock = patcher.start()
self.addCleanup(patcher.stop)
patcher = mock.patch("subprocess.check_output")
self.check_output_mock = patcher.start()
self.addCleanup(patcher.stop)
def test_cross_compiler_prefix_empty(
self, mock_platform_machine, mock_platform_architecture
):
mock_platform_machine.return_value = "x86_64"
mock_platform_architecture.return_value = ("64bit", "ELF")
options = snapcraft.ProjectOptions(target_deb_arch="i386")
self.assertThat(options.cross_compiler_prefix, Equals(""))
def test_opencv(self):
if snapcraft.ProjectOptions().deb_arch == "armhf":
self.skipTest("The autopkgtest armhf runners can't install snaps")
snap_path = self.build_snap(self.snap_content_dir)
bin_path = os.path.join(os.path.dirname(snap_path), "prime", "bin", "example")
self.assertThat(bin_path, FileExists())
interpreter = subprocess.check_output(
[self.patchelf_command, "--print-interpreter", bin_path]
).decode()
expected_interpreter = r"^/snap/.*"
self.assertThat(interpreter, MatchesRegex(expected_interpreter))
arch_triplet = snapcraft.ProjectOptions().arch_triplet
# test $ORIGIN in action
rpath = subprocess.check_output(
[self.patchelf_command, "--print-rpath", bin_path]
).decode()
expected_rpath = "$ORIGIN/../usr/lib/{}:".format(arch_triplet)
self.assertThat(rpath, Contains(expected_rpath))
# test $ORIGIN applied
ldd = subprocess.check_output(["ldd", bin_path]).decode()
expected_opencv_path = "/prime/bin/../usr/lib/{}/libopencv_core".format(
arch_triplet
)
self.assertThat(ldd, Contains(expected_opencv_path))
self.install_snap(snap_path, "opencv-example", "1.0", classic=True)
def download(
self,
snap_name,
*,
risk: str,
download_path: str,
track: str = None,
arch: str = None,
except_hash=""
):
if arch is None:
arch = snapcraft.ProjectOptions().deb_arch
snap_info = self.cpi.get_info(snap_name)
channel_mapping = snap_info.get_channel_mapping(
risk=risk, track=track, arch=arch
)
if channel_mapping.download.sha3_384 == except_hash:
return channel_mapping.download.sha3_384
try:
channel_mapping.download.verify(download_path)
except errors.StoreDownloadError:
self._download_snap(channel_mapping.download, download_path)
channel_mapping.download.verify(download_path)
return channel_mapping.download.sha3_384