Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _check_output_presence(self, spec):
outspec = spec.get('outputs', {})
unmatched_output = []
for ospec_id in outspec:
ospec = outspec[ospec_id]
ospectype = ospec['type']
if ospectype == 'file':
self.assertThat(
ospec['value'],
Annotate('expected output file missing', FileExists()))
elif ospectype == 'directory':
self.assertThat(
ospec['value'],
Annotate('expected output directory missing', DirExists()))
elif ospectype == 'string' and ospec_id.startswith('tests'):
execinfo = self._details['exec_info']
sec, idx, field = ospec_id.split('::')
for f, matcher in __spec_matchers__.iteritems():
if f in ospec:
# allow for multiple target values (given a matcher) being
# specified. For some matchers it might make no sense
# (e.g. "endswith")
targets = ospec[f]
for target in (targets if isinstance(targets, list) else [targets]):
target = unicode.replace(target, "", os.linesep)
# TODO: This replacement may be should be done elsewhere
# to have a general solution. It's now affecting string-type only.
# Additionally, "" may appear in some output intentionally,
# so let's find sth closer to be 'unique'.
self.assertThat(
def test_clean_stage_step(self):
self.assert_files_exist()
self.run_snapcraft(['clean', '--step=stage'])
self.assertThat(self.stage_dir, Not(DirExists()))
self.assertThat(self.prime_dir, Not(DirExists()))
self.assertThat(self.parts_dir, DirExists())
# Now try to prime again
self.run_snapcraft('prime')
self.assert_files_exist()
def test_build_one_part_only_from_3(self):
parts = self.make_snapcraft_yaml("build", n=3)
result = self.run_command(["build", "build1"])
self.assertThat(result.exit_code, Equals(0))
self.assertThat(self.parts_dir, DirExists())
self.assertThat(parts[1]["part_dir"], DirExists())
self.verify_state("build1", parts[1]["state_dir"], "build")
for i in [0, 2]:
self.assertThat(parts[i]["part_dir"], Not(DirExists()))
self.assertThat(parts[i]["state_dir"], Not(DirExists()))
def test_partial_clean(self):
parts = self.make_snapcraft_yaml(n=3)
result = self.run_command(["clean", "clean0", "clean2"])
self.assertThat(result.exit_code, Equals(0))
self.assertThat(self.parts_dir, DirExists())
self.assertThat(self.stage_dir, DirExists())
self.assertThat(self.prime_dir, DirExists())
for i in [0, 2]:
self.assertThat(parts[i]["part_dir"], Not(DirExists()))
# Now clean it the rest of the way
result = self.run_command(["clean", "clean1"])
self.assertThat(result.exit_code, Equals(0))
self.assertThat(self.parts_dir, Not(DirExists()))
self.assertThat(self.stage_dir, Not(DirExists()))
self.assertThat(self.prime_dir, Not(DirExists()))
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_start_instance(self):
provider = ProviderImpl(project=self.project, echoer=self.echoer_mock)
provider.launch_instance()
provider.launch_mock.assert_not_called()
provider.start_mock.assert_any_call()
provider.run_mock.assert_not_called()
# Given the way we constructe this test, this directory should not exist
# TODO add robustness to start. (LP: #1792242)
self.assertThat(provider.provider_project_dir, Not(DirExists()))
os.path.join('dir-simple', 'sub')
]
for expected_file in expected_files:
self.assertThat(
os.path.join(self.stage_dir, expected_file),
FileExists())
self.assertThat(os.access(
os.path.join(self.stage_dir, 'exec'), os.X_OK),
Equals(True))
expected_dirs = [
'dir-simple',
]
for expected_dir in expected_dirs:
self.assertThat(
os.path.join(self.stage_dir, expected_dir),
DirExists())
# Regression test for
# https://bugs.launchpad.net/snapcraft/+bug/1500728
self.run_snapcraft('pull')
def test_clean_pull(self):
class Options:
pass
plugin = conda.CondaPlugin("test-part", Options(), self.project)
os.makedirs(plugin._conda_home)
plugin.clean_pull()
self.assertThat(plugin._conda_home, Not(DirExists()))
def test_stage_one_part_only_from_3(self):
parts = self.make_snapcraft_yaml("stage", n=3)
result = self.run_command(["stage", "stage1"])
self.assertThat(result.exit_code, Equals(0))
self.assertThat(self.parts_dir, DirExists())
self.assertThat(parts[1]["part_dir"], DirExists())
self.verify_state("stage1", parts[1]["state_dir"], "stage")
for i in [0, 2]:
self.assertThat(parts[i]["part_dir"], Not(DirExists()))
self.assertThat(parts[i]["state_dir"], Not(DirExists()))
def test_clean_stage_step(self):
self.assert_files_exist()
self.run_snapcraft(['clean', '--step=stage'])
self.assertThat(self.stage_dir, Not(DirExists()))
self.assertThat(self.prime_dir, Not(DirExists()))
self.assertThat(self.parts_dir, DirExists())
# Now try to prime again
self.run_snapcraft('prime')
self.assert_files_exist()