diff options
author | Jack Neus <jackneus@google.com> | 2021-06-09 15:21:25 +0000 |
---|---|---|
committer | Jack Neus <jackneus@google.com> | 2021-06-11 13:54:32 +0000 |
commit | 5ba2120362ceb49b89e0536108792fd7c824e28a (patch) | |
tree | b42b5ad7214b80823d469af09005a3a5e14b989f | |
parent | 78f4dd3138b774dfea9d789d7324b8857f5a1a58 (diff) | |
download | git-repo-5ba2120362ceb49b89e0536108792fd7c824e28a.tar.gz |
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>
-rw-r--r-- | manifest_xml.py | 10 | ||||
-rw-r--r-- | tests/test_manifest_xml.py | 31 |
2 files changed, 41 insertions, 0 deletions
diff --git a/manifest_xml.py b/manifest_xml.py index 30e96584..09cae6f5 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
@@ -122,9 +122,13 @@ class _Default(object): | |||
122 | sync_tags = True | 122 | sync_tags = True |
123 | 123 | ||
124 | def __eq__(self, other): | 124 | def __eq__(self, other): |
125 | if not isinstance(other, _Default): | ||
126 | return False | ||
125 | return self.__dict__ == other.__dict__ | 127 | return self.__dict__ == other.__dict__ |
126 | 128 | ||
127 | def __ne__(self, other): | 129 | def __ne__(self, other): |
130 | if not isinstance(other, _Default): | ||
131 | return True | ||
128 | return self.__dict__ != other.__dict__ | 132 | return self.__dict__ != other.__dict__ |
129 | 133 | ||
130 | 134 | ||
@@ -147,12 +151,18 @@ class _XmlRemote(object): | |||
147 | self.resolvedFetchUrl = self._resolveFetchUrl() | 151 | self.resolvedFetchUrl = self._resolveFetchUrl() |
148 | 152 | ||
149 | def __eq__(self, other): | 153 | def __eq__(self, other): |
154 | if not isinstance(other, _XmlRemote): | ||
155 | return False | ||
150 | return self.__dict__ == other.__dict__ | 156 | return self.__dict__ == other.__dict__ |
151 | 157 | ||
152 | def __ne__(self, other): | 158 | def __ne__(self, other): |
159 | if not isinstance(other, _XmlRemote): | ||
160 | return True | ||
153 | return self.__dict__ != other.__dict__ | 161 | return self.__dict__ != other.__dict__ |
154 | 162 | ||
155 | def _resolveFetchUrl(self): | 163 | def _resolveFetchUrl(self): |
164 | if self.fetchUrl is None: | ||
165 | return '' | ||
156 | url = self.fetchUrl.rstrip('/') | 166 | url = self.fetchUrl.rstrip('/') |
157 | manifestUrl = self.manifestUrl.rstrip('/') | 167 | manifestUrl = self.manifestUrl.rstrip('/') |
158 | # urljoin will gets confused over quite a few things. The ones we care | 168 | # urljoin will gets confused over quite a few things. The ones we care |
diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py index bd74780d..2a16900a 100644 --- a/tests/test_manifest_xml.py +++ b/tests/test_manifest_xml.py | |||
@@ -607,3 +607,34 @@ class ContactinfoElementTests(ManifestParseTestCase): | |||
607 | '<?xml version="1.0" ?><manifest>' | 607 | '<?xml version="1.0" ?><manifest>' |
608 | f'<contactinfo bugurl="{bugurl}"/>' | 608 | f'<contactinfo bugurl="{bugurl}"/>' |
609 | '</manifest>') | 609 | '</manifest>') |
610 | |||
611 | |||
612 | class DefaultElementTests(ManifestParseTestCase): | ||
613 | """Tests for <default>.""" | ||
614 | |||
615 | def test_default(self): | ||
616 | """Check default settings.""" | ||
617 | a = manifest_xml._Default() | ||
618 | a.revisionExpr = 'foo' | ||
619 | a.remote = manifest_xml._XmlRemote(name='remote') | ||
620 | b = manifest_xml._Default() | ||
621 | b.revisionExpr = 'bar' | ||
622 | self.assertEqual(a, a) | ||
623 | self.assertNotEqual(a, b) | ||
624 | self.assertNotEqual(b, a.remote) | ||
625 | self.assertNotEqual(a, 123) | ||
626 | self.assertNotEqual(a, None) | ||
627 | |||
628 | |||
629 | class RemoteElementTests(ManifestParseTestCase): | ||
630 | """Tests for <remote>.""" | ||
631 | |||
632 | def test_remote(self): | ||
633 | """Check remote settings.""" | ||
634 | a = manifest_xml._XmlRemote(name='foo') | ||
635 | b = manifest_xml._XmlRemote(name='bar') | ||
636 | self.assertEqual(a, a) | ||
637 | self.assertNotEqual(a, b) | ||
638 | self.assertNotEqual(a, manifest_xml._Default()) | ||
639 | self.assertNotEqual(a, 123) | ||
640 | self.assertNotEqual(a, None) | ||