621
634
self.assertEqualDiff(content, open(path, 'r').read())
637
class TestCaseWithTransport(TestCaseInTempDir):
638
"""A test case that provides get_url and get_readonly_url facilities.
640
These back onto two transport servers, one for readonly access and one for
643
If no explicit class is provided for readonly access, a
644
ReadonlyTransportDecorator is used instead which allows the use of non disk
645
based read write transports.
647
If an explicit class is provided for readonly access, that server and the
648
readwrite one must both define get_url() as resolving to os.getcwd().
651
def __init__(self, methodName='testMethod'):
652
super(TestCaseWithTransport, self).__init__(methodName)
653
self.__readonly_server = None
655
self.transport_server = default_transport
656
self.transport_readonly_server = None
658
def get_readonly_url(self, relpath=None):
659
"""Get a URL for the readonly transport.
661
This will either be backed by '.' or a decorator to the transport
662
used by self.get_url()
663
relpath provides for clients to get a path relative to the base url.
664
These should only be downwards relative, not upwards.
666
if self.__readonly_server is None:
667
if self.transport_readonly_server is None:
668
# readonly decorator requested
669
# bring up the server
671
self.__readonly_server = ReadonlyServer()
672
self.__readonly_server.setUp(self.__server)
674
self.__readonly_server = self.transport_readonly_server()
675
self.__readonly_server.setUp()
676
self.addCleanup(self.__readonly_server.tearDown)
677
base = self.__readonly_server.get_url()
678
if relpath is not None:
679
if not base.endswith('/'):
681
base = base + relpath
684
def get_url(self, relpath=None):
685
"""Get a URL for the readwrite transport.
687
This will either be backed by '.' or to an equivalent non-file based
689
relpath provides for clients to get a path relative to the base url.
690
These should only be downwards relative, not upwards.
692
if self.__server is None:
693
self.__server = self.transport_server()
694
self.__server.setUp()
695
self.addCleanup(self.__server.tearDown)
696
base = self.__server.get_url()
697
if relpath is not None and relpath != '.':
698
if not base.endswith('/'):
700
base = base + relpath
703
def make_branch(self, relpath):
704
"""Create a branch on the transport at relpath."""
706
url = self.get_url(relpath)
707
segments = relpath.split('/')
708
if segments and segments[-1] not in ('', '.'):
709
parent = self.get_url('/'.join(segments[:-1]))
710
t = bzrlib.transport.get_transport(parent)
712
t.mkdir(segments[-1])
715
return bzrlib.branch.Branch.create(url)
716
except UninitializableFormat:
717
raise TestSkipped("Format %s is not initializable.")
719
def make_branch_and_tree(self, relpath):
720
"""Create a branch on the transport and a tree locally.
724
b = self.make_branch(relpath)
725
return WorkingTree.create(b, relpath)
728
class ChrootedTestCase(TestCaseWithTransport):
729
"""A support class that provides readonly urls outside the local namespace.
731
This is done by checking if self.transport_server is a MemoryServer. if it
732
is then we are chrooted already, if it is not then an HttpServer is used
735
TODO RBC 20060127: make this an option to TestCaseWithTransport so it can
736
be used without needed to redo it when a different
741
super(ChrootedTestCase, self).setUp()
742
if not self.transport_server == bzrlib.transport.memory.MemoryServer:
743
self.transport_readonly_server = bzrlib.transport.http.HttpServer
624
746
def filter_suite_by_re(suite, pattern):
625
747
result = TestSuite()
626
748
filter_re = re.compile(pattern)
658
781
def selftest(verbose=False, pattern=".*", stop_on_failure=True,
660
784
"""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)
785
global default_transport
786
if transport is None:
787
transport = default_transport
788
old_transport = default_transport
789
default_transport = transport
792
return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
793
stop_on_failure=stop_on_failure, keep_output=keep_output,
796
default_transport = old_transport
665
800
def test_suite():
761
891
for m in (MODULES_TO_DOCTEST):
762
892
suite.addTest(DocTestSuite(m))
763
893
for name, plugin in bzrlib.plugin.all_plugins().items():
764
if hasattr(plugin, 'test_suite'):
894
if getattr(plugin, 'test_suite', None) is not None:
765
895
suite.addTest(plugin.test_suite())
899
def adapt_modules(mods_list, adapter, loader, suite):
900
"""Adapt the modules in mods_list using adapter and add to suite."""
901
for mod_name in mods_list:
902
mod = _load_module_by_name(mod_name)
903
for test in iter_suite_tests(loader.loadTestsFromModule(mod)):
904
suite.addTests(adapter.adapt(test))
769
907
def _load_module_by_name(mod_name):
770
908
parts = mod_name.split('.')
771
909
module = __import__(mod_name)