621
638
self.assertEqualDiff(content, open(path, 'r').read())
641
class TestCaseWithTransport(TestCaseInTempDir):
642
"""A test case that provides get_url and get_readonly_url facilities.
644
These back onto two transport servers, one for readonly access and one for
647
If no explicit class is provided for readonly access, a
648
ReadonlyTransportDecorator is used instead which allows the use of non disk
649
based read write transports.
651
If an explicit class is provided for readonly access, that server and the
652
readwrite one must both define get_url() as resolving to os.getcwd().
655
def __init__(self, methodName='testMethod'):
656
super(TestCaseWithTransport, self).__init__(methodName)
657
self.__readonly_server = None
659
self.transport_server = default_transport
660
self.transport_readonly_server = None
662
def get_readonly_url(self, relpath=None):
663
"""Get a URL for the readonly transport.
665
This will either be backed by '.' or a decorator to the transport
666
used by self.get_url()
667
relpath provides for clients to get a path relative to the base url.
668
These should only be downwards relative, not upwards.
670
if self.__readonly_server is None:
671
if self.transport_readonly_server is None:
672
# readonly decorator requested
673
# bring up the server
675
self.__readonly_server = ReadonlyServer()
676
self.__readonly_server.setUp(self.__server)
678
self.__readonly_server = self.transport_readonly_server()
679
self.__readonly_server.setUp()
680
self.addCleanup(self.__readonly_server.tearDown)
681
base = self.__readonly_server.get_url()
682
if relpath is not None:
683
if not base.endswith('/'):
685
base = base + relpath
688
def get_url(self, relpath=None):
689
"""Get a URL for the readwrite transport.
691
This will either be backed by '.' or to an equivalent non-file based
693
relpath provides for clients to get a path relative to the base url.
694
These should only be downwards relative, not upwards.
696
if self.__server is None:
697
self.__server = self.transport_server()
698
self.__server.setUp()
699
self.addCleanup(self.__server.tearDown)
700
base = self.__server.get_url()
701
if relpath is not None and relpath != '.':
702
if not base.endswith('/'):
704
base = base + relpath
707
def make_branch(self, relpath):
708
"""Create a branch on the transport at relpath."""
710
url = self.get_url(relpath)
711
segments = relpath.split('/')
712
if segments and segments[-1] not in ('', '.'):
713
parent = self.get_url('/'.join(segments[:-1]))
714
t = bzrlib.transport.get_transport(parent)
716
t.mkdir(segments[-1])
719
return bzrlib.branch.Branch.create(url)
720
except UninitializableFormat:
721
raise TestSkipped("Format %s is not initializable.")
723
def make_branch_and_tree(self, relpath):
724
"""Create a branch on the transport and a tree locally.
728
b = self.make_branch(relpath)
729
return WorkingTree.create(b, relpath)
732
class ChrootedTestCase(TestCaseWithTransport):
733
"""A support class that provides readonly urls outside the local namespace.
735
This is done by checking if self.transport_server is a MemoryServer. if it
736
is then we are chrooted already, if it is not then an HttpServer is used
739
TODO RBC 20060127: make this an option to TestCaseWithTransport so it can
740
be used without needed to redo it when a different
745
super(ChrootedTestCase, self).setUp()
746
if not self.transport_server == bzrlib.transport.memory.MemoryServer:
747
self.transport_readonly_server = bzrlib.transport.http.HttpServer
624
750
def filter_suite_by_re(suite, pattern):
625
751
result = TestSuite()
626
752
filter_re = re.compile(pattern)
658
785
def selftest(verbose=False, pattern=".*", stop_on_failure=True,
660
788
"""Run the whole test suite under the enhanced runner"""
661
return run_suite(test_suite(), 'testbzr', verbose=verbose, pattern=pattern,
662
stop_on_failure=stop_on_failure, keep_output=keep_output)
789
global default_transport
790
if transport is None:
791
transport = default_transport
792
old_transport = default_transport
793
default_transport = transport
796
return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
797
stop_on_failure=stop_on_failure, keep_output=keep_output,
800
default_transport = old_transport
665
804
def test_suite():
762
896
for m in (MODULES_TO_DOCTEST):
763
897
suite.addTest(DocTestSuite(m))
764
898
for name, plugin in bzrlib.plugin.all_plugins().items():
765
if hasattr(plugin, 'test_suite'):
899
if getattr(plugin, 'test_suite', None) is not None:
766
900
suite.addTest(plugin.test_suite())
904
def adapt_modules(mods_list, adapter, loader, suite):
905
"""Adapt the modules in mods_list using adapter and add to suite."""
906
for mod_name in mods_list:
907
mod = _load_module_by_name(mod_name)
908
for test in iter_suite_tests(loader.loadTestsFromModule(mod)):
909
suite.addTests(adapter.adapt(test))
770
912
def _load_module_by_name(mod_name):
771
913
parts = mod_name.split('.')
772
914
module = __import__(mod_name)