repo: properly handle NoneType in Default/Remote equality checks

BUG=none
TEST=none

Change-Id: I4ccdbbc7ba4b6f6e20c6959db1b46fdb44ea2819
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/308982
Reviewed-by: Mike Frysinger <vapier@google.com>
Tested-by: Jack Neus <jackneus@google.com>
This commit is contained in:
Jack Neus 2021-06-09 15:21:25 +00:00
parent 78f4dd3138
commit 5ba2120362
2 changed files with 41 additions and 0 deletions

View File

@ -122,9 +122,13 @@ class _Default(object):
sync_tags = True
def __eq__(self, other):
if not isinstance(other, _Default):
return False
return self.__dict__ == other.__dict__
def __ne__(self, other):
if not isinstance(other, _Default):
return True
return self.__dict__ != other.__dict__
@ -147,12 +151,18 @@ class _XmlRemote(object):
self.resolvedFetchUrl = self._resolveFetchUrl()
def __eq__(self, other):
if not isinstance(other, _XmlRemote):
return False
return self.__dict__ == other.__dict__
def __ne__(self, other):
if not isinstance(other, _XmlRemote):
return True
return self.__dict__ != other.__dict__
def _resolveFetchUrl(self):
if self.fetchUrl is None:
return ''
url = self.fetchUrl.rstrip('/')
manifestUrl = self.manifestUrl.rstrip('/')
# urljoin will gets confused over quite a few things. The ones we care

View File

@ -607,3 +607,34 @@ class ContactinfoElementTests(ManifestParseTestCase):
'<?xml version="1.0" ?><manifest>'
f'<contactinfo bugurl="{bugurl}"/>'
'</manifest>')
class DefaultElementTests(ManifestParseTestCase):
"""Tests for <default>."""
def test_default(self):
"""Check default settings."""
a = manifest_xml._Default()
a.revisionExpr = 'foo'
a.remote = manifest_xml._XmlRemote(name='remote')
b = manifest_xml._Default()
b.revisionExpr = 'bar'
self.assertEqual(a, a)
self.assertNotEqual(a, b)
self.assertNotEqual(b, a.remote)
self.assertNotEqual(a, 123)
self.assertNotEqual(a, None)
class RemoteElementTests(ManifestParseTestCase):
"""Tests for <remote>."""
def test_remote(self):
"""Check remote settings."""
a = manifest_xml._XmlRemote(name='foo')
b = manifest_xml._XmlRemote(name='bar')
self.assertEqual(a, a)
self.assertNotEqual(a, b)
self.assertNotEqual(a, manifest_xml._Default())
self.assertNotEqual(a, 123)
self.assertNotEqual(a, None)