From 06da9987f6be6ddc1637e8ae02646d6dfab09862 Mon Sep 17 00:00:00 2001 From: Michael Kelly Date: Wed, 30 Jun 2021 01:58:28 -0700 Subject: Gracefully ignore bad remove-project line Sometimes, we don't care if the remove project is referring to a non-existing project and we can just ignore it. This change allows us to ignore remove-project entries if the project that they refer to doesn't exist, making them effectively a no-op. Because this change breaks existing configuration, we allow this to be configuration controlled using the `optional` attribute in the remove-project tag. Change-Id: I6313a02983e81344eadcb4e47d7d6b037ee7420e Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/310964 Tested-by: Michael Kelly Reviewed-by: Mike Frysinger --- tests/test_manifest_xml.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'tests/test_manifest_xml.py') diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py index 55468b51..96ee4c4a 100644 --- a/tests/test_manifest_xml.py +++ b/tests/test_manifest_xml.py @@ -638,3 +638,53 @@ class RemoteElementTests(ManifestParseTestCase): self.assertNotEqual(a, manifest_xml._Default()) self.assertNotEqual(a, 123) self.assertNotEqual(a, None) + + +class RemoveProjectElementTests(ManifestParseTestCase): + """Tests for .""" + + def test_remove_one_project(self): + manifest = self.getXmlManifest(""" + + + + + + +""") + self.assertEqual(manifest.projects, []) + + def test_remove_one_project_one_remains(self): + manifest = self.getXmlManifest(""" + + + + + + + +""") + + self.assertEqual(len(manifest.projects), 1) + self.assertEqual(manifest.projects[0].name, 'yourproject') + + def test_remove_one_project_doesnt_exist(self): + with self.assertRaises(manifest_xml.ManifestParseError): + manifest = self.getXmlManifest(""" + + + + + +""") + manifest.projects + + def test_remove_one_optional_project_doesnt_exist(self): + manifest = self.getXmlManifest(""" + + + + + +""") + self.assertEqual(manifest.projects, []) -- cgit v1.2.3-54-g00ecf