diff options
Diffstat (limited to 'tests/test_manifest_xml.py')
| -rw-r--r-- | tests/test_manifest_xml.py | 106 |
1 files changed, 49 insertions, 57 deletions
diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py index 07939e16..c1fed2bf 100644 --- a/tests/test_manifest_xml.py +++ b/tests/test_manifest_xml.py | |||
| @@ -15,6 +15,7 @@ | |||
| 15 | """Unittests for the manifest_xml.py module.""" | 15 | """Unittests for the manifest_xml.py module.""" |
| 16 | 16 | ||
| 17 | import os | 17 | import os |
| 18 | from pathlib import Path | ||
| 18 | import platform | 19 | import platform |
| 19 | import re | 20 | import re |
| 20 | import tempfile | 21 | import tempfile |
| @@ -97,36 +98,34 @@ class ManifestParseTestCase(unittest.TestCase): | |||
| 97 | 98 | ||
| 98 | def setUp(self): | 99 | def setUp(self): |
| 99 | self.tempdirobj = tempfile.TemporaryDirectory(prefix="repo_tests") | 100 | self.tempdirobj = tempfile.TemporaryDirectory(prefix="repo_tests") |
| 100 | self.tempdir = self.tempdirobj.name | 101 | self.tempdir = Path(self.tempdirobj.name) |
| 101 | self.repodir = os.path.join(self.tempdir, ".repo") | 102 | self.repodir = self.tempdir / ".repo" |
| 102 | self.manifest_dir = os.path.join(self.repodir, "manifests") | 103 | self.manifest_dir = self.repodir / "manifests" |
| 103 | self.manifest_file = os.path.join( | 104 | self.manifest_file = self.repodir / manifest_xml.MANIFEST_FILE_NAME |
| 104 | self.repodir, manifest_xml.MANIFEST_FILE_NAME | 105 | self.local_manifest_dir = ( |
| 106 | self.repodir / manifest_xml.LOCAL_MANIFESTS_DIR_NAME | ||
| 105 | ) | 107 | ) |
| 106 | self.local_manifest_dir = os.path.join( | 108 | self.repodir.mkdir() |
| 107 | self.repodir, manifest_xml.LOCAL_MANIFESTS_DIR_NAME | 109 | self.manifest_dir.mkdir() |
| 108 | ) | ||
| 109 | os.mkdir(self.repodir) | ||
| 110 | os.mkdir(self.manifest_dir) | ||
| 111 | 110 | ||
| 112 | # The manifest parsing really wants a git repo currently. | 111 | # The manifest parsing really wants a git repo currently. |
| 113 | gitdir = os.path.join(self.repodir, "manifests.git") | 112 | gitdir = self.repodir / "manifests.git" |
| 114 | os.mkdir(gitdir) | 113 | gitdir.mkdir() |
| 115 | with open(os.path.join(gitdir, "config"), "w") as fp: | 114 | (gitdir / "config").write_text( |
| 116 | fp.write( | 115 | """[remote "origin"] |
| 117 | """[remote "origin"] | ||
| 118 | url = https://localhost:0/manifest | 116 | url = https://localhost:0/manifest |
| 119 | """ | 117 | """ |
| 120 | ) | 118 | ) |
| 121 | 119 | ||
| 122 | def tearDown(self): | 120 | def tearDown(self): |
| 123 | self.tempdirobj.cleanup() | 121 | self.tempdirobj.cleanup() |
| 124 | 122 | ||
| 125 | def getXmlManifest(self, data): | 123 | def getXmlManifest(self, data): |
| 126 | """Helper to initialize a manifest for testing.""" | 124 | """Helper to initialize a manifest for testing.""" |
| 127 | with open(self.manifest_file, "w", encoding="utf-8") as fp: | 125 | self.manifest_file.write_text(data, encoding="utf-8") |
| 128 | fp.write(data) | 126 | return manifest_xml.XmlManifest( |
| 129 | return manifest_xml.XmlManifest(self.repodir, self.manifest_file) | 127 | str(self.repodir), str(self.manifest_file) |
| 128 | ) | ||
| 130 | 129 | ||
| 131 | @staticmethod | 130 | @staticmethod |
| 132 | def encodeXmlAttr(attr): | 131 | def encodeXmlAttr(attr): |
| @@ -243,12 +242,14 @@ class XmlManifestTests(ManifestParseTestCase): | |||
| 243 | 242 | ||
| 244 | def test_link(self): | 243 | def test_link(self): |
| 245 | """Verify Link handling with new names.""" | 244 | """Verify Link handling with new names.""" |
| 246 | manifest = manifest_xml.XmlManifest(self.repodir, self.manifest_file) | 245 | manifest = manifest_xml.XmlManifest( |
| 247 | with open(os.path.join(self.manifest_dir, "foo.xml"), "w") as fp: | 246 | str(self.repodir), str(self.manifest_file) |
| 248 | fp.write("<manifest></manifest>") | 247 | ) |
| 248 | (self.manifest_dir / "foo.xml").write_text("<manifest></manifest>") | ||
| 249 | manifest.Link("foo.xml") | 249 | manifest.Link("foo.xml") |
| 250 | with open(self.manifest_file) as fp: | 250 | self.assertIn( |
| 251 | self.assertIn('<include name="foo.xml" />', fp.read()) | 251 | '<include name="foo.xml" />', self.manifest_file.read_text() |
| 252 | ) | ||
| 252 | 253 | ||
| 253 | def test_toxml_empty(self): | 254 | def test_toxml_empty(self): |
| 254 | """Verify the ToXml() helper.""" | 255 | """Verify the ToXml() helper.""" |
| @@ -406,10 +407,9 @@ class IncludeElementTests(ManifestParseTestCase): | |||
| 406 | 407 | ||
| 407 | def test_revision_default(self): | 408 | def test_revision_default(self): |
| 408 | """Check handling of revision attribute.""" | 409 | """Check handling of revision attribute.""" |
| 409 | root_m = os.path.join(self.manifest_dir, "root.xml") | 410 | root_m = self.manifest_dir / "root.xml" |
| 410 | with open(root_m, "w") as fp: | 411 | root_m.write_text( |
| 411 | fp.write( | 412 | """ |
| 412 | """ | ||
| 413 | <manifest> | 413 | <manifest> |
| 414 | <remote name="test-remote" fetch="http://localhost" /> | 414 | <remote name="test-remote" fetch="http://localhost" /> |
| 415 | <default remote="test-remote" revision="refs/heads/main" /> | 415 | <default remote="test-remote" revision="refs/heads/main" /> |
| @@ -418,17 +418,16 @@ class IncludeElementTests(ManifestParseTestCase): | |||
| 418 | <project name="root-name2" path="root-path2" /> | 418 | <project name="root-name2" path="root-path2" /> |
| 419 | </manifest> | 419 | </manifest> |
| 420 | """ | 420 | """ |
| 421 | ) | 421 | ) |
| 422 | with open(os.path.join(self.manifest_dir, "stable.xml"), "w") as fp: | 422 | (self.manifest_dir / "stable.xml").write_text( |
| 423 | fp.write( | 423 | """ |
| 424 | """ | ||
| 425 | <manifest> | 424 | <manifest> |
| 426 | <project name="stable-name1" path="stable-path1" /> | 425 | <project name="stable-name1" path="stable-path1" /> |
| 427 | <project name="stable-name2" path="stable-path2" revision="stable-branch2" /> | 426 | <project name="stable-name2" path="stable-path2" revision="stable-branch2" /> |
| 428 | </manifest> | 427 | </manifest> |
| 429 | """ | 428 | """ |
| 430 | ) | 429 | ) |
| 431 | include_m = manifest_xml.XmlManifest(self.repodir, root_m) | 430 | include_m = manifest_xml.XmlManifest(str(self.repodir), str(root_m)) |
| 432 | for proj in include_m.projects: | 431 | for proj in include_m.projects: |
| 433 | if proj.name == "root-name1": | 432 | if proj.name == "root-name1": |
| 434 | # Check include revision not set on root level proj. | 433 | # Check include revision not set on root level proj. |
| @@ -444,10 +443,9 @@ class IncludeElementTests(ManifestParseTestCase): | |||
| 444 | self.assertEqual("stable-branch2", proj.revisionExpr) | 443 | self.assertEqual("stable-branch2", proj.revisionExpr) |
| 445 | 444 | ||
| 446 | def test_group_levels(self): | 445 | def test_group_levels(self): |
| 447 | root_m = os.path.join(self.manifest_dir, "root.xml") | 446 | root_m = self.manifest_dir / "root.xml" |
| 448 | with open(root_m, "w") as fp: | 447 | root_m.write_text( |
| 449 | fp.write( | 448 | """ |
| 450 | """ | ||
| 451 | <manifest> | 449 | <manifest> |
| 452 | <remote name="test-remote" fetch="http://localhost" /> | 450 | <remote name="test-remote" fetch="http://localhost" /> |
| 453 | <default remote="test-remote" revision="refs/heads/main" /> | 451 | <default remote="test-remote" revision="refs/heads/main" /> |
| @@ -456,25 +454,23 @@ class IncludeElementTests(ManifestParseTestCase): | |||
| 456 | <project name="root-name2" path="root-path2" groups="r2g1,r2g2" /> | 454 | <project name="root-name2" path="root-path2" groups="r2g1,r2g2" /> |
| 457 | </manifest> | 455 | </manifest> |
| 458 | """ | 456 | """ |
| 459 | ) | 457 | ) |
| 460 | with open(os.path.join(self.manifest_dir, "level1.xml"), "w") as fp: | 458 | (self.manifest_dir / "level1.xml").write_text( |
| 461 | fp.write( | 459 | """ |
| 462 | """ | ||
| 463 | <manifest> | 460 | <manifest> |
| 464 | <include name="level2.xml" groups="level2-group" /> | 461 | <include name="level2.xml" groups="level2-group" /> |
| 465 | <project name="level1-name1" path="level1-path1" /> | 462 | <project name="level1-name1" path="level1-path1" /> |
| 466 | </manifest> | 463 | </manifest> |
| 467 | """ | 464 | """ |
| 468 | ) | 465 | ) |
| 469 | with open(os.path.join(self.manifest_dir, "level2.xml"), "w") as fp: | 466 | (self.manifest_dir / "level2.xml").write_text( |
| 470 | fp.write( | 467 | """ |
| 471 | """ | ||
| 472 | <manifest> | 468 | <manifest> |
| 473 | <project name="level2-name1" path="level2-path1" groups="l2g1,l2g2" /> | 469 | <project name="level2-name1" path="level2-path1" groups="l2g1,l2g2" /> |
| 474 | </manifest> | 470 | </manifest> |
| 475 | """ | 471 | """ |
| 476 | ) | 472 | ) |
| 477 | include_m = manifest_xml.XmlManifest(self.repodir, root_m) | 473 | include_m = manifest_xml.XmlManifest(str(self.repodir), str(root_m)) |
| 478 | for proj in include_m.projects: | 474 | for proj in include_m.projects: |
| 479 | if proj.name == "root-name1": | 475 | if proj.name == "root-name1": |
| 480 | # Check include group not set on root level proj. | 476 | # Check include group not set on root level proj. |
| @@ -510,9 +506,8 @@ class IncludeElementTests(ManifestParseTestCase): | |||
| 510 | manifest.ToXml() | 506 | manifest.ToXml() |
| 511 | 507 | ||
| 512 | # Setup target of the include. | 508 | # Setup target of the include. |
| 513 | target = os.path.join(self.tempdir, "target.xml") | 509 | target = self.tempdir / "target.xml" |
| 514 | with open(target, "w") as fp: | 510 | target.write_text("<manifest></manifest>") |
| 515 | fp.write("<manifest></manifest>") | ||
| 516 | 511 | ||
| 517 | # Include with absolute path. | 512 | # Include with absolute path. |
| 518 | parse(os.path.abspath(target)) | 513 | parse(os.path.abspath(target)) |
| @@ -526,12 +521,9 @@ class IncludeElementTests(ManifestParseTestCase): | |||
| 526 | def parse(name): | 521 | def parse(name): |
| 527 | name = self.encodeXmlAttr(name) | 522 | name = self.encodeXmlAttr(name) |
| 528 | # Setup target of the include. | 523 | # Setup target of the include. |
| 529 | with open( | 524 | (self.manifest_dir / "target.xml").write_text( |
| 530 | os.path.join(self.manifest_dir, "target.xml"), | 525 | f'<manifest><include name="{name}"/></manifest>' |
| 531 | "w", | 526 | ) |
| 532 | encoding="utf-8", | ||
| 533 | ) as fp: | ||
| 534 | fp.write(f'<manifest><include name="{name}"/></manifest>') | ||
| 535 | 527 | ||
| 536 | manifest = self.getXmlManifest( | 528 | manifest = self.getXmlManifest( |
| 537 | """ | 529 | """ |
