def test_make_wrap(self): repo = git.Repo.init(self.workdir) repo.index.commit('initial commit') repo.head.reference = repo.create_head('1.2.3') def gopen(path, mode='r'): return gitutils.GitFile.open(repo, path, mode) with gopen('upstream.wrap', 'w') as f: upstream.UpstreamWrap(directory='hello', source_url='https://example.com/file.tgz', source_filename='file.tgz', source_hash='hash-hash-hash').write(f) with gopen('meson.wrap', 'w') as f: f.write('hello world') repo.index.commit('my commit') wrap = wrapcreator.make_wrap('project', repo.git_dir, '1.2.3') up = upstream.UpstreamWrap.from_string(wrap.wrap) 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.wrap_name, 'project-1.2.3-1-wrap.wrap') self.assertEqual(wrap.zip_name, 'project-1.2.3-1-wrap.zip')
def test_attr(self): w = upstream.UpstreamWrap() 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))
def test_check_definition_okay(self): up = upstream.UpstreamWrap() 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_definition(up) except RuntimeError as e: self.fail('Unexpected RuntimeError {!r}'.format(e))
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: upstream.UpstreamWrap(directory=directory, source_url=zipurl, source_filename=filename, source_hash=ziphash).write(ofile)
def test_check_definition_empty(self): with self.assertRaises(RuntimeError): wrapcreator._check_definition(upstream.UpstreamWrap())
def test_init(self): w = upstream.UpstreamWrap(source_url='hello', source_hash='world') self.assertEqual(w.source_url, 'hello') self.assertEqual(w.source_hash, 'world')
def test_write(self): w = upstream.UpstreamWrap() w.directory = '/hello/world' s = w.write_string() self.assertIn('/hello/world', s)
def test_option_not_found(self): w = upstream.UpstreamWrap() w.source_filename = 'hello' self.assertFalse(w.has_directory) with self.assertRaises(ValueError): w.directory
def test_section_not_found(self): w = upstream.UpstreamWrap() self.assertFalse(w.has_directory) with self.assertRaises(ValueError): self.assertIsNone(w.directory)