~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/__init__.py

  • Committer: Robert Collins
  • Date: 2005-10-14 02:17:36 UTC
  • mfrom: (1185.16.34)
  • Revision ID: robertc@lifelesslap.robertcollins.net-20051014021736-7230e59066856096
MergeĀ fromĀ Martin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
 
18
18
from cStringIO import StringIO
 
19
import difflib
 
20
import errno
19
21
import logging
20
 
import unittest
21
 
import tempfile
22
22
import os
23
 
import errno
24
23
import re
25
24
import shutil
26
 
import subprocess
27
25
import sys
 
26
import tempfile
 
27
import unittest
28
28
import time
29
29
 
30
30
import bzrlib.commands
162
162
    routine, and to build and check bzr trees."""
163
163
 
164
164
    BZRPATH = 'bzr'
 
165
    _log_file_name = None
165
166
 
166
167
    def setUp(self):
167
168
        unittest.TestCase.setUp(self)
168
169
        bzrlib.trace.disable_default_logging()
169
170
        self._enable_file_logging()
170
171
 
 
172
    def _ndiff_strings(self, a, b):
 
173
        """Return ndiff between two strings containing lines."""
 
174
        difflines = difflib.ndiff(a.splitlines(True),
 
175
                                  b.splitlines(True),
 
176
                                  linejunk=lambda x: False,
 
177
                                  charjunk=lambda x: False)
 
178
        return ''.join(difflines)
171
179
 
 
180
    def assertEqualDiff(self, a, b):
 
181
        """Assert two texts are equal, if not raise an exception.
 
182
        
 
183
        This is intended for use with multi-line strings where it can 
 
184
        be hard to find the differences by eye.
 
185
        """
 
186
        # TODO: perhaps override assertEquals to call this for strings?
 
187
        if a == b:
 
188
            return
 
189
        raise AssertionError("texts not equal:\n" + 
 
190
                             self._ndiff_strings(a, b))      
 
191
        
172
192
    def _enable_file_logging(self):
173
193
        fileno, name = tempfile.mkstemp(suffix='.log', prefix='testbzr')
174
194
 
196
216
 
197
217
    def _get_log(self):
198
218
        """Return as a string the log for this test"""
199
 
        return open(self._log_file_name).read()
200
 
 
 
219
        if self._log_file_name:
 
220
            return open(self._log_file_name).read()
 
221
        else:
 
222
            return ''
201
223
 
202
224
    def capture(self, cmd):
203
225
        """Shortcut that splits cmd into words, runs, and returns stdout"""
489
511
                   'bzrlib.selftest.testworkingtree',
490
512
                   'bzrlib.selftest.test_upgrade',
491
513
                   'bzrlib.selftest.test_conflicts',
 
514
                   'bzrlib.selftest.testtestament',
 
515
                   'bzrlib.selftest.testannotate',
492
516
                   ]
493
517
 
494
518
    for m in (bzrlib.store, bzrlib.inventory, bzrlib.branch,