Test and bugfix for LiteralFileNode equality.

This commit is contained in:
Itamar Turner-Trauring 2020-09-28 16:49:30 -04:00
parent 66c6522325
commit e3a9f5fa75
2 changed files with 23 additions and 5 deletions

View File

@ -32,16 +32,15 @@ class _ImmutableFileNodeBase(object):
def __hash__(self):
return self.u.__hash__()
def __eq__(self, other):
if isinstance(other, _ImmutableFileNodeBase):
return self.u.__eq__(other.u)
return self.u == other.u
else:
return False
def __ne__(self, other):
if isinstance(other, _ImmutableFileNodeBase):
return self.u.__eq__(other.u)
else:
return True
return not self == other
class LiteralFileNode(_ImmutableFileNodeBase):

View File

@ -26,6 +26,7 @@ from allmydata.util.consumer import download_to_data
from allmydata.interfaces import NotEnoughSharesError
from allmydata.immutable.upload import Data
from allmydata.immutable.downloader import finder
from allmydata.immutable.literal import LiteralFileNode
from .no_network import (
NoNetworkServer,
@ -340,6 +341,24 @@ class Test(GridTestMixin, unittest.TestCase, common.ShouldFailMixin):
return d
class LiteralFileNodeTests(unittest.TestCase):
"""Tests for LiteralFileNode."""
def test_equality(self):
"""LiteralFileNodes are equal iff they have the same URI."""
uri1 = uri.LiteralFileURI(b"1")
uri2 = uri.LiteralFileURI(b"2")
lfn1 = LiteralFileNode(uri1)
lfn1b = LiteralFileNode(uri1)
lfn2 = LiteralFileNode(uri2)
self.assertTrue(lfn1 == lfn1b)
self.assertFalse(lfn1 != lfn1b)
self.assertTrue(lfn1 != lfn2)
self.assertFalse(lfn1 == lfn2)
self.assertTrue(lfn1 != 300)
self.assertFalse(lfn1 == 300)
# XXX extend these tests to show bad behavior of various kinds from servers:
# raising exception from each remove_foo() method, for example