Skip to content

Commit

Permalink
Merge 49b6080 into c67c072
Browse files Browse the repository at this point in the history
  • Loading branch information
Fenn-CS committed Sep 25, 2021
2 parents c67c072 + 49b6080 commit 38dc870
Show file tree
Hide file tree
Showing 16 changed files with 325 additions and 287 deletions.
Empty file added newsfragments/3788.minor
Empty file.
5 changes: 3 additions & 2 deletions src/allmydata/test/mutable/test_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
if PY2:
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401

from twisted.trial import unittest
from ..common import AsyncTestCase
from foolscap.api import flushEventualQueue
from allmydata.monitor import Monitor
from allmydata.mutable.common import CorruptShareError
from .util import PublishMixin, corrupt, CheckerMixin

class Checker(unittest.TestCase, CheckerMixin, PublishMixin):
class Checker(AsyncTestCase, CheckerMixin, PublishMixin):
def setUp(self):
super(Checker, self).setUp()
return self.publish_one()


Expand Down
17 changes: 10 additions & 7 deletions src/allmydata/test/mutable/test_datahandle.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
if PY2:
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401

from twisted.trial import unittest
from ..common import SyncTestCase
from allmydata.mutable.publish import MutableData
from testtools.matchers import Equals, HasLength

class DataHandle(unittest.TestCase):

class DataHandle(SyncTestCase):
def setUp(self):
super(DataHandle, self).setUp()
self.test_data = b"Test Data" * 50000
self.uploadable = MutableData(self.test_data)

Expand All @@ -26,28 +29,28 @@ def test_datahandle_read(self):
data = b"".join(data)
start = i
end = i + chunk_size
self.failUnlessEqual(data, self.test_data[start:end])
self.assertThat(data, Equals(self.test_data[start:end]))


def test_datahandle_get_size(self):
actual_size = len(self.test_data)
size = self.uploadable.get_size()
self.failUnlessEqual(size, actual_size)
self.assertThat(size, Equals(actual_size))


def test_datahandle_get_size_out_of_order(self):
# We should be able to call get_size whenever we want without
# disturbing the location of the seek pointer.
chunk_size = 100
data = self.uploadable.read(chunk_size)
self.failUnlessEqual(b"".join(data), self.test_data[:chunk_size])
self.assertThat(b"".join(data), Equals(self.test_data[:chunk_size]))

# Now get the size.
size = self.uploadable.get_size()
self.failUnlessEqual(size, len(self.test_data))
self.assertThat(self.test_data, HasLength(size))

# Now get more data. We should be right where we left off.
more_data = self.uploadable.read(chunk_size)
start = chunk_size
end = chunk_size * 2
self.failUnlessEqual(b"".join(more_data), self.test_data[start:end])
self.assertThat(b"".join(more_data), Equals(self.test_data[start:end]))
5 changes: 3 additions & 2 deletions src/allmydata/test/mutable/test_different_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
if PY2:
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401

from twisted.trial import unittest
from ..common import AsyncTestCase
from .util import FakeStorage, make_nodemaker

class DifferentEncoding(unittest.TestCase):
class DifferentEncoding(AsyncTestCase):
def setUp(self):
super(DifferentEncoding, self).setUp()
self._storage = s = FakeStorage()
self.nodemaker = make_nodemaker(s)

Expand Down
10 changes: 6 additions & 4 deletions src/allmydata/test/mutable/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
if PY2:
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401

from twisted.trial import unittest
from ..common import SyncTestCase
from allmydata.mutable.common import NeedMoreDataError, UncoordinatedWriteError

class Exceptions(unittest.TestCase):

class Exceptions(SyncTestCase):
def test_repr(self):
nmde = NeedMoreDataError(100, 50, 100)
self.failUnless("NeedMoreDataError" in repr(nmde), repr(nmde))
self.assertTrue("NeedMoreDataError" in repr(nmde), msg=repr(nmde))
self.assertTrue("NeedMoreDataError" in repr(nmde), msg=repr(nmde))
ucwe = UncoordinatedWriteError()
self.failUnless("UncoordinatedWriteError" in repr(ucwe), repr(ucwe))
self.assertTrue("UncoordinatedWriteError" in repr(ucwe), msg=repr(ucwe))
6 changes: 4 additions & 2 deletions src/allmydata/test/mutable/test_filehandle.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@

import os
from io import BytesIO
from twisted.trial import unittest
from ..common import SyncTestCase
from allmydata.mutable.publish import MutableFileHandle

class FileHandle(unittest.TestCase):

class FileHandle(SyncTestCase):
def setUp(self):
super(FileHandle, self).setUp()
self.test_data = b"Test Data" * 50000
self.sio = BytesIO(self.test_data)
self.uploadable = MutableFileHandle(self.sio)
Expand Down
Loading

0 comments on commit 38dc870

Please sign in to comment.