summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2021-02-25 04:54:56 -0500
committerMike Frysinger <vapier@google.com>2021-02-25 17:06:56 +0000
commit37ac3d626fc08fe47e937704913a626d26864a37 (patch)
tree9506004eb38cd4ff0578508f1749f99bcdda35be
parent55d6a5a3a224c2c0b397f57b02aea8f9bf76ca08 (diff)
downloadgit-repo-37ac3d626fc08fe47e937704913a626d26864a37.tar.gz
tests: refactor manifest tests
The XmlManifestTests class is getting to be large and we're only adding more to it. Factor out the core logic into a new TestCase so we can reuse it to better group more tests. Change-Id: I5113444a4649a70ecfa8d83d3305959a953693f7 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/298222 Reviewed-by: Raman Tenneti <rtenneti@google.com> Tested-by: Mike Frysinger <vapier@google.com>
-rw-r--r--tests/test_manifest_xml.py188
1 files changed, 98 insertions, 90 deletions
diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py
index 5fd242fc..40388f93 100644
--- a/tests/test_manifest_xml.py
+++ b/tests/test_manifest_xml.py
@@ -24,6 +24,38 @@ import error
24import manifest_xml 24import manifest_xml
25 25
26 26
27class ManifestParseTestCase(unittest.TestCase):
28 """TestCase for parsing manifests."""
29
30 def setUp(self):
31 self.tempdir = tempfile.mkdtemp(prefix='repo_tests')
32 self.repodir = os.path.join(self.tempdir, '.repo')
33 self.manifest_dir = os.path.join(self.repodir, 'manifests')
34 self.manifest_file = os.path.join(
35 self.repodir, manifest_xml.MANIFEST_FILE_NAME)
36 self.local_manifest_dir = os.path.join(
37 self.repodir, manifest_xml.LOCAL_MANIFESTS_DIR_NAME)
38 os.mkdir(self.repodir)
39 os.mkdir(self.manifest_dir)
40
41 # The manifest parsing really wants a git repo currently.
42 gitdir = os.path.join(self.repodir, 'manifests.git')
43 os.mkdir(gitdir)
44 with open(os.path.join(gitdir, 'config'), 'w') as fp:
45 fp.write("""[remote "origin"]
46 url = https://localhost:0/manifest
47""")
48
49 def tearDown(self):
50 shutil.rmtree(self.tempdir, ignore_errors=True)
51
52 def getXmlManifest(self, data):
53 """Helper to initialize a manifest for testing."""
54 with open(self.manifest_file, 'w') as fp:
55 fp.write(data)
56 return manifest_xml.XmlManifest(self.repodir, self.manifest_file)
57
58
27class ManifestValidateFilePaths(unittest.TestCase): 59class ManifestValidateFilePaths(unittest.TestCase):
28 """Check _ValidateFilePaths helper. 60 """Check _ValidateFilePaths helper.
29 61
@@ -146,37 +178,9 @@ class ValueTests(unittest.TestCase):
146 manifest_xml.XmlInt(node, 'a') 178 manifest_xml.XmlInt(node, 'a')
147 179
148 180
149class XmlManifestTests(unittest.TestCase): 181class XmlManifestTests(ManifestParseTestCase):
150 """Check manifest processing.""" 182 """Check manifest processing."""
151 183
152 def setUp(self):
153 self.tempdir = tempfile.mkdtemp(prefix='repo_tests')
154 self.repodir = os.path.join(self.tempdir, '.repo')
155 self.manifest_dir = os.path.join(self.repodir, 'manifests')
156 self.manifest_file = os.path.join(
157 self.repodir, manifest_xml.MANIFEST_FILE_NAME)
158 self.local_manifest_dir = os.path.join(
159 self.repodir, manifest_xml.LOCAL_MANIFESTS_DIR_NAME)
160 os.mkdir(self.repodir)
161 os.mkdir(self.manifest_dir)
162
163 # The manifest parsing really wants a git repo currently.
164 gitdir = os.path.join(self.repodir, 'manifests.git')
165 os.mkdir(gitdir)
166 with open(os.path.join(gitdir, 'config'), 'w') as fp:
167 fp.write("""[remote "origin"]
168 url = https://localhost:0/manifest
169""")
170
171 def tearDown(self):
172 shutil.rmtree(self.tempdir, ignore_errors=True)
173
174 def getXmlManifest(self, data):
175 """Helper to initialize a manifest for testing."""
176 with open(self.manifest_file, 'w') as fp:
177 fp.write(data)
178 return manifest_xml.XmlManifest(self.repodir, self.manifest_file)
179
180 def test_empty(self): 184 def test_empty(self):
181 """Parse an 'empty' manifest file.""" 185 """Parse an 'empty' manifest file."""
182 manifest = self.getXmlManifest( 186 manifest = self.getXmlManifest(
@@ -221,67 +225,6 @@ class XmlManifestTests(unittest.TestCase):
221 self.assertEqual(manifest.repo_hooks_project.name, 'repohooks') 225 self.assertEqual(manifest.repo_hooks_project.name, 'repohooks')
222 self.assertEqual(manifest.repo_hooks_project.enabled_repo_hooks, ['a', 'b']) 226 self.assertEqual(manifest.repo_hooks_project.enabled_repo_hooks, ['a', 'b'])
223 227
224 def test_superproject(self):
225 """Check superproject settings."""
226 manifest = self.getXmlManifest("""
227<manifest>
228 <remote name="test-remote" fetch="http://localhost" />
229 <default remote="test-remote" revision="refs/heads/main" />
230 <superproject name="superproject"/>
231</manifest>
232""")
233 self.assertEqual(manifest.superproject['name'], 'superproject')
234 self.assertEqual(manifest.superproject['remote'].name, 'test-remote')
235 self.assertEqual(manifest.superproject['remote'].url, 'http://localhost/superproject')
236 self.assertEqual(
237 manifest.ToXml().toxml(),
238 '<?xml version="1.0" ?><manifest>' +
239 '<remote name="test-remote" fetch="http://localhost"/>' +
240 '<default remote="test-remote" revision="refs/heads/main"/>' +
241 '<superproject name="superproject"/>' +
242 '</manifest>')
243
244 def test_superproject_with_remote(self):
245 """Check superproject settings."""
246 manifest = self.getXmlManifest("""
247<manifest>
248 <remote name="default-remote" fetch="http://localhost" />
249 <remote name="superproject-remote" fetch="http://localhost" />
250 <default remote="default-remote" revision="refs/heads/main" />
251 <superproject name="platform/superproject" remote="superproject-remote"/>
252</manifest>
253""")
254 self.assertEqual(manifest.superproject['name'], 'platform/superproject')
255 self.assertEqual(manifest.superproject['remote'].name, 'superproject-remote')
256 self.assertEqual(manifest.superproject['remote'].url, 'http://localhost/platform/superproject')
257 self.assertEqual(
258 manifest.ToXml().toxml(),
259 '<?xml version="1.0" ?><manifest>' +
260 '<remote name="default-remote" fetch="http://localhost"/>' +
261 '<remote name="superproject-remote" fetch="http://localhost"/>' +
262 '<default remote="default-remote" revision="refs/heads/main"/>' +
263 '<superproject name="platform/superproject" remote="superproject-remote"/>' +
264 '</manifest>')
265
266 def test_superproject_with_defalut_remote(self):
267 """Check superproject settings."""
268 manifest = self.getXmlManifest("""
269<manifest>
270 <remote name="default-remote" fetch="http://localhost" />
271 <default remote="default-remote" revision="refs/heads/main" />
272 <superproject name="superproject" remote="default-remote"/>
273</manifest>
274""")
275 self.assertEqual(manifest.superproject['name'], 'superproject')
276 self.assertEqual(manifest.superproject['remote'].name, 'default-remote')
277 self.assertEqual(
278 manifest.ToXml().toxml(),
279 '<?xml version="1.0" ?><manifest>' +
280 '<remote name="default-remote" fetch="http://localhost"/>' +
281 '<default remote="default-remote" revision="refs/heads/main"/>' +
282 '<superproject name="superproject"/>' +
283 '</manifest>')
284
285 def test_unknown_tags(self): 228 def test_unknown_tags(self):
286 """Check superproject settings.""" 229 """Check superproject settings."""
287 manifest = self.getXmlManifest(""" 230 manifest = self.getXmlManifest("""
@@ -389,3 +332,68 @@ class XmlManifestTests(unittest.TestCase):
389 self.assertIn('level2-group', proj.groups) 332 self.assertIn('level2-group', proj.groups)
390 # Check level2 proj group not removed. 333 # Check level2 proj group not removed.
391 self.assertIn('l2g1', proj.groups) 334 self.assertIn('l2g1', proj.groups)
335
336
337class SuperProjectTests(ManifestParseTestCase):
338 """Tests for <superproject>."""
339
340 def test_superproject(self):
341 """Check superproject settings."""
342 manifest = self.getXmlManifest("""
343<manifest>
344 <remote name="test-remote" fetch="http://localhost" />
345 <default remote="test-remote" revision="refs/heads/main" />
346 <superproject name="superproject"/>
347</manifest>
348""")
349 self.assertEqual(manifest.superproject['name'], 'superproject')
350 self.assertEqual(manifest.superproject['remote'].name, 'test-remote')
351 self.assertEqual(manifest.superproject['remote'].url, 'http://localhost/superproject')
352 self.assertEqual(
353 manifest.ToXml().toxml(),
354 '<?xml version="1.0" ?><manifest>' +
355 '<remote name="test-remote" fetch="http://localhost"/>' +
356 '<default remote="test-remote" revision="refs/heads/main"/>' +
357 '<superproject name="superproject"/>' +
358 '</manifest>')
359
360 def test_remote(self):
361 """Check superproject settings with a remote."""
362 manifest = self.getXmlManifest("""
363<manifest>
364 <remote name="default-remote" fetch="http://localhost" />
365 <remote name="superproject-remote" fetch="http://localhost" />
366 <default remote="default-remote" revision="refs/heads/main" />
367 <superproject name="platform/superproject" remote="superproject-remote"/>
368</manifest>
369""")
370 self.assertEqual(manifest.superproject['name'], 'platform/superproject')
371 self.assertEqual(manifest.superproject['remote'].name, 'superproject-remote')
372 self.assertEqual(manifest.superproject['remote'].url, 'http://localhost/platform/superproject')
373 self.assertEqual(
374 manifest.ToXml().toxml(),
375 '<?xml version="1.0" ?><manifest>' +
376 '<remote name="default-remote" fetch="http://localhost"/>' +
377 '<remote name="superproject-remote" fetch="http://localhost"/>' +
378 '<default remote="default-remote" revision="refs/heads/main"/>' +
379 '<superproject name="platform/superproject" remote="superproject-remote"/>' +
380 '</manifest>')
381
382 def test_defalut_remote(self):
383 """Check superproject settings with a default remote."""
384 manifest = self.getXmlManifest("""
385<manifest>
386 <remote name="default-remote" fetch="http://localhost" />
387 <default remote="default-remote" revision="refs/heads/main" />
388 <superproject name="superproject" remote="default-remote"/>
389</manifest>
390""")
391 self.assertEqual(manifest.superproject['name'], 'superproject')
392 self.assertEqual(manifest.superproject['remote'].name, 'default-remote')
393 self.assertEqual(
394 manifest.ToXml().toxml(),
395 '<?xml version="1.0" ?><manifest>' +
396 '<remote name="default-remote" fetch="http://localhost"/>' +
397 '<default remote="default-remote" revision="refs/heads/main"/>' +
398 '<superproject name="superproject"/>' +
399 '</manifest>')