diff options
Diffstat (limited to 'tests/test_manifest_xml.py')
-rw-r--r-- | tests/test_manifest_xml.py | 57 |
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 | ||
21 | import os | 21 | import os |
22 | import unittest | 22 | import unittest |
23 | import xml.dom.minidom | ||
23 | 24 | ||
24 | import error | 25 | import error |
25 | import manifest_xml | 26 | import 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 | |||
95 | class 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') | ||