mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
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:
parent
78f4dd3138
commit
5ba2120362
@ -122,9 +122,13 @@ class _Default(object):
|
|||||||
sync_tags = True
|
sync_tags = True
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
|
if not isinstance(other, _Default):
|
||||||
|
return False
|
||||||
return self.__dict__ == other.__dict__
|
return self.__dict__ == other.__dict__
|
||||||
|
|
||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
|
if not isinstance(other, _Default):
|
||||||
|
return True
|
||||||
return self.__dict__ != other.__dict__
|
return self.__dict__ != other.__dict__
|
||||||
|
|
||||||
|
|
||||||
@ -147,12 +151,18 @@ class _XmlRemote(object):
|
|||||||
self.resolvedFetchUrl = self._resolveFetchUrl()
|
self.resolvedFetchUrl = self._resolveFetchUrl()
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
|
if not isinstance(other, _XmlRemote):
|
||||||
|
return False
|
||||||
return self.__dict__ == other.__dict__
|
return self.__dict__ == other.__dict__
|
||||||
|
|
||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
|
if not isinstance(other, _XmlRemote):
|
||||||
|
return True
|
||||||
return self.__dict__ != other.__dict__
|
return self.__dict__ != other.__dict__
|
||||||
|
|
||||||
def _resolveFetchUrl(self):
|
def _resolveFetchUrl(self):
|
||||||
|
if self.fetchUrl is None:
|
||||||
|
return ''
|
||||||
url = self.fetchUrl.rstrip('/')
|
url = self.fetchUrl.rstrip('/')
|
||||||
manifestUrl = self.manifestUrl.rstrip('/')
|
manifestUrl = self.manifestUrl.rstrip('/')
|
||||||
# urljoin will gets confused over quite a few things. The ones we care
|
# urljoin will gets confused over quite a few things. The ones we care
|
||||||
|
@ -607,3 +607,34 @@ class ContactinfoElementTests(ManifestParseTestCase):
|
|||||||
'<?xml version="1.0" ?><manifest>'
|
'<?xml version="1.0" ?><manifest>'
|
||||||
f'<contactinfo bugurl="{bugurl}"/>'
|
f'<contactinfo bugurl="{bugurl}"/>'
|
||||||
'</manifest>')
|
'</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)
|
||||||
|
Loading…
Reference in New Issue
Block a user