def test_make_wrap(self): repo = gitutils.GitProject(git.Repo.init(self.workdir)) repo.commit('initial commit') repo.create_version('1.2.3') with repo.open('upstream.wrap', 'w') as f: ini.WrapFile(directory='hello', source_url='https://example.com/file.tgz', source_filename='file.tgz', source_hash='hash-hash-hash').write(f) with repo.open('meson.wrap', 'w') as f: f.write('hello world') repo.commit('my commit') wrap = wrapcreator.make_wrap('project', repo.git_dir, '1.2.3') up = ini.WrapFile.from_string(wrap.wrapfile_content) self.assertEqual(up.directory, 'hello') self.assertEqual(up.source_url, 'https://example.com/file.tgz') self.assertEqual(up.source_filename, 'file.tgz') self.assertEqual(up.source_hash, 'hash-hash-hash') self.assertEqual( up.patch_url, 'https://wrapdb.mesonbuild.com/v1/' 'projects/project/1.2.3/1/get_zip') self.assertEqual(up.patch_filename, 'project-1.2.3-1-wrap.zip') with io.BytesIO(wrap.zip) as zipf: with zipfile.ZipFile(zipf, 'r') as zip: self.assertListEqual(zip.namelist(), ['hello/meson.wrap']) self.assertEqual(zip.read('hello/meson.wrap'), b'hello world') self.assertEqual(up.patch_hash, hashlib.sha256(wrap.zip).hexdigest()) self.assertEqual(wrap.wrapfile_name, 'project-1.2.3-1-wrap.wrap') self.assertEqual(wrap.zip_name, 'project-1.2.3-1-wrap.zip') self.assertEqual(wrap.commit_sha, repo.head_hexsha)
def test_merged_revisions(self): repo = gitutils.GitProject(git.Repo.init(self.workdir)) repo.commit('initial commit') repo.create_version('1.0.0') with repo.open('upstream.wrap', 'w') as f: ini.WrapFile(directory='hello', source_url='https://example.com/file.tgz', source_filename='file.tgz', source_hash='hash-hash-hash').write(f) repo.commit('commit 1') wrap = wrapcreator.make_wrap('project', repo.git_dir, '1.0.0') self.assertEqual(wrap.revision, 1) comm2 = repo.commit('commit 2') wrap = wrapcreator.make_wrap('project', repo.git_dir, '1.0.0') self.assertEqual(wrap.revision, 2) repo.commit('commit 3') wrap = wrapcreator.make_wrap('project', repo.git_dir, '1.0.0') self.assertEqual(wrap.revision, 3) repo.merge_commit('commit 4', parent=comm2) wrap = wrapcreator.make_wrap('project', repo.git_dir, '1.0.0') self.assertEqual(wrap.revision, 4) repo.merge_commit('commit 5', parent=comm2) wrap = wrapcreator.make_wrap('project', repo.git_dir, '1.0.0') self.assertEqual(wrap.revision, 5)
def test_attr(self): w = ini.WrapFile() for attr in ('directory', 'lead_directory_missing', 'source_url', 'source_filename', 'source_hash', 'patch_url', 'patch_filename', 'patch_hash'): setattr(w, attr, 'test-value') self.assertEqual(getattr(w, attr), 'test-value') self.assertTrue(getattr(w, 'has_' + attr)) self.assertTrue(w.has(attr))
def test_check_wrapfile_okay(self): up = ini.WrapFile() up.directory = 'hello' up.source_url = 'https://example.com/file.tgz' up.source_filename = 'file.tgz' up.source_hash = 'hash-hash-hash' try: wrapcreator._check_wrapfile(up) except RuntimeError as e: self.fail(f'Unexpected RuntimeError {e!r}')
def create_version(self, version, zipurl, filename, directory, ziphash=None, base='HEAD'): if ziphash is None: ziphash = self._get_hash(zipurl) self.repo.head.reference = self.repo.create_head(version, commit=base) assert not self.repo.head.is_detached self.repo.head.reset(index=True, working_tree=True) with self.open('upstream.wrap', 'w') as ofile: ini.WrapFile(directory=directory, source_url=zipurl, source_filename=filename, source_hash=ziphash).write(ofile)
def test_write(self): w = ini.WrapFile() w.directory = '/hello/world' s = w.write_string() self.assertIn('/hello/world', s) self.assertIn('[wrap-file]', s)
def test_check_wrapfile_empty(self): with self.assertRaises(RuntimeError): wrapcreator._check_wrapfile(ini.WrapFile())