From 37ac3d626fc08fe47e937704913a626d26864a37 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Thu, 25 Feb 2021 04:54:56 -0500 Subject: [PATCH] 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 Tested-by: Mike Frysinger --- tests/test_manifest_xml.py | 188 +++++++++++++++++++------------------ 1 file 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 import manifest_xml +class ManifestParseTestCase(unittest.TestCase): + """TestCase for parsing manifests.""" + + def setUp(self): + self.tempdir = tempfile.mkdtemp(prefix='repo_tests') + self.repodir = os.path.join(self.tempdir, '.repo') + self.manifest_dir = os.path.join(self.repodir, 'manifests') + self.manifest_file = os.path.join( + self.repodir, manifest_xml.MANIFEST_FILE_NAME) + self.local_manifest_dir = os.path.join( + self.repodir, manifest_xml.LOCAL_MANIFESTS_DIR_NAME) + os.mkdir(self.repodir) + os.mkdir(self.manifest_dir) + + # The manifest parsing really wants a git repo currently. + gitdir = os.path.join(self.repodir, 'manifests.git') + os.mkdir(gitdir) + with open(os.path.join(gitdir, 'config'), 'w') as fp: + fp.write("""[remote "origin"] + url = https://localhost:0/manifest +""") + + def tearDown(self): + shutil.rmtree(self.tempdir, ignore_errors=True) + + def getXmlManifest(self, data): + """Helper to initialize a manifest for testing.""" + with open(self.manifest_file, 'w') as fp: + fp.write(data) + return manifest_xml.XmlManifest(self.repodir, self.manifest_file) + + class ManifestValidateFilePaths(unittest.TestCase): """Check _ValidateFilePaths helper. @@ -146,37 +178,9 @@ class ValueTests(unittest.TestCase): manifest_xml.XmlInt(node, 'a') -class XmlManifestTests(unittest.TestCase): +class XmlManifestTests(ManifestParseTestCase): """Check manifest processing.""" - def setUp(self): - self.tempdir = tempfile.mkdtemp(prefix='repo_tests') - self.repodir = os.path.join(self.tempdir, '.repo') - self.manifest_dir = os.path.join(self.repodir, 'manifests') - self.manifest_file = os.path.join( - self.repodir, manifest_xml.MANIFEST_FILE_NAME) - self.local_manifest_dir = os.path.join( - self.repodir, manifest_xml.LOCAL_MANIFESTS_DIR_NAME) - os.mkdir(self.repodir) - os.mkdir(self.manifest_dir) - - # The manifest parsing really wants a git repo currently. - gitdir = os.path.join(self.repodir, 'manifests.git') - os.mkdir(gitdir) - with open(os.path.join(gitdir, 'config'), 'w') as fp: - fp.write("""[remote "origin"] - url = https://localhost:0/manifest -""") - - def tearDown(self): - shutil.rmtree(self.tempdir, ignore_errors=True) - - def getXmlManifest(self, data): - """Helper to initialize a manifest for testing.""" - with open(self.manifest_file, 'w') as fp: - fp.write(data) - return manifest_xml.XmlManifest(self.repodir, self.manifest_file) - def test_empty(self): """Parse an 'empty' manifest file.""" manifest = self.getXmlManifest( @@ -221,67 +225,6 @@ class XmlManifestTests(unittest.TestCase): self.assertEqual(manifest.repo_hooks_project.name, 'repohooks') self.assertEqual(manifest.repo_hooks_project.enabled_repo_hooks, ['a', 'b']) - def test_superproject(self): - """Check superproject settings.""" - manifest = self.getXmlManifest(""" - - - - - -""") - self.assertEqual(manifest.superproject['name'], 'superproject') - self.assertEqual(manifest.superproject['remote'].name, 'test-remote') - self.assertEqual(manifest.superproject['remote'].url, 'http://localhost/superproject') - self.assertEqual( - manifest.ToXml().toxml(), - '' + - '' + - '' + - '' + - '') - - def test_superproject_with_remote(self): - """Check superproject settings.""" - manifest = self.getXmlManifest(""" - - - - - - -""") - self.assertEqual(manifest.superproject['name'], 'platform/superproject') - self.assertEqual(manifest.superproject['remote'].name, 'superproject-remote') - self.assertEqual(manifest.superproject['remote'].url, 'http://localhost/platform/superproject') - self.assertEqual( - manifest.ToXml().toxml(), - '' + - '' + - '' + - '' + - '' + - '') - - def test_superproject_with_defalut_remote(self): - """Check superproject settings.""" - manifest = self.getXmlManifest(""" - - - - - -""") - self.assertEqual(manifest.superproject['name'], 'superproject') - self.assertEqual(manifest.superproject['remote'].name, 'default-remote') - self.assertEqual( - manifest.ToXml().toxml(), - '' + - '' + - '' + - '' + - '') - def test_unknown_tags(self): """Check superproject settings.""" manifest = self.getXmlManifest(""" @@ -389,3 +332,68 @@ class XmlManifestTests(unittest.TestCase): self.assertIn('level2-group', proj.groups) # Check level2 proj group not removed. self.assertIn('l2g1', proj.groups) + + +class SuperProjectTests(ManifestParseTestCase): + """Tests for .""" + + def test_superproject(self): + """Check superproject settings.""" + manifest = self.getXmlManifest(""" + + + + + +""") + self.assertEqual(manifest.superproject['name'], 'superproject') + self.assertEqual(manifest.superproject['remote'].name, 'test-remote') + self.assertEqual(manifest.superproject['remote'].url, 'http://localhost/superproject') + self.assertEqual( + manifest.ToXml().toxml(), + '' + + '' + + '' + + '' + + '') + + def test_remote(self): + """Check superproject settings with a remote.""" + manifest = self.getXmlManifest(""" + + + + + + +""") + self.assertEqual(manifest.superproject['name'], 'platform/superproject') + self.assertEqual(manifest.superproject['remote'].name, 'superproject-remote') + self.assertEqual(manifest.superproject['remote'].url, 'http://localhost/platform/superproject') + self.assertEqual( + manifest.ToXml().toxml(), + '' + + '' + + '' + + '' + + '' + + '') + + def test_defalut_remote(self): + """Check superproject settings with a default remote.""" + manifest = self.getXmlManifest(""" + + + + + +""") + self.assertEqual(manifest.superproject['name'], 'superproject') + self.assertEqual(manifest.superproject['remote'].name, 'default-remote') + self.assertEqual( + manifest.ToXml().toxml(), + '' + + '' + + '' + + '' + + '')