summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/test_manifest_xml.py89
1 files changed, 89 insertions, 0 deletions
diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py
index aa6cb7df..40385cce 100644
--- a/tests/test_manifest_xml.py
+++ b/tests/test_manifest_xml.py
@@ -19,6 +19,8 @@
19from __future__ import print_function 19from __future__ import print_function
20 20
21import os 21import os
22import shutil
23import tempfile
22import unittest 24import unittest
23import xml.dom.minidom 25import xml.dom.minidom
24 26
@@ -146,3 +148,90 @@ class ValueTests(unittest.TestCase):
146 with self.assertRaises(error.ManifestParseError): 148 with self.assertRaises(error.ManifestParseError):
147 node = self._get_node('<node a="xx"/>') 149 node = self._get_node('<node a="xx"/>')
148 manifest_xml.XmlInt(node, 'a') 150 manifest_xml.XmlInt(node, 'a')
151
152
153class XmlManifestTests(unittest.TestCase):
154 """Check manifest processing."""
155
156 def setUp(self):
157 self.tempdir = tempfile.mkdtemp(prefix='repo_tests')
158 self.repodir = os.path.join(self.tempdir, '.repo')
159 self.manifest_dir = os.path.join(self.repodir, 'manifests')
160 self.manifest_file = os.path.join(
161 self.repodir, manifest_xml.MANIFEST_FILE_NAME)
162 self.local_manifest_dir = os.path.join(
163 self.repodir, manifest_xml.LOCAL_MANIFESTS_DIR_NAME)
164 os.mkdir(self.repodir)
165 os.mkdir(self.manifest_dir)
166
167 # The manifest parsing really wants a git repo currently.
168 gitdir = os.path.join(self.repodir, 'manifests.git')
169 os.mkdir(gitdir)
170 with open(os.path.join(gitdir, 'config'), 'w') as fp:
171 fp.write("""[remote "origin"]
172 url = https://localhost:0/manifest
173""")
174
175 def tearDown(self):
176 shutil.rmtree(self.tempdir, ignore_errors=True)
177
178 def getXmlManifest(self, data):
179 """Helper to initialize a manifest for testing."""
180 with open(self.manifest_file, 'w') as fp:
181 fp.write(data)
182 return manifest_xml.XmlManifest(self.repodir, self.manifest_file)
183
184 def test_empty(self):
185 """Parse an 'empty' manifest file."""
186 manifest = self.getXmlManifest(
187 '<?xml version="1.0" encoding="UTF-8"?>'
188 '<manifest></manifest>')
189 self.assertEqual(manifest.remotes, {})
190 self.assertEqual(manifest.projects, [])
191
192 def test_link(self):
193 """Verify Link handling with new names."""
194 manifest = manifest_xml.XmlManifest(self.repodir, self.manifest_file)
195 with open(os.path.join(self.manifest_dir, 'foo.xml'), 'w') as fp:
196 fp.write('<manifest></manifest>')
197 manifest.Link('foo.xml')
198 with open(self.manifest_file) as fp:
199 self.assertIn('<include name="foo.xml" />', fp.read())
200
201 def test_toxml_empty(self):
202 """Verify the ToXml() helper."""
203 manifest = self.getXmlManifest(
204 '<?xml version="1.0" encoding="UTF-8"?>'
205 '<manifest></manifest>')
206 self.assertEqual(manifest.ToXml().toxml(), '<?xml version="1.0" ?><manifest/>')
207
208 def test_todict_empty(self):
209 """Verify the ToDict() helper."""
210 manifest = self.getXmlManifest(
211 '<?xml version="1.0" encoding="UTF-8"?>'
212 '<manifest></manifest>')
213 self.assertEqual(manifest.ToDict(), {})
214
215 def test_project_group(self):
216 """Check project group settings."""
217 manifest = self.getXmlManifest("""
218<manifest>
219 <remote name="test-remote" fetch="http://localhost" />
220 <default remote="test-remote" revision="refs/heads/main" />
221 <project name="test-name" path="test-path"/>
222 <project name="extras" path="path" groups="g1,g2,g1"/>
223</manifest>
224""")
225 self.assertEqual(len(manifest.projects), 2)
226 # Ordering isn't guaranteed.
227 result = {
228 manifest.projects[0].name: manifest.projects[0].groups,
229 manifest.projects[1].name: manifest.projects[1].groups,
230 }
231 project = manifest.projects[0]
232 self.assertCountEqual(
233 result['test-name'],
234 ['name:test-name', 'all', 'path:test-path'])
235 self.assertCountEqual(
236 result['extras'],
237 ['g1', 'g2', 'g1', 'name:extras', 'all', 'path:path'])