47
47
import bzrlib.trace
48
48
from bzrlib.transport import urlescape
49
49
import bzrlib.transport
50
from bzrlib.transport.readonly import ReadonlyServer
50
51
from bzrlib.trace import mutter
51
52
from bzrlib.tests.TestUtil import TestLoader, TestSuite
52
53
from bzrlib.tests.treeshape import build_tree_contents
237
238
_log_file_name = None
238
239
_log_contents = ''
241
def __init__(self, methodName='testMethod'):
242
super(TestCase, self).__init__(methodName)
241
246
unittest.TestCase.setUp(self)
243
247
self._cleanEnvironment()
244
248
bzrlib.trace.disable_default_logging()
245
249
self._startLogFile()
628
632
self.assertEqualDiff(content, open(path, 'r').read())
635
class TestCaseWithTransport(TestCaseInTempDir):
636
"""A test case that provides get_url and get_readonly_url facilities.
638
These back onto two transport servers, one for readonly access and one for
641
If no explicit class is provided for readonly access, a
642
ReadonlyTransportDecorator is used instead which allows the use of non disk
643
based read write transports.
645
If an explicit class is provided for readonly access, that server and the
646
readwrite one must both define get_url() as resolving to os.getcwd().
649
def __init__(self, methodName='testMethod'):
650
super(TestCaseWithTransport, self).__init__(methodName)
651
self.__readonly_server = None
654
def get_readonly_url(self):
655
"""Get a URL for the readonly transport.
657
This will either be backed by '.' or a decorator to the transport
658
used by self.get_url()
660
if self.__readonly_server is None:
661
if self.transport_readonly_server is None:
662
# readonly decorator requested
663
# bring up the server
665
self.__readonly_server = ReadonlyServer()
666
self.__readonly_server.setUp(self.__server)
668
self.__readonly_server = self.transport_readonly_server()
669
self.__readonly_server.setUp()
670
self.addCleanup(self.__readonly_server.tearDown)
671
return self.__readonly_server.get_url()
674
"""Get a URL for the readwrite transport.
676
This will either be backed by '.' or to an equivalent non-file based
679
if self.__server is None:
680
self.__server = self.transport_server()
681
self.__server.setUp()
682
self.addCleanup(self.__server.tearDown)
683
return self.__server.get_url()
631
687
def filter_suite_by_re(suite, pattern):
632
688
result = TestSuite()
633
689
filter_re = re.compile(pattern)
760
816
from bzrlib.branch import BranchTestProviderAdapter
761
817
adapter = BranchTestProviderAdapter(
762
818
bzrlib.transport.local.LocalRelpathServer,
763
bzrlib.transport.local.LocalRelpathServer,
819
# None here will cause a readonly decorator to be created
820
# by the TestCaseWithTransport.get_readonly_transport method.
764
822
bzrlib.branch.BzrBranchFormat._formats.values())
765
823
for mod_name in test_branch_implementations:
766
824
mod = _load_module_by_name(mod_name)