summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2020-02-22 05:30:12 -0500
committerMike Frysinger <vapier@google.com>2020-03-13 18:48:52 +0000
commitbb8ee7f54a4e0bf07d466304d800f13ec41ac21c (patch)
treeaf0dec0603951b94f2cb7a73d273edd486df0fbf /tests
parent23d7dafd10e382f42c34618f7c86b3ff1c9d4245 (diff)
downloadgit-repo-bb8ee7f54a4e0bf07d466304d800f13ec41ac21c.tar.gz
manifest_xml: unify bool & int parsing
We've been overly lenient with boolean parsing by ignoring invalid values as "false" even if the user didn't intend that. Turn all unknown values into warnings to avoid breaking existing manifests, and unify the parsing logic in a helper to simplify. We've been stricter about numbers, but still copying & pasting inconsistent code. Add a helper for this too. For out of range sync-j numbers (i.e. less than 1), throw a warning for now, but mark it for future hard failures. Change-Id: I924162b8036e6a5f1e31b6ebb24b6a26ed63712d Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/256457 Reviewed-by: Michael Mortensen <mmortensen@google.com> Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_manifest_xml.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py
index 1cb72971..aa6cb7df 100644
--- a/tests/test_manifest_xml.py
+++ b/tests/test_manifest_xml.py
@@ -20,6 +20,7 @@ from __future__ import print_function
20 20
21import os 21import os
22import unittest 22import unittest
23import xml.dom.minidom
23 24
24import error 25import error
25import manifest_xml 26import manifest_xml
@@ -89,3 +90,59 @@ class ManifestValidateFilePaths(unittest.TestCase):
89 error.ManifestInvalidPathError, self.check_both, path, 'a') 90 error.ManifestInvalidPathError, self.check_both, path, 'a')
90 self.assertRaises( 91 self.assertRaises(
91 error.ManifestInvalidPathError, self.check_both, 'a', path) 92 error.ManifestInvalidPathError, self.check_both, 'a', path)
93
94
95class ValueTests(unittest.TestCase):
96 """Check utility parsing code."""
97
98 def _get_node(self, text):
99 return xml.dom.minidom.parseString(text).firstChild
100
101 def test_bool_default(self):
102 """Check XmlBool default handling."""
103 node = self._get_node('<node/>')
104 self.assertIsNone(manifest_xml.XmlBool(node, 'a'))
105 self.assertIsNone(manifest_xml.XmlBool(node, 'a', None))
106 self.assertEqual(123, manifest_xml.XmlBool(node, 'a', 123))
107
108 node = self._get_node('<node a=""/>')
109 self.assertIsNone(manifest_xml.XmlBool(node, 'a'))
110
111 def test_bool_invalid(self):
112 """Check XmlBool invalid handling."""
113 node = self._get_node('<node a="moo"/>')
114 self.assertEqual(123, manifest_xml.XmlBool(node, 'a', 123))
115
116 def test_bool_true(self):
117 """Check XmlBool true values."""
118 for value in ('yes', 'true', '1'):
119 node = self._get_node('<node a="%s"/>' % (value,))
120 self.assertTrue(manifest_xml.XmlBool(node, 'a'))
121
122 def test_bool_false(self):
123 """Check XmlBool false values."""
124 for value in ('no', 'false', '0'):
125 node = self._get_node('<node a="%s"/>' % (value,))
126 self.assertFalse(manifest_xml.XmlBool(node, 'a'))
127
128 def test_int_default(self):
129 """Check XmlInt default handling."""
130 node = self._get_node('<node/>')
131 self.assertIsNone(manifest_xml.XmlInt(node, 'a'))
132 self.assertIsNone(manifest_xml.XmlInt(node, 'a', None))
133 self.assertEqual(123, manifest_xml.XmlInt(node, 'a', 123))
134
135 node = self._get_node('<node a=""/>')
136 self.assertIsNone(manifest_xml.XmlInt(node, 'a'))
137
138 def test_int_good(self):
139 """Check XmlInt numeric handling."""
140 for value in (-1, 0, 1, 50000):
141 node = self._get_node('<node a="%s"/>' % (value,))
142 self.assertEqual(value, manifest_xml.XmlInt(node, 'a'))
143
144 def test_int_invalid(self):
145 """Check XmlInt invalid handling."""
146 with self.assertRaises(error.ManifestParseError):
147 node = self._get_node('<node a="xx"/>')
148 manifest_xml.XmlInt(node, 'a')