def test_requirements_policy_pass(self): content = textwrap.dedent("""\ cffi!=1.1.2 other """) reqs = requirement.parse(content) policy_check = [x for x in requirement.check_reqs_bounds_policy(reqs)] self.assertEqual(len(policy_check), 0)
def test_requirements_policy_fail(self): content = textwrap.dedent("""\ cffi>=1.1.1,!=1.1.0 other>=1,>=2,!=1.1.0 """) reqs = requirement.parse(content) self.assertEqual([ 'Requirement cffi should not include a >= specifier', 'Requirement other should not include a >= specifier'], sorted([x for x in requirement.check_reqs_bounds_policy(reqs)]))
def test_requirements_policy_fail(self): content = textwrap.dedent("""\ cffi>=1.1.1,!=1.1.0 other>=1,>=2,!=1.1.0 no_lower_bound """) reqs = requirement.parse(content) self.assertEqual([ 'Requirement cffi has a !=1.1.0 specifier that is not >=1.1.1', 'Requirement no-lower-bound needs a >= specifier', 'Requirement other has multiple >= specifier' ], sorted([x for x in requirement.check_reqs_bounds_policy(reqs)]))
def main(): parser = argparse.ArgumentParser() parser.add_argument( 'global_requirements', default='global-requirements.txt', help='path to the global-requirements.txt file', ) parser.add_argument( 'upper_constraints', default='upper-constraints.txt', help='path to the upper-constraints.txt file', ) parser.add_argument( 'blacklist', default='blacklist.txt', help='path to the blacklist.txt file', ) args = parser.parse_args() error_count = 0 # Check the format of the constraints file. print('\nChecking %s' % args.upper_constraints) constraints_txt = read_requirements_file(args.upper_constraints) for msg in constraints.check_format(constraints_txt): print(msg) error_count += 1 # Check that the constraints and requirements are compatible. print('\nChecking %s' % args.global_requirements) global_reqs = read_requirements_file(args.global_requirements) for msg in constraints.check_compatible(global_reqs, constraints_txt): print(msg) error_count += 1 # Check requirements to satisfy policy. print('\nChecking requirements on %s' % args.global_requirements) for msg in requirement.check_reqs_bounds_policy(global_reqs): print(msg) error_count += 1 # Check that global requirements are uniformly formatted print('\nValidating uniform formatting on %s' % args.global_requirements) with open(args.global_requirements, 'rt') as f: for line in f: if line == '\n': continue req = requirement.parse_line(line) normed_req = req.to_line(comment_prefix=' ', sort_specifiers=True) if line.rstrip() != normed_req.rstrip(): print("-%s\n+%s" % (line.rstrip(), normed_req.rstrip())) error_count += 1 # Check that all of the items in the global-requirements list # appear in exactly one of the constraints file or the blacklist. print('\nChecking %s' % args.blacklist) blacklist = read_requirements_file(args.blacklist) for msg in constraints.check_blacklist_coverage( global_reqs, constraints_txt, blacklist, os.path.basename(args.upper_constraints)): print(msg) error_count += 1 return 1 if error_count else 0