15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
# TODO: Perhaps there should be an API to find out if bzr running under the
19
# test suite -- some plugins might want to avoid making intrusive changes if
20
# this is the case. However, we want behaviour under to test to diverge as
21
# little as possible, so this should be used rarely if it's added at all.
22
# (Suggestion from j-a-meinel, 2005-11-24)
18
24
from cStringIO import StringIO
34
41
import bzrlib.inventory
35
42
import bzrlib.merge3
36
43
import bzrlib.osutils
44
import bzrlib.osutils as osutils
37
45
import bzrlib.plugin
38
46
import bzrlib.store
39
47
import bzrlib.trace
48
from bzrlib.transport import urlescape
40
49
from bzrlib.trace import mutter
41
50
from bzrlib.tests.TestUtil import TestLoader, TestSuite
42
51
from bzrlib.tests.treeshape import build_tree_contents
156
166
def printErrorList(self, flavour, errors):
157
167
for test, err in errors:
158
168
self.stream.writeln(self.separator1)
159
self.stream.writeln("%s: %s" % (flavour,self.getDescription(test)))
169
self.stream.writeln("%s: %s" % (flavour, self.getDescription(test)))
160
170
if hasattr(test, '_get_log'):
161
171
print >>self.stream
162
172
print >>self.stream, \
163
('vvvv[log from %s]' % test).ljust(78,'-')
173
('vvvv[log from %s]' % test.id()).ljust(78,'-')
164
174
print >>self.stream, test._get_log()
165
175
print >>self.stream, \
166
('^^^^[log from %s]' % test).ljust(78,'-')
176
('^^^^[log from %s]' % test.id()).ljust(78,'-')
167
177
self.stream.writeln(self.separator2)
168
178
self.stream.writeln("%s" % err)
258
268
raise AssertionError("texts not equal:\n" +
259
269
self._ndiff_strings(a, b))
271
def assertStartsWith(self, s, prefix):
272
if not s.startswith(prefix):
273
raise AssertionError('string %r does not start with %r' % (s, prefix))
275
def assertEndsWith(self, s, suffix):
276
if not s.endswith(prefix):
277
raise AssertionError('string %r does not end with %r' % (s, suffix))
261
279
def assertContainsRe(self, haystack, needle_re):
262
280
"""Assert that a contains something matching a regular expression."""
274
292
raise AssertionError("value(s) %r not present in container %r" %
275
293
(missing, superlist))
295
def assertTransportMode(self, transport, path, mode):
296
"""Fail if a path does not have mode mode.
298
If modes are not supported on this platform, the test is skipped.
300
if sys.platform == 'win32':
302
path_stat = transport.stat(path)
303
actual_mode = stat.S_IMODE(path_stat.st_mode)
304
self.assertEqual(mode, actual_mode,
305
'mode of %r incorrect (%o != %o)' % (path, mode, actual_mode))
277
307
def _startLogFile(self):
278
308
"""Send bzr and test log messages to a temporary file.
526
558
# successfully created
527
TestCaseInTempDir.TEST_ROOT = os.path.abspath(root)
559
TestCaseInTempDir.TEST_ROOT = osutils.abspath(root)
529
561
# make a fake bzr directory there to prevent any tests propagating
530
562
# up onto the source directory's real branch
531
os.mkdir(os.path.join(TestCaseInTempDir.TEST_ROOT, '.bzr'))
563
os.mkdir(osutils.pathjoin(TestCaseInTempDir.TEST_ROOT, '.bzr'))
534
566
super(TestCaseInTempDir, self).setUp()
536
568
_currentdir = os.getcwdu()
537
569
short_id = self.id().replace('bzrlib.tests.', '') \
538
570
.replace('__main__.', '')
539
self.test_dir = os.path.join(self.TEST_ROOT, short_id)
571
self.test_dir = osutils.pathjoin(self.TEST_ROOT, short_id)
540
572
os.mkdir(self.test_dir)
541
573
os.chdir(self.test_dir)
542
574
os.environ['HOME'] = self.test_dir
575
os.environ['APPDATA'] = self.test_dir
543
576
def _leaveDirectory():
544
577
os.chdir(_currentdir)
545
578
self.addCleanup(_leaveDirectory)
547
def build_tree(self, shape, line_endings='native'):
580
def build_tree(self, shape, line_endings='native', transport=None):
548
581
"""Build a test tree according to a pattern.
550
583
shape is a sequence of file specifications. If the final
555
588
in binary mode, exact contents are written
556
589
in native mode, the line endings match the
557
590
default platform endings.
592
:param transport: A transport to write to, for building trees on
593
VFS's. If the transport is readonly or None,
594
"." is opened automatically.
559
596
# XXX: It's OK to just create them using forward slashes on windows?
597
if transport is None or transport.is_readonly():
598
transport = bzrlib.transport.get_transport(".")
560
599
for name in shape:
561
600
self.assert_(isinstance(name, basestring))
562
601
if name[-1] == '/':
602
transport.mkdir(urlescape(name[:-1]))
565
604
if line_endings == 'binary':
567
606
elif line_endings == 'native':
570
609
raise BzrError('Invalid line ending request %r' % (line_endings,))
571
print >>f, "contents of", name
610
content = "contents of %s%s" % (name, end)
611
transport.put(urlescape(name), StringIO(content))
574
613
def build_tree_contents(self, shape):
575
614
build_tree_contents(shape)
577
616
def failUnlessExists(self, path):
578
617
"""Fail unless path, which may be abs or relative, exists."""
579
self.failUnless(bzrlib.osutils.lexists(path))
618
self.failUnless(osutils.lexists(path))
620
def failIfExists(self, path):
621
"""Fail if path, which may be abs or relative, exists."""
622
self.failIf(osutils.lexists(path))
581
624
def assertFileEqual(self, content, path):
582
625
"""Fail if path does not contain 'content'."""
583
self.failUnless(bzrlib.osutils.lexists(path))
626
self.failUnless(osutils.lexists(path))
584
627
self.assertEqualDiff(content, open(path, 'r').read())
587
630
def filter_suite_by_re(suite, pattern):
588
631
result = TestSuite()
636
679
'bzrlib.tests.test_annotate',
637
680
'bzrlib.tests.test_api',
638
681
'bzrlib.tests.test_bad_files',
682
'bzrlib.tests.test_basis_inventory',
639
683
'bzrlib.tests.test_branch',
640
684
'bzrlib.tests.test_command',
641
685
'bzrlib.tests.test_commit',
645
689
'bzrlib.tests.test_diff',
646
690
'bzrlib.tests.test_doc_generate',
647
691
'bzrlib.tests.test_fetch',
692
'bzrlib.tests.test_fileid_involved',
648
693
'bzrlib.tests.test_gpg',
649
694
'bzrlib.tests.test_graph',
650
695
'bzrlib.tests.test_hashcache',
659
704
'bzrlib.tests.test_msgeditor',
660
705
'bzrlib.tests.test_nonascii',
661
706
'bzrlib.tests.test_options',
707
'bzrlib.tests.test_osutils',
662
708
'bzrlib.tests.test_parent',
709
'bzrlib.tests.test_permissions',
663
710
'bzrlib.tests.test_plugins',
664
711
'bzrlib.tests.test_remove',
665
712
'bzrlib.tests.test_revision',
666
'bzrlib.tests.test_revision_info',
667
713
'bzrlib.tests.test_revisionnamespaces',
668
714
'bzrlib.tests.test_revprops',
669
715
'bzrlib.tests.test_reweave',
671
717
'bzrlib.tests.test_sampler',
672
718
'bzrlib.tests.test_selftest',
673
719
'bzrlib.tests.test_setup',
674
'bzrlib.tests.test_sftp',
720
'bzrlib.tests.test_sftp_transport',
675
721
'bzrlib.tests.test_smart_add',
676
722
'bzrlib.tests.test_source',
677
723
'bzrlib.tests.test_status',
678
724
'bzrlib.tests.test_store',
725
'bzrlib.tests.test_symbol_versioning',
679
726
'bzrlib.tests.test_testament',
680
727
'bzrlib.tests.test_trace',
681
728
'bzrlib.tests.test_transactions',
689
736
'bzrlib.tests.test_workingtree',
690
737
'bzrlib.tests.test_xml',
739
test_transport_implementations = [
740
'bzrlib.tests.test_transport_implementations']
693
print '%10s: %s' % ('bzr', os.path.realpath(sys.argv[0]))
742
TestCase.BZRPATH = osutils.pathjoin(
743
osutils.realpath(osutils.dirname(bzrlib.__path__[0])), 'bzr')
744
print '%10s: %s' % ('bzr', osutils.realpath(sys.argv[0]))
694
745
print '%10s: %s' % ('bzrlib', bzrlib.__path__[0])
696
747
suite = TestSuite()
699
750
# actually wrong, just "no such module". We should probably override that
700
751
# class, but for the moment just load them ourselves. (mbp 20051202)
701
752
loader = TestLoader()
753
from bzrlib.transport import TransportTestProviderAdapter
754
adapter = TransportTestProviderAdapter()
755
for mod_name in test_transport_implementations:
756
mod = _load_module_by_name(mod_name)
757
for test in iter_suite_tests(loader.loadTestsFromModule(mod)):
758
suite.addTests(adapter.adapt(test))
702
759
for mod_name in testmod_names:
703
760
mod = _load_module_by_name(mod_name)
704
761
suite.addTest(loader.loadTestsFromModule(mod))