summaryrefslogtreecommitdiff
path: root/chromium/components/policy/tools/template_writers/writers/xml_writer_base_unittest.py
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/components/policy/tools/template_writers/writers/xml_writer_base_unittest.py')
-rwxr-xr-xchromium/components/policy/tools/template_writers/writers/xml_writer_base_unittest.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/chromium/components/policy/tools/template_writers/writers/xml_writer_base_unittest.py b/chromium/components/policy/tools/template_writers/writers/xml_writer_base_unittest.py
new file mode 100755
index 00000000000..40c2ff52bb5
--- /dev/null
+++ b/chromium/components/policy/tools/template_writers/writers/xml_writer_base_unittest.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+"""Unittests for writers.admx_writer."""
+
+import re
+import unittest
+
+
+class XmlWriterBaseTest(unittest.TestCase):
+ '''Base class for XML writer unit-tests.
+ '''
+
+ def GetXMLOfChildren(self, parent):
+ '''Returns the XML of all child nodes of the given parent node.
+ Args:
+ parent: The XML of the children of this node will be returned.
+
+ Return: XML of the chrildren of the parent node.
+ '''
+ raw_pretty_xml = ''.join(
+ child.toprettyxml(indent=' ') for child in parent.childNodes)
+ # Python 2.6.5 which is present in Lucid has bug in its pretty print
+ # function which produces new lines around string literals. This has been
+ # fixed in Precise which has Python 2.7.3 but we have to keep compatibility
+ # with both for now.
+ text_re = re.compile('>\n\s+([^<>\s].*?)\n\s*</', re.DOTALL)
+ return text_re.sub('>\g<1></', raw_pretty_xml)
+
+ def AssertXMLEquals(self, output, expected_output):
+ '''Asserts if the passed XML arguements are equal.
+ Args:
+ output: Actual XML text.
+ expected_output: Expected XML text.
+ '''
+ self.assertEquals(output.strip(), expected_output.strip())