mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-06-21 16:39:38 +00:00
Move FakeCanary to common_util
Couldn't bring myself to move it back to test_storage.
This commit is contained in:
@ -87,31 +87,3 @@ def skip_if_cannot_represent_filename(u):
|
|||||||
u.encode(enc)
|
u.encode(enc)
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
raise unittest.SkipTest("A non-ASCII filename could not be encoded on this platform.")
|
raise unittest.SkipTest("A non-ASCII filename could not be encoded on this platform.")
|
||||||
|
|
||||||
|
|
||||||
class Marker(object):
|
|
||||||
pass
|
|
||||||
|
|
||||||
class FakeCanary(object):
|
|
||||||
"""For use in storage tests.
|
|
||||||
|
|
||||||
Can be moved back to test_storage.py once enough Python 3 porting has been
|
|
||||||
done.
|
|
||||||
"""
|
|
||||||
def __init__(self, ignore_disconnectors=False):
|
|
||||||
self.ignore = ignore_disconnectors
|
|
||||||
self.disconnectors = {}
|
|
||||||
def notifyOnDisconnect(self, f, *args, **kwargs):
|
|
||||||
if self.ignore:
|
|
||||||
return
|
|
||||||
m = Marker()
|
|
||||||
self.disconnectors[m] = (f, args, kwargs)
|
|
||||||
return m
|
|
||||||
def dontNotifyOnDisconnect(self, marker):
|
|
||||||
if self.ignore:
|
|
||||||
return
|
|
||||||
del self.disconnectors[marker]
|
|
||||||
def getRemoteTubID(self):
|
|
||||||
return None
|
|
||||||
def getPeer(self):
|
|
||||||
return "<fake>"
|
|
||||||
|
@ -87,6 +87,34 @@ class StallMixin(object):
|
|||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
class Marker(object):
|
||||||
|
pass
|
||||||
|
|
||||||
|
class FakeCanary(object):
|
||||||
|
"""For use in storage tests.
|
||||||
|
|
||||||
|
Can be moved back to test_storage.py once enough Python 3 porting has been
|
||||||
|
done.
|
||||||
|
"""
|
||||||
|
def __init__(self, ignore_disconnectors=False):
|
||||||
|
self.ignore = ignore_disconnectors
|
||||||
|
self.disconnectors = {}
|
||||||
|
def notifyOnDisconnect(self, f, *args, **kwargs):
|
||||||
|
if self.ignore:
|
||||||
|
return
|
||||||
|
m = Marker()
|
||||||
|
self.disconnectors[m] = (f, args, kwargs)
|
||||||
|
return m
|
||||||
|
def dontNotifyOnDisconnect(self, marker):
|
||||||
|
if self.ignore:
|
||||||
|
return
|
||||||
|
del self.disconnectors[marker]
|
||||||
|
def getRemoteTubID(self):
|
||||||
|
return None
|
||||||
|
def getPeer(self):
|
||||||
|
return "<fake>"
|
||||||
|
|
||||||
|
|
||||||
class ShouldFailMixin(object):
|
class ShouldFailMixin(object):
|
||||||
|
|
||||||
def shouldFail(self, expected_failure, which, substring,
|
def shouldFail(self, expected_failure, which, substring,
|
||||||
|
@ -27,8 +27,7 @@ from allmydata.util import fileutil, hashutil, pollmixin
|
|||||||
from allmydata.storage.server import StorageServer, si_b2a
|
from allmydata.storage.server import StorageServer, si_b2a
|
||||||
from allmydata.storage.crawler import ShareCrawler, TimeSliceExceeded
|
from allmydata.storage.crawler import ShareCrawler, TimeSliceExceeded
|
||||||
|
|
||||||
from allmydata.test.common_py3 import FakeCanary
|
from allmydata.test.common_util import StallMixin, FakeCanary
|
||||||
from allmydata.test.common_util import StallMixin
|
|
||||||
|
|
||||||
class BucketEnumeratingCrawler(ShareCrawler):
|
class BucketEnumeratingCrawler(ShareCrawler):
|
||||||
cpu_slice = 500 # make sure it can complete in a single slice
|
cpu_slice = 500 # make sure it can complete in a single slice
|
||||||
|
@ -52,7 +52,7 @@ from allmydata.storage_client import (
|
|||||||
_StorageServer,
|
_StorageServer,
|
||||||
)
|
)
|
||||||
from .common import LoggingServiceParent, ShouldFailMixin
|
from .common import LoggingServiceParent, ShouldFailMixin
|
||||||
from .common_py3 import FakeCanary
|
from .common_util import FakeCanary
|
||||||
|
|
||||||
|
|
||||||
class UtilTests(unittest.TestCase):
|
class UtilTests(unittest.TestCase):
|
||||||
|
@ -50,7 +50,7 @@ from allmydata.web.storage import (
|
|||||||
StorageStatusElement,
|
StorageStatusElement,
|
||||||
remove_prefix
|
remove_prefix
|
||||||
)
|
)
|
||||||
from .common_py3 import FakeCanary
|
from .common_util import FakeCanary
|
||||||
|
|
||||||
def remove_tags(s):
|
def remove_tags(s):
|
||||||
s = re.sub(br'<[^>]*>', b' ', s)
|
s = re.sub(br'<[^>]*>', b' ', s)
|
||||||
|
@ -33,7 +33,7 @@ from .common import (
|
|||||||
from ..common import (
|
from ..common import (
|
||||||
SameProcessStreamEndpointAssigner,
|
SameProcessStreamEndpointAssigner,
|
||||||
)
|
)
|
||||||
from ..common_py3 import (
|
from ..common_util import (
|
||||||
FakeCanary,
|
FakeCanary,
|
||||||
)
|
)
|
||||||
from ..common_web import (
|
from ..common_web import (
|
||||||
|
Reference in New Issue
Block a user