Index: tools/metrics/common/pretty_print_xml.py |
diff --git a/tools/metrics/common/pretty_print_xml.py b/tools/metrics/common/pretty_print_xml.py |
index ea65778954f7935c8bbb1861e354ea62273d88c4..d47acede959f2106482bb8e896e7f508673f9070 100644 |
--- a/tools/metrics/common/pretty_print_xml.py |
+++ b/tools/metrics/common/pretty_print_xml.py |
@@ -66,10 +66,11 @@ def SplitParagraphs(text): |
class XmlStyle(object): |
"""A class that stores all style specification for an output xml file.""" |
- def __init__(self, attribute_order, tags_that_have_extra_newline, |
- tags_that_dont_indent, tags_that_allow_single_line, |
- tags_alphabetization_rules): |
+ def __init__(self, attribute_order, required_attributes, |
+ tags_that_have_extra_newline, tags_that_dont_indent, |
+ tags_that_allow_single_line, tags_alphabetization_rules): |
self.attribute_order = attribute_order |
+ self.required_attributes = required_attributes |
self.tags_that_have_extra_newline = tags_that_have_extra_newline |
self.tags_that_dont_indent = tags_that_dont_indent |
self.tags_that_allow_single_line = tags_that_allow_single_line |
@@ -199,8 +200,22 @@ class XmlStyle(object): |
if not node.childNodes: |
closing_chars = 2 |
- # Pretty-print the attributes. |
attributes = node.attributes.keys() |
+ required_attributes = [attribute for attribute in self.required_attributes |
+ if attribute in self.attribute_order[node.tagName]] |
+ missing_attributes = [attribute for attribute in required_attributes |
+ if attribute not in attributes] |
+ |
+ for attribute in missing_attributes: |
+ logging.error( |
+ 'Missing attribute "%s" in tag "%s"', attribute, node.tagName) |
+ if missing_attributes: |
+ raise Error( |
+ 'Missing attributes {0} in tag "{1}"'.format( |
+ ', '.join('"{0}"'.format(a) for a in missing_attributes), |
Alexei Svitkine (slow)
2017/05/19 20:05:28
Nit: I'd extract this inner statement into a var a
|
+ node.tagName)) |
+ |
+ # Pretty-print the attributes. |
if attributes: |
# Reorder the attributes. |
unrecognized_attributes = ( |