def test_non_empty(self): codes = InterfaceParser.get_output_codes() self.assertNotEqual(codes, [])
def main(): """Main utility implementation.""" codes = InterfaceComparator.get_output_codes() codes += InterfaceParser.get_output_codes() # Parse command line arguments. parser = argparse.ArgumentParser(description="Comparing D-Bus interface definitions") parser.add_argument("old_file", type=str, help="Old interface XML file") parser.add_argument("new_file", type=str, help="New interface XML file") parser.add_argument( "--file-display-name", dest="file_display_name", type=str, help="Human-readable name for new interface XML file " "(if --new-file is a pipe, for example)", ) parser.add_argument( "--fatal-warnings", action="store_const", const=True, default=False, help="Treat all warnings as fatal" ) parser.add_argument( "--warnings", dest="warnings", metavar="CATEGORY,…", type=str, help="Warning categories (%s; %s)" % (", ".join(WARNING_CATEGORIES), ", ".join(codes)), ) args = parser.parse_args() if not args.old_file or not args.new_file: parser.print_help() sys.exit(1) if args.warnings is None or args.warnings == "all": # Enable all warnings by default warnings_args = WARNING_CATEGORIES elif args.warnings == "none": warnings_args = [] else: warnings_args = args.warnings.split(",") for warning_arg in warnings_args: if warning_arg[:3] == "no-": warning_arg = warning_arg[3:] if warning_arg not in WARNING_CATEGORIES and warning_arg not in codes: sys.stderr.write("%s: Unrecognized warning ‘%s’.\n" % (sys.argv[0], warning_arg)) parser.print_help() sys.exit(1) enabled_warnings = [arg for arg in warnings_args if arg[:3] != "no-"] disabled_warnings = [arg[3:] for arg in warnings_args if arg[:3] == "no-"] # Parse the two files. old_parser = InterfaceParser(args.old_file) new_parser = InterfaceParser(args.new_file) old_interfaces = _parse_file(args.old_file, old_parser) new_interfaces = _parse_file(args.new_file, new_parser) # Work out the human-readable name of the new XML filename. if args.file_display_name is not None: new_filename = args.file_display_name else: new_filename = args.new_file # Compare the interfaces. comparator = InterfaceComparator(old_interfaces, new_interfaces, enabled_warnings, disabled_warnings, new_filename) out = comparator.compare() _print_output(out) sys.exit(_calculate_exit_status(args, out))
def test_unique(self): codes = InterfaceParser.get_output_codes() self.assertEqual(len(codes), len(set(codes)))
def main(): """Main utility implementation.""" codes = InterfaceComparator.get_output_codes() codes += InterfaceParser.get_output_codes() # Parse command line arguments. parser = argparse.ArgumentParser( description='Comparing D-Bus interface definitions') parser.add_argument('old_file', type=str, help='Old interface XML file') parser.add_argument('new_file', type=str, help='New interface XML file') parser.add_argument('--file-display-name', dest='file_display_name', type=str, help='Human-readable name for new interface XML file ' '(if --new-file is a pipe, for example)') parser.add_argument('--fatal-warnings', action='store_const', const=True, default=False, help='Treat all warnings as fatal') parser.add_argument('--warnings', dest='warnings', metavar='CATEGORY,…', type=str, help='Warning categories (%s; %s)' % (', '.join(WARNING_CATEGORIES), ', '.join(codes))) args = parser.parse_args() if not args.old_file or not args.new_file: parser.print_help() sys.exit(1) if args.warnings is None or args.warnings == 'all': # Enable all warnings by default warnings_args = WARNING_CATEGORIES elif args.warnings == 'none': warnings_args = [] else: warnings_args = args.warnings.split(',') for warning_arg in warnings_args: if warning_arg[:3] == 'no-': warning_arg = warning_arg[3:] if warning_arg not in WARNING_CATEGORIES and warning_arg not in codes: sys.stderr.write('%s: Unrecognized warning ‘%s’.\n' % (sys.argv[0], warning_arg)) parser.print_help() sys.exit(1) enabled_warnings = [arg for arg in warnings_args if arg[:3] != 'no-'] disabled_warnings = [arg[3:] for arg in warnings_args if arg[:3] == 'no-'] # Parse the two files. old_parser = InterfaceParser(args.old_file) new_parser = InterfaceParser(args.new_file) old_interfaces = _parse_file(args.old_file, old_parser) new_interfaces = _parse_file(args.new_file, new_parser) # Work out the human-readable name of the new XML filename. if args.file_display_name is not None: new_filename = args.file_display_name else: new_filename = args.new_file # Compare the interfaces. comparator = InterfaceComparator(old_interfaces, new_interfaces, enabled_warnings, disabled_warnings, new_filename) out = comparator.compare() _print_output(out) sys.exit(_calculate_exit_status(args, out))