Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.copy_project_to_cwd('hg-branch')
self.init_source_control()
subprocess.check_call(
['hg', 'branch', 'second'], stdout=subprocess.DEVNULL)
open('second', 'w').close()
self.commit('second', 'second')
subprocess.check_call(
['hg', 'branch', 'default'], stdout=subprocess.DEVNULL)
open('default', 'w').close()
self.commit('default', 'default')
self.run_snapcraft('pull')
self.assertThat(
os.path.join(self.parts_dir, 'mercurial', 'src', 'second'),
FileExists())
self.run_snapcraft('pull')
self.assertThat(
os.path.join(self.parts_dir, 'mercurial', 'src', 'second'),
FileExists())
def test_pull_with_pip_requirements_file(self):
self.run_snapcraft("build", "pip-requirements-file")
self.assertThat(
glob(
os.path.join(
self.parts_dir,
"python2",
"install",
"lib",
"python2*",
"site-packages",
"argparse.py",
)
)[0],
FileExists(),
)
self.assertThat(
glob(
os.path.join(
self.parts_dir,
"python3",
"install",
"lib",
"python3*",
"site-packages",
"argparse.py",
)
)[0],
FileExists(),
)
def test_use_of_source_subdir_picks_up_setup_py(self):
# Regression test for LP: #1752481
self.run_snapcraft("stage", "python-with-source-subdir")
self.assertThat(os.path.join(self.stage_dir, "bin", "hello"), FileExists())
def test_snap_filter_is_deprecated(self):
output = self.run_snapcraft(
['prime', 'snap-keyword'], 'prime-filter')
# Verify that the `snap` keyword is deprecated.
self.assertThat(
output, Contains(
"DEPRECATED: The 'snap' keyword has been replaced by 'prime'."
"\nSee http://snapcraft.io/docs/deprecation-notices/dn1 "
"for more information."))
# Verify that only the `snap1` file made it into prime (i.e. `snap2`
# was filtered out).
self.assertThat(os.path.join(self.prime_dir, 'snap1'), FileExists())
self.assertThat(
os.path.join(self.prime_dir, 'snap2'), Not(FileExists()))
def test_builtin_function_from_stage(self):
os.mkdir("stagedir")
runner = _runner.Runner(
part_properties={"override-stage": "snapcraftctl stage"},
sourcedir="sourcedir",
builddir="builddir",
stagedir="stagedir",
primedir="primedir",
builtin_functions={"stage": _fake_stage},
)
runner.stage()
self.assertThat(os.path.join("stagedir", "fake-stage"), FileExists())
def test_builtin_function_from_prime(self):
os.mkdir("primedir")
runner = _runner.Runner(
part_properties={"override-prime": "snapcraftctl prime"},
sourcedir="sourcedir",
builddir="builddir",
stagedir="stagedir",
primedir="primedir",
builtin_functions={"prime": _fake_prime},
)
runner.prime()
self.assertThat(os.path.join("primedir", "fake-prime"), FileExists())
def test_build(self):
plugin = nodejs.NodePlugin("test-part", self.options, self.project)
self.create_assets(plugin)
plugin.build()
self.assertThat(os.path.join(plugin.installdir, "bin", "run"), FileExists())
expected_env = dict(PATH=os.path.join(plugin._npm_dir, "bin"))
if self.http_proxy is not None:
expected_env["http_proxy"] = self.http_proxy
if self.https_proxy is not None:
expected_env["https_proxy"] = self.https_proxy
if self.package_manager == "npm":
expected_run_calls = [
mock.call(
[self.get_npm_cmd(plugin), "install", "--unsafe-perm"],
cwd=plugin.builddir,
env=expected_env,
),
mock.call(
[self.get_npm_cmd(plugin), "pack"],
cwd=plugin.builddir,
def test_clean_build_step_single_part(self):
self.assert_files_exist()
self.run_snapcraft(['clean', 'part1', '--step=build'])
self.assertThat(os.path.join(self.stage_bindir, 'file1'),
Not(FileExists()))
self.assertThat(os.path.join(self.stage_bindir, 'file2'), FileExists())
self.assertThat(os.path.join(self.snap_bindir, 'file1'),
Not(FileExists()))
self.assertThat(os.path.join(self.snap_bindir, 'file2'), FileExists())
self.assertThat(self.parts['part1']['builddir'], Not(DirExists()))
self.assertThat(self.parts['part1']['installdir'], Not(DirExists()))
self.assertThat(self.parts['part1']['sourcedir'], DirExists())
self.assertThat(
os.path.join(self.parts['part2']['builddir'], 'file2'),
FileExists())
self.assertThat(
os.path.join(self.parts['part2']['bindir'], 'file2'),
FileExists())
# Now try to prime again
self.run_snapcraft('prime')
self.assert_files_exist()
def test_migrate(self):
"""
The legacy bootstrap flag file gets migrated to a local state flag.
"""
with open(paths.LEGACY_BOOTSTRAP_FLAG, "w") as fd:
fd.write("")
self.configuration.migrate()
self.assertThat(paths.LEGACY_BOOTSTRAP_FLAG, Not(FileExists()))