def test_invalid_versions(self): for version in INVALID_VERSIONS: self.assertFalse(valid(version), "{} should NOT be a valid version.".format(version))
def test_valid_versions(self): for version in VALID_VERSIONS.keys(): self.assertTrue(valid(version), "{} should be a valid version".format(version))
['^0.1.2', '>=0.1.2-0 <0.2.0-0'], ['^1.2.3', '>=1.2.3-0 <2.0.0-0'], ['^1.2.3-beta.4', '>=1.2.3-beta.4 <2.0.0-0'], ['<1', '<1.0.0-0'], ['< 1', '<1.0.0-0'], ['>=1', '>=1.0.0-0'], ['>= 1', '>=1.0.0-0'], ['<1.2', '<1.2.0-0'], ['< 1.2', '<1.2.0-0'], ['1', '>=1.0.0-0 <2.0.0-0'], ['>01.02.03', '>1.2.3'], ['~1.2.3beta', '>=1.2.3-beta <1.3.0-0'], ['^ 1.2 ^ 1', '>=1.2.0-0 <2.0.0-0 >=1.0.0-0 <2.0.0-0'] ] for v in tests: pre = v[0] wanted = v[1] found = validSpec(pre) equal(found, wanted, 'validRange(' + pre + ') === ' + str(wanted) + " got " + str(found)) if __name__ == "__main__": comparison() equality() ranges() negative() increment() valid()
def validate(self, version): try: semver.valid(version, loose=False) return True except AttributeError: return False
def main(): p = argparse.ArgumentParser() p.add_argument("version", help="A version to test bumping to.") p.add_argument("--test-dir", "-d", required=True, help="The folder in which the api tests reside.") p.add_argument("--repository", "-r", help="Path to repository on the system, default is CWD") p.add_argument("--cache", "-c", help="A cache of results") p.add_argument( "--setup-only", action="store_true", help="if cache has been set, this method will run the setup only") p.add_argument("--verbose", "-v", action="count", help="Run with verbose output.") p.add_argument("--test-suite", "-s", choices=["all", "unit", "jsapi"], required=True, help="The test suite to run") args = p.parse_args() if args.verbose == 1: logging.basicConfig(level=logging.INFO) if args.verbose == 2: logging.basicConfig(level=logging.DEBUG) repo = git.Repository(args.repository) if not repo.is_repo(): error("Not currently in a git repository") branch = repo.current_branch() if branch != "master": error("Must be on the master branch, was on " + branch) tags = semver.sort(repo.get_tags()) if not semver.valid(args.version): error(args.version + ' is not valid SemVer') if args.version not in tags: error('Version ' + args.version + ' not in history') if args.cache: args.cache = os.path.abspath(args.cache) runner = runtests.TestRunner(args.test_dir, repo=repo, cache=args.cache) tests = list(cvt(runner, tags, args.version)) if args.cache: if not os.path.isdir(args.cache): os.makedirs(args.cache) # in parallel from multiprocessing import Pool pool = Pool() for i in pool.imap_unordered(setup_test, tests): print "Setup ", i if not args.setup_only: for (runner, impl, test) in tests: for violation in runner.run(impl, test, args.test_suite): print "V{},{},{},{!r}".format(args.version, *violation)