~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Aaron Bentley
  • Date: 2006-08-16 19:13:00 UTC
  • mfrom: (1934 +trunk)
  • mto: (1910.2.43 format-bumps)
  • mto: This revision was merged to the branch mainline in revision 1935.
  • Revision ID: abentley@panoramicfeedback.com-20060816191300-045772b26b975d1c
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
import bzrlib.plugin
64
64
import bzrlib.progress as progress
65
65
from bzrlib.revision import common_ancestor
 
66
from bzrlib.revisionspec import RevisionSpec
66
67
import bzrlib.store
67
68
import bzrlib.trace
68
69
from bzrlib.transport import get_transport
136
137
    """
137
138
    stop_early = False
138
139
    
139
 
    def __init__(self, stream, descriptions, verbosity, pb=None):
 
140
    def __init__(self, stream, descriptions, verbosity, pb=None,
 
141
                 bench_history=None):
 
142
        """Construct new TestResult.
 
143
 
 
144
        :param bench_history: Optionally, a writable file object to accumulate
 
145
            benchmark results.
 
146
        """
140
147
        unittest._TextTestResult.__init__(self, stream, descriptions, verbosity)
141
148
        self.pb = pb
 
149
        if bench_history is not None:
 
150
            from bzrlib.version import _get_bzr_source_tree
 
151
            src_tree = _get_bzr_source_tree()
 
152
            if src_tree:
 
153
                revision_id = src_tree.last_revision()
 
154
            else:
 
155
                # XXX: If there's no branch, what should we do?
 
156
                revision_id = ''
 
157
            bench_history.write("--date %s %s\n" % (time.time(), revision_id))
 
158
        self._bench_history = bench_history
142
159
    
143
160
    def extractBenchmarkTime(self, testCase):
144
161
        """Add a benchmark time for the current test case."""
248
265
 
249
266
    def addSuccess(self, test):
250
267
        self.extractBenchmarkTime(test)
 
268
        if self._bench_history is not None:
 
269
            if self._benchmarkTime is not None:
 
270
                self._bench_history.write("%s %s\n" % (
 
271
                    self._formatTime(self._benchmarkTime),
 
272
                    test.id()))
251
273
        if self.showAll:
252
274
            self.stream.writeln('   OK %s' % self._testTimeString())
253
275
            for bench_called, stats in getattr(test, '_benchcalls', []):
304
326
                 descriptions=0,
305
327
                 verbosity=1,
306
328
                 keep_output=False,
307
 
                 pb=None):
 
329
                 pb=None,
 
330
                 bench_history=None):
308
331
        self.stream = unittest._WritelnDecorator(stream)
309
332
        self.descriptions = descriptions
310
333
        self.verbosity = verbosity
311
334
        self.keep_output = keep_output
312
335
        self.pb = pb
 
336
        self._bench_history = bench_history
313
337
 
314
338
    def _makeResult(self):
315
339
        result = _MyResult(self.stream,
316
340
                           self.descriptions,
317
341
                           self.verbosity,
318
 
                           pb=self.pb)
 
342
                           pb=self.pb,
 
343
                           bench_history=self._bench_history)
319
344
        result.stop_early = self.stop_on_failure
320
345
        return result
321
346
 
395
420
 
396
421
class TestSkipped(Exception):
397
422
    """Indicates that a test was intentionally skipped, rather than failing."""
398
 
    # XXX: Not used yet
399
423
 
400
424
 
401
425
class CommandFailed(Exception):
594
618
            'HOME': os.getcwd(),
595
619
            'APPDATA': os.getcwd(),
596
620
            'BZR_EMAIL': None,
 
621
            'BZREMAIL': None, # may still be present in the environment
597
622
            'EMAIL': None,
598
623
        }
599
624
        self.__old_env = {}
964
989
        shape is a sequence of file specifications.  If the final
965
990
        character is '/', a directory is created.
966
991
 
 
992
        This assumes that all the elements in the tree being built are new.
 
993
 
967
994
        This doesn't add anything to a branch.
968
995
        :param line_endings: Either 'binary' or 'native'
969
996
                             in binary mode, exact contents are written
974
1001
                          VFS's. If the transport is readonly or None,
975
1002
                          "." is opened automatically.
976
1003
        """
977
 
        # XXX: It's OK to just create them using forward slashes on windows?
 
1004
        # It's OK to just create them using forward slashes on windows.
978
1005
        if transport is None or transport.is_readonly():
979
1006
            transport = get_transport(".")
980
1007
        for name in shape:
989
1016
                else:
990
1017
                    raise errors.BzrError('Invalid line ending request %r' % (line_endings,))
991
1018
                content = "contents of %s%s" % (name.encode('utf-8'), end)
992
 
                transport.put(urlutils.escape(name), StringIO(content))
 
1019
                # Technically 'put()' is the right command. However, put
 
1020
                # uses an AtomicFile, which requires an extra rename into place
 
1021
                # As long as the files didn't exist in the past, append() will
 
1022
                # do the same thing as put()
 
1023
                # On jam's machine, make_kernel_like_tree is:
 
1024
                #   put:    4.5-7.5s (averaging 6s)
 
1025
                #   append: 2.9-4.5s
 
1026
                transport.append(urlutils.escape(name), StringIO(content))
993
1027
 
994
1028
    def build_tree_contents(self, shape):
995
1029
        build_tree_contents(shape)
1199
1233
 
1200
1234
def run_suite(suite, name='test', verbose=False, pattern=".*",
1201
1235
              stop_on_failure=False, keep_output=False,
1202
 
              transport=None, lsprof_timed=None):
 
1236
              transport=None, lsprof_timed=None, bench_history=None):
1203
1237
    TestCaseInTempDir._TEST_NAME = name
1204
1238
    TestCase._gather_lsprof_in_benchmarks = lsprof_timed
1205
1239
    if verbose:
1212
1246
                            descriptions=0,
1213
1247
                            verbosity=verbosity,
1214
1248
                            keep_output=keep_output,
1215
 
                            pb=pb)
 
1249
                            pb=pb,
 
1250
                            bench_history=bench_history)
1216
1251
    runner.stop_on_failure=stop_on_failure
1217
1252
    if pattern != '.*':
1218
1253
        suite = filter_suite_by_re(suite, pattern)
1224
1259
             keep_output=False,
1225
1260
             transport=None,
1226
1261
             test_suite_factory=None,
1227
 
             lsprof_timed=None):
 
1262
             lsprof_timed=None,
 
1263
             bench_history=None):
1228
1264
    """Run the whole test suite under the enhanced runner"""
 
1265
    # XXX: Very ugly way to do this...
 
1266
    # Disable warning about old formats because we don't want it to disturb
 
1267
    # any blackbox tests.
 
1268
    from bzrlib import repository
 
1269
    repository._deprecation_warning_done = True
 
1270
 
1229
1271
    global default_transport
1230
1272
    if transport is None:
1231
1273
        transport = default_transport
1239
1281
        return run_suite(suite, 'testbzr', verbose=verbose, pattern=pattern,
1240
1282
                     stop_on_failure=stop_on_failure, keep_output=keep_output,
1241
1283
                     transport=transport,
1242
 
                     lsprof_timed=lsprof_timed)
 
1284
                     lsprof_timed=lsprof_timed,
 
1285
                     bench_history=bench_history)
1243
1286
    finally:
1244
1287
        default_transport = old_transport
1245
1288
 
1253
1296
    testmod_names = [
1254
1297
                   'bzrlib.tests.test_ancestry',
1255
1298
                   'bzrlib.tests.test_api',
 
1299
                   'bzrlib.tests.test_atomicfile',
1256
1300
                   'bzrlib.tests.test_bad_files',
1257
1301
                   'bzrlib.tests.test_branch',
1258
1302
                   'bzrlib.tests.test_bundle',
1259
1303
                   'bzrlib.tests.test_bzrdir',
 
1304
                   'bzrlib.tests.test_cache_utf8',
1260
1305
                   'bzrlib.tests.test_command',
1261
1306
                   'bzrlib.tests.test_commit',
1262
1307
                   'bzrlib.tests.test_commit_merge',
1322
1367
                   'bzrlib.tests.test_upgrade',
1323
1368
                   'bzrlib.tests.test_urlutils',
1324
1369
                   'bzrlib.tests.test_versionedfile',
 
1370
                   'bzrlib.tests.test_version',
1325
1371
                   'bzrlib.tests.test_weave',
1326
1372
                   'bzrlib.tests.test_whitebox',
1327
1373
                   'bzrlib.tests.test_workingtree',