def test_clean_build_step(self): self.assert_files_exist() self.run_snapcraft(['clean', '--step=build'], self.project_dir) for part_name, part in self.parts.items(): self.assertThat(part['builddir'], Not(DirExists())) self.assertThat(part['installdir'], Not(DirExists())) self.assertThat(part['sourcedir'], DirExists()) # Now try to build again self.run_snapcraft('build', self.project_dir) self.assert_files_exist()
def test_build_doesnt_get_bad_install_directory_lp1586546(self): """Verify that LP: #1586546 doesn't come back.""" self.run_snapcraft('stage', 'python-pyyaml') self.assertThat( glob(os.path.join( self.parts_dir, 'python2', 'install', 'lib', 'python2*', 'site-packages', 'yaml'))[0], DirExists()) self.assertThat( glob(os.path.join( self.parts_dir, 'python3', 'install', 'lib', 'python3*', 'site-packages', 'yaml'))[0], DirExists())
def test_clean_make_plugin(self): project_dir = 'simple-make' self.run_snapcraft('snap', project_dir) snap_dirs = ('stage', 'parts', 'snap') for dir_ in snap_dirs: self.assertThat( os.path.join(project_dir, dir_), DirExists()) self.run_snapcraft('clean', project_dir) for dir_ in snap_dirs: self.assertThat( os.path.join(project_dir, dir_), Not(DirExists()))
def assert_clean(self, parts, common=False): for part in parts: self.expectThat( self.part_dirs[part], Not(DirExists()), 'Expected part directory for {!r} to be cleaned'.format(part)) if common: self.expectThat(self.parts_dir, Not(DirExists()), 'Expected parts/ directory to be cleaned') self.expectThat(self.stage_dir, Not(DirExists()), 'Expected stage/ directory to be cleaned') self.expectThat(self.prime_dir, Not(DirExists()), 'Expected snap/ directory to be cleaned')
def test_clean_with_deprecated_strip_step(self): bindir = os.path.join(self.prime_dir, 'bin') self.assertThat(os.path.join(bindir, 'file1'), FileExists()) self.assertThat(os.path.join(bindir, 'file2'), FileExists()) self.run_snapcraft(['clean', '--step=strip']) self.assertThat(self.prime_dir, Not(DirExists())) self.assertThat(self.stage_dir, DirExists()) self.assertThat(self.parts_dir, DirExists()) # Now try to prime again self.run_snapcraft('prime') self.assertThat(os.path.join(bindir, 'file1'), FileExists()) self.assertThat(os.path.join(bindir, 'file2'), FileExists())
def test_build_doesnt_get_bad_install_directory_lp1586546(self): """Verify that LP: #1586546 doesn't come back.""" project_dir = 'python-pyyaml' self.run_snapcraft('stage', project_dir) self.assertThat( os.path.join( project_dir, 'parts', 'python2', 'install', 'usr', 'lib', 'python2.7', 'dist-packages', 'yaml'), DirExists()) self.assertThat( os.path.join( project_dir, 'parts', 'python3', 'install', 'usr', 'lib', 'python3', 'dist-packages', 'yaml'), DirExists())
def assert_not_clean(self, parts, common=False): for part in parts: self.expectThat( self.part_dirs[part], DirExists(), 'Expected part directory for {!r} to be uncleaned'.format( part)) if common: self.expectThat(self.partsdir, DirExists(), 'Expected parts/ directory to be uncleaned') self.expectThat(self.stagedir, DirExists(), 'Expected stage/ directory to be uncleaned') self.expectThat(self.snapdir, DirExists(), 'Expected snap/ directory to be uncleaned')
def test_clean_with_deprecated_strip_step(self): bindir = os.path.join(self.prime_dir, "bin") self.assertThat(os.path.join(bindir, "file1"), FileExists()) self.assertThat(os.path.join(bindir, "file2"), FileExists()) self.run_snapcraft(["clean", "--step=strip"]) self.assertThat(self.prime_dir, Not(DirExists())) self.assertThat(self.stage_dir, DirExists()) self.assertThat(self.parts_dir, DirExists()) # Now try to prime again self.run_snapcraft("prime") self.assertThat(os.path.join(bindir, "file1"), FileExists()) self.assertThat(os.path.join(bindir, "file2"), FileExists())
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_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_prime_step_single_part(self): bindir = os.path.join(self.prime_dir, 'bin') self.assertThat(os.path.join(bindir, 'file1'), FileExists()) self.assertThat(os.path.join(bindir, 'file2'), FileExists()) self.run_snapcraft(['clean', 'part1', '--step=prime']) self.assertThat(os.path.join(bindir, 'file1'), Not(FileExists())) self.assertThat(os.path.join(bindir, 'file2'), FileExists()) self.assertThat(self.stage_dir, DirExists()) self.assertThat(self.parts_dir, DirExists()) # Now try to prime again self.run_snapcraft('prime') self.assertThat(os.path.join(bindir, 'file1'), FileExists()) self.assertThat(os.path.join(bindir, 'file2'), FileExists())
def test_clean_prime_step(self): snapdir = os.path.join(self.project_dir, 'prime') bindir = os.path.join(snapdir, 'bin') self.assertThat(os.path.join(bindir, 'file1'), FileExists()) self.assertThat(os.path.join(bindir, 'file2'), FileExists()) self.run_snapcraft(['clean', '--step=prime'], self.project_dir) self.assertThat(snapdir, Not(DirExists())) self.assertThat(os.path.join(self.project_dir, 'stage'), DirExists()) self.assertThat(os.path.join(self.project_dir, 'parts'), DirExists()) # Now try to prime again self.run_snapcraft('prime', self.project_dir) self.assertThat(os.path.join(bindir, 'file1'), FileExists()) self.assertThat(os.path.join(bindir, 'file2'), FileExists())
def test_clean_pull_step(self): self.assert_files_exist() self.run_snapcraft(['clean', '--step=pull'], self.project_dir) self.assertThat(self.stagedir, Not(DirExists())) self.assertThat(self.snapdir, Not(DirExists())) for part_name, part in self.parts.items(): self.assertThat(part['builddir'], Not(DirExists())) self.assertThat(part['installdir'], Not(DirExists())) self.assertThat(part['sourcedir'], Not(DirExists())) # Now try to strip again self.run_snapcraft('strip', self.project_dir) self.assert_files_exist()
def test_clean_build_step(self): self.assert_files_exist() self.run_snapcraft(["clean", "--step=build"]) self.assertThat(self.stage_dir, Not(DirExists())) self.assertThat(self.prime_dir, Not(DirExists())) for part_name, part in self.parts.items(): self.assertThat(part["builddir"], Not(DirExists())) self.assertThat(part["installdir"], Not(DirExists())) self.assertThat(part["sourcedir"], DirExists()) # Now try to prime again self.run_snapcraft("prime") self.assert_files_exist()
def test_local_plugin_not_removed(self): self.make_snapcraft_yaml(n=3) local_plugin = os.path.join(self.local_plugins_dir, 'foo.py') os.makedirs(os.path.dirname(local_plugin)) open(local_plugin, 'w').close() result = self.run_command(['clean']) 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())) self.assertThat(local_plugin, FileExists())
def test_clean_prime_step_single_part(self): bindir = os.path.join(self.prime_dir, "bin") self.assertThat(os.path.join(bindir, "file1"), FileExists()) self.assertThat(os.path.join(bindir, "file2"), FileExists()) self.run_snapcraft(["clean", "part1", "--step=prime"]) self.assertThat(os.path.join(bindir, "file1"), Not(FileExists())) self.assertThat(os.path.join(bindir, "file2"), FileExists()) self.assertThat(self.stage_dir, DirExists()) self.assertThat(self.parts_dir, DirExists()) # Now try to prime again self.run_snapcraft("prime") self.assertThat(os.path.join(bindir, "file1"), FileExists()) self.assertThat(os.path.join(bindir, "file2"), FileExists())
def test_cross_compile(self, mock_download): plugin = rust.RustPlugin('test-part', self.options, self.project_options) os.makedirs(plugin.sourcedir) plugin.enable_cross_compilation() self.assertThat(plugin._target, Equals(self.target)) plugin.pull() mock_download.assert_called_once_with() self.assertThat(self.run_mock.call_count, Equals(2)) self.run_mock.assert_has_calls([ mock.call( [plugin._rustup, '--prefix={}'.format(os.path.join(plugin._rustpath)), '--disable-sudo', '--save', '--with-target={}'.format(self.target)], cwd=os.path.join(plugin.partdir, 'build')), mock.call( [plugin._cargo, 'fetch', '--manifest-path', os.path.join(plugin.sourcedir, 'Cargo.toml')], cwd=os.path.join(plugin.partdir, 'build')), ]) plugin.build() self.assertThat(os.path.join(plugin._cargo_dir, 'config'), FileExists()) self.assertThat(self.run_mock.call_count, Equals(3)) self.run_mock.assert_has_calls([ mock.call( [plugin._cargo, 'install', '-j{}'.format(plugin.project.parallel_build_count), '--root', plugin.installdir, '--path', plugin.builddir], cwd=os.path.join(plugin.partdir, 'build'), env=plugin._build_env()) ]) plugin.clean_build() self.assertThat(plugin._cargo_dir, Not(DirExists())) plugin.clean_pull() self.assertThat(plugin._rustpath, Not(DirExists())) # Cleaning again shouldn't raise an exception plugin.clean_build() plugin.clean_pull()
def test__creates_directory(self): parent = self.make_dir() new_home = self.make_nonexistent_path(parent) self.patch_gnupg_home(new_home) self.patch_call() upgrade_cluster.create_gnupg_home() self.assertThat(new_home, DirExists())
def test_clean_strip_step_single_part(self): bindir = os.path.join(self.project_dir, 'snap', 'bin') self.assertThat(os.path.join(bindir, 'file1'), FileExists()) self.assertThat(os.path.join(bindir, 'file2'), FileExists()) self.run_snapcraft(['clean', 'part1', '--step=strip'], self.project_dir) self.assertThat(os.path.join(bindir, 'file1'), Not(FileExists())) self.assertThat(os.path.join(bindir, 'file2'), FileExists()) self.assertThat(os.path.join(self.project_dir, 'stage'), DirExists()) self.assertThat(os.path.join(self.project_dir, 'parts'), DirExists()) # Now try to strip again self.run_snapcraft('strip', self.project_dir) self.assertThat(os.path.join(bindir, 'file1'), FileExists()) self.assertThat(os.path.join(bindir, 'file2'), FileExists())
def test_stage_dump_plugin(self): self.run_snapcraft('stage', 'dump') expected_files = [ 'flat', os.path.join('flatdir', 'flat2'), 'onedeep', os.path.join('onedeepdir', 'onedeep2'), 'oneflat', 'top-simple', 'notop', 'parent', 'slash', 'readonly_file', ] for expected_file in expected_files: self.assertThat(os.path.join(self.stage_dir, expected_file), FileExists()) expected_dirs = [ 'dir-simple', 'notopdir', ] 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 assert_not_clean(self, parts): for part in parts: self.assertThat( os.path.join(self.part_dirs[part], "state"), DirExists(), "{!r} is clean!".format(part), )
def test_stage_nil_plugin(self): project_dir = 'simple-tar' self.run_snapcraft('stage', project_dir) expected_files = [ 'flat', os.path.join('flatdir', 'flat2'), 'onedeep', os.path.join('onedeepdir', 'onedeep2'), 'oneflat', 'top-simple', 'notop', 'parent', 'slash', 'readonly_file' ] for expected_file in expected_files: self.assertThat(os.path.join(project_dir, 'stage', expected_file), FileExists()) expected_dirs = [ 'dir-simple', 'notopdir', ] for expected_dir in expected_dirs: self.assertThat(os.path.join(project_dir, 'stage', expected_dir), DirExists()) binary_output = self.get_output_ignoring_non_zero_exit(os.path.join( 'stage', 'bin', 'test'), cwd=project_dir) self.assertEqual('tarproject\n', binary_output) # Regression test for # https://bugs.launchpad.net/snapcraft/+bug/1500728 self.run_snapcraft('pull', project_dir)
def test_stage_zip_source(self): self.copy_project_to_cwd('zip') self.run_snapcraft('stage') expected_files = [ 'exec', 'top-simple', 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_pull_snap_file_must_extract(self): snap_source = sources.Snap(self.test_file_path, self.dest_dir) snap_source.pull() self.assertThat(os.path.join(self.dest_dir, "meta.basic"), DirExists()) self.assertThat(os.path.join(self.dest_dir, "meta.basic", "snap.yaml"), FileExists())
def test_not_even_creating_parents(self): fixture = FileTree(['a/b/foo.txt', 'c/d/e/']) with fixture: path = fixture.path self.assertThat(os.path.join(path, 'a', 'b', 'foo.txt'), FileContains("The file 'a/b/foo.txt'.")) self.assertThat(os.path.join(path, 'c', 'd', 'e'), DirExists())
def test_clean_build_step_single_part(self): self.assert_files_exist() self.run_snapcraft(['clean', 'part1', '--step=build']) 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 build again self.run_snapcraft('build') self.assert_files_exist()
def test_clean_pull_removes_dotnet_dir(self): dotnet_dir = os.path.join('parts', 'test-part', 'dotnet', 'sdk') os.makedirs(dotnet_dir) plugin = dotnet.DotNetPlugin( 'test-part', self.options, self.project) plugin.clean_pull() self.assertThat(dotnet_dir, Not(DirExists()))
def test_launch_instance(self): provider = ProviderImpl(project=self.project, echoer=self.echoer_mock) provider.start_mock.side_effect = errors.ProviderInstanceNotFoundError( instance_name=self.instance_name) provider.launch_instance() provider.launch_mock.assert_any_call() provider.start_mock.assert_any_call() provider.save_info_mock.assert_called_once_with({"base": "core16"}) self.assertThat(provider.run_mock.call_count, Equals(7)) provider.run_mock.assert_has_calls([ call(["snapcraft", "refresh"]), call(["mv", "/tmp/L3Jvb3QvLmJhc2hyYw==", "/root/.bashrc"]), call(["chown", "root:root", "/root/.bashrc"]), call(["chmod", "0600", "/root/.bashrc"]), call([ "mv", "/tmp/L2Jpbi9fc25hcGNyYWZ0X3Byb21wdA==", "/bin/_snapcraft_prompt", ]), call(["chown", "root:root", "/bin/_snapcraft_prompt"]), call(["chmod", "0755", "/bin/_snapcraft_prompt"]), ]) self.assertThat(provider.provider_project_dir, DirExists())
def test_setup_with_dir(self): patcher = mock.patch.object(_images._Image, "get") image_get_mock = patcher.start() image_get_mock.return_value = "base-build-image.qcow2" self.addCleanup(patcher.stop) patcher = mock.patch("subprocess.check_call") call_mock = patcher.start() self.addCleanup(patcher.stop) _images.setup( base="core16", snap_arch="amd64", size="1G", image_path=os.path.join("dir", "image.qcow2"), ) self.assertThat("dir", DirExists()) call_mock.assert_called_once_with( [ "qemu-img", "create", "-q", "-f", "qcow2", "-b", "base-build-image.qcow2", os.path.join("dir", "image.qcow2"), "1G", ] )
def test_setup(self): """ The fixture passes port and dbpath as extra arguments, and configure the output format to match mongodb's one. """ self.reactor.process.data = b"\n".join(OUT) client = [] class FakeMongoClient(object): def __init__(self, endpoint): client.append(endpoint) def close(self): client.append("close") self.patch(self.fixture, "allocatePort", lambda: 666) self.patch(pymongo, "MongoClient", FakeMongoClient) self.fixture.setUp() executable, arg1, arg2, arg3 = self.reactor.process.args self.assertEqual(b"mongod", executable) self.assertEqual(b"--port=666", arg1) self.assertEqual(["mongodb://localhost:666"], client) self.assertThat(arg2, StartsWith(b"--dbpath=")) self.assertThat(arg2.split(b"=")[1], DirExists()) self.assertEqual(b"--nojournal", arg3) self.assertIn("waiting for connections on port 666", self.logger.output.split("\n")) self.fixture.cleanUp() self.assertEqual(["mongodb://localhost:666", "close"], client)
def test_not_exists(self): doesntexist = os.path.join(self.mkdtemp(), 'doesntexist') mismatch = DirExists().match(doesntexist) self.assertThat( PathExists().match(doesntexist).describe(), Equals(mismatch.describe()))
def test_not_a_directory(self): filename = os.path.join(self.mkdtemp(), 'foo') self.touch(filename) mismatch = DirExists().match(filename) self.assertThat( "%s is not a directory." % filename, Equals(mismatch.describe()))