def test_packageurls(self, mock_build): """ Test the name and version detection from tarball url Reads in file packageurls and assumes each line to be of the format <url>,<expected name>,<expected version> Does not use self.assertEquals but appends to a list so all failures are reported instead of just the first one. """ errors = [] with open("tests/packageurls", "r") as pkgurls: for urlline in pkgurls.read().split("\n"): if not urlline or urlline.startswith("#"): continue (url, name, version) = urlline.split(",") tarball.name_and_version(url, "") if tarball.name != name: errors.append("name: '{}' != '{}' for url: {}".format(tarball.name, name, url)) if tarball.version != version: errors.append("version: '{}' != '{}' for url: {}".format(tarball.version, version, url)) if errors: # raising an AssertionError signifies to unittest this is a failure # instead of an error. This prints a pretty list of all failures # that occurred. raise AssertionError("\n{}".format("\n".join(errors)))
def test_version_configuration_override(self): """ Test the version and name override from the command line """ tarball.name_and_version('something', 'else', FileManager()) self.assertEqual(tarball.version, 'else') self.assertEqual(tarball.name, 'something')
def test_packageurl(self, mock_build): """ Test the name and version detection from tarball url """ tarball.name = '' tarball.version = '' tarball.url = url tarball.name_and_version('', '', FileManager()) self.assertEqual(tarball.name, name) self.assertEqual(tarball.version, version)
def test_packageurl(self, mock_build): """ Test the name and version detection from tarball url """ tarball.name = '' tarball.version = '' tarball.giturl = '' tarball.url = url tarball.name_and_version('', '', FileManager()) self.assertEqual(name, tarball.name) self.assertEqual(version, tarball.version) if re.match("https?://github.com", url) != None: self.assertIsNotNone(tarball.giturl) self.assertNotEqual('', tarball.giturl, "giturl should not be empty") self.assertIsNotNone( re.match("https://github.com/[^/]+/"+tarball.repo+".git", tarball.giturl), "%s looks incorrect" % tarball.giturl)
def test_version_configuration_override(self): """ Test the version and name override from the command line """ set_multi_version_backup = tarball.set_multi_version n, _, v = tarball.name_and_version('something', 'else', FileManager()) tarball.set_multi_version = set_multi_version_backup self.assertEqual(v, 'else') self.assertEqual(n, 'something')
def generator(self): """Test template.""" conf = config.Config() conf.parse_config_versions = Mock(return_value={}) tarball.url = url n, _, v = tarball.name_and_version('', '', Mock(), conf) self.assertEqual(name, n) self.assertEqual(version, v) if "github.com" in url: self.assertRegex( tarball.giturl, r"https://github.com/[^/]+/" + tarball.repo + ".git")
def test_packageurl(self, mock_build): """ Test the name and version detection from tarball url """ tarball.giturl = '' tarball.url = url set_multi_version_backup = tarball.set_multi_version tarball.config.parse_config_versions = mock_gen(rv=version) n, _, v = tarball.name_and_version('', '', FileManager()) tarball.set_multi_version = set_multi_version_backup self.assertEqual(name, n) self.assertEqual(version, v) if re.match("https?://github.com", url) != None: self.assertIsNotNone(tarball.giturl) self.assertNotEqual('', tarball.giturl, "giturl should not be empty") self.assertIsNotNone( re.match("https://github.com/[^/]+/"+tarball.repo+".git", tarball.giturl), "%s looks incorrect" % tarball.giturl)
def main(): parser = argparse.ArgumentParser() parser.add_argument("-g", "--skip-git", action="store_false", dest="git", default=True, help="Don't commit result to git") parser.add_argument("-n", "--name", nargs=1, action="store", dest="name", default="", help="Override the package name") parser.add_argument("url", help="tarball URL (e.g." " http://example.com/downloads/mytar.tar.gz)") parser.add_argument('-a', "--archives", action="store", dest="archives", default=[], nargs='*', help="tarball URLs for additional source archives and" " a location for the sources to be extacted to (e.g." " http://example.com/downloads/dependency.tar.gz" " /directory/relative/to/extract/root )") parser.add_argument("-l", "--license-only", action="store_true", dest="license_only", default=False, help="Only scan for license files") parser.add_argument("-b", "--skip-bump", dest="bump", action="store_false", default=True, help="Don't bump release number") parser.add_argument("-c", "--config", dest="config", action="store", default="/usr/share/defaults/autospec/autospec.conf", help="Set configuration file to use") parser.add_argument("-t", "--target", dest="target", action="store", default=None, help="Target location to create or reuse") parser.add_argument("-i", "--integrity", action="store_true", default=False, help="Attempt to download and verify package signature") args = parser.parse_args() if len(args.archives) % 2 != 0: parser.error(argparse.ArgumentTypeError( "-a/--archives requires an even number of arguments")) check_requirements(args.git) # # First, download the tarball, extract it and then do a set # of static analysis on the content of the tarball. # build.setup_patterns() tarball.name_and_version(args.url, args.name) tarball.download_tarball(args.url, args.name, args.archives, args.target) _dir = tarball.path if args.license_only: try: with open(os.path.join(build.download_path, tarball.name + ".license"), "r") as dotlic: for word in dotlic.read().split(): if word.find(":") < 0: license.add_license(word) except: pass license.scan_for_licenses(name, _dir) exit(0) config.config_file = args.config config.parse_config_files(build.download_path, args.bump) config.parse_existing_spec(build.download_path, tarball.name) buildreq.set_build_req() buildreq.scan_for_configure(name, _dir, build.download_path) specdescription.scan_for_description(name, _dir) license.scan_for_licenses(name, _dir) docs.scan_for_changes(build.download_path, _dir) add_sources(build.download_path, args.archives) test.scan_for_tests(_dir) # # Now, we have enough to write out a specfile, and try to build it. # We will then analyze the build result and learn information until the # package builds # specfile = specfiles.Specfile(tarball.url, tarball.version, tarball.name, tarball.release) load_specfile(specfile) specfile.write_spec(build.download_path) print("\n") if args.integrity == True: pkg_integrity.check(args.url, build.download_path) while 1: build.package() specfile.packages = files.packages specfile.locales = lang.locales specfile.write_spec(build.download_path) files.newfiles_printed = 0 if build.round > 20 or build.must_restart == 0: break test.check_regression(build.download_path) if build.success == 0: print("Build failed") return elif os.path.isfile("README.clear"): try: print("\nREADME.clear CONTENTS") print("*********************") with open("README.clear", "r") as readme_f: print(readme_f.read()) print("*********************\n") except: pass examine_abi(build.download_path) with open(build.download_path + "/release", "w") as fp: fp.write(tarball.release + "\n") commitmessage.guess_commit_message() if args.git: git.commit_to_git(build.download_path)