Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
file_path = _create_file(
"file",
textwrap.dedent(
"""\
#!/usr/bin/env python3.5
'''
This is a test
=======================
"""
),
)
mangling.rewrite_python_shebangs(os.path.dirname(file_path))
self.assertThat(
file_path,
FileContains(
textwrap.dedent(
"""\
#!/usr/bin/env python3.5
def test_prime_with_non_ascii_desktop_file(self):
# Originally, in this test we forced LC_ALL=C. However, now that we
# are using the click python library we can't do it because it fails
# to run any command when the system language is ascii.
# --20170518 - elopio
self.run_snapcraft('prime', 'desktop-with-non-ascii')
desktop_path = os.path.join(
self.prime_dir, 'meta', 'gui', 'test-app.desktop')
self.expectThat(
desktop_path, FileContains(matcher=Contains('non ascíí')))
def test_environment(self):
self.run_snapcraft('stage', 'snapcraft-environment')
part_install_dir = os.path.join(self.path,
self.parts_dir, 'env', 'install')
test_name = os.path.join(self.stage_dir, 'test_name')
self.assertThat(test_name, FileContains('test-environment'))
test_version = os.path.join(self.stage_dir, 'test_version')
self.assertThat(test_version, FileContains('0.1'))
test_stage = os.path.join(self.stage_dir, 'test_stage')
self.assertThat(
test_stage, FileContains(os.path.join(self.path, self.stage_dir)))
test_part_install = os.path.join(
self.path, self.stage_dir, 'test_part_install')
self.assertThat(test_part_install, FileContains(part_install_dir))
name = self.get_unique_name()
version = self.get_unique_version()
self.copy_project_to_cwd(self.project)
self.update_name_and_version(name, version)
self.run_snapcraft("snap")
snap_path = "{}_{}_{}.snap".format(name, version, "all")
self.assertThat(snap_path, FileExists())
self.register(name)
status = self.sign_build(snap_path, local=True)
self.assertThat(status, Equals(0))
snap_build_path = "{}-build".format(snap_path)
self.assertThat(snap_build_path, FileExists())
self.assertThat(
snap_build_path, FileContains(matcher=Contains("type: snap-build"))
)
self.fake_snapd.snaps_result = [
{
"id": "fake-snap-id",
"name": "fake-snap",
"channel": "stable",
"revision": "x1",
}
]
snap_pkg = snaps.SnapPackage("fake-snap/strict/stable")
snap_pkg.local_download(
snap_path="fake-snap.snap", assertion_path="fake-snap.assert"
)
self.assertThat("fake-snap.snap", FileExists())
self.assertThat("fake-snap.assert", FileContains(""))
fake_get_assertion.mock.assert_not_called()
exec_prefix=${{prefix}}
libdir=${{prefix}}/lib
includedir=${{prefix}}/include
Name: granite
Description: elementary's Application Framework
Version: 0.4
Libs: -L${{libdir}} -lgranite
Cflags: -I${{includedir}}/granite
Requires: cairo gee-0.8 glib-2.0 gio-unix-2.0 gobject-2.0
""".format(
self.tempdir
)
)
self.assertThat(pc_file, FileContains(expected_pc_file_content))
def test_command_relative_command_found_in_slash(self):
cmd = command.Command(app_name="foo", command_name="command", command="sh")
cmd.prime_command(
can_use_wrapper=True, massage_command=True, prime_dir=self.path
)
wrapper_path = cmd.write_wrapper(prime_dir=self.path)
self.expectThat(cmd.command, Equals("command-foo.wrapper"))
self.assertThat(wrapper_path, FileExists())
self.assertThat(wrapper_path, FileContains('#!/bin/sh\nexec /bin/sh "$@"\n'))
self.assertThat(
self.fake_logger.output.strip(),
Equals(
"The command 'sh' was not found in the prime directory, it has "
"been changed to '/bin/sh'."
def test_generate_desktop_file(self):
d = DesktopFile(
snap_name=self.snap_name,
app_name=self.app_name,
filename=self.desktop_file_path,
prime_dir=self.path,
)
try:
d.write(icon_path=self.icon_path, gui_dir=".")
except AttributeError:
d.write(gui_dir=".")
self.assertThat(self.expected_desktop_file, FileExists())
self.assertThat(
self.expected_desktop_file,
FileContains(
dedent(
"""\
[Desktop Entry]
Exec=foo
Icon={}
""".format(
self.expected_icon
)
part_properties={"override-build": "echo $PATH > path"},
sourcedir="sourcedir",
builddir="builddir",
stagedir="stagedir",
primedir="primedir",
builtin_functions={},
)
runner.build()
expected_path_segment = "/snap/snapcraft/current/bin/scriptlet-bin"
self.assertThat(os.path.join("builddir", "path"), FileExists())
self.assertThat(
os.path.join("builddir", "path"),
FileContains(matcher=Contains(expected_path_segment)),
)
def test_environment(self):
self.run_snapcraft("stage", "snapcraft-environment")
part_install_dir = os.path.join(self.path, self.parts_dir, "env", "install")
test_name = os.path.join(self.stage_dir, "test_name")
self.assertThat(test_name, FileContains("test-environment"))
test_version = os.path.join(self.stage_dir, "test_version")
self.assertThat(test_version, FileContains("0.1"))
test_stage = os.path.join(self.stage_dir, "test_stage")
self.assertThat(
test_stage, FileContains(os.path.join(self.path, self.stage_dir))
)
test_part_install = os.path.join(self.path, self.stage_dir, "test_part_install")
self.assertThat(test_part_install, FileContains(part_install_dir))