~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_log.py

  • Committer: Alexander Belchenko
  • Date: 2007-11-19 22:54:30 UTC
  • mfrom: (3006 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3008.
  • Revision ID: bialix@ukr.net-20071119225430-x0ewosrsagis0yno
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
219
219
    return b
220
220
 
221
221
 
 
222
def normalize_log(log):
 
223
    """Replaces the variable lines of logs with fixed lines"""
 
224
    author = 'author: Dolor Sit <test@example.com>'
 
225
    committer = 'committer: Lorem Ipsum <test@example.com>'
 
226
    lines = log.splitlines(True)
 
227
    for idx,line in enumerate(lines):
 
228
        stripped_line = line.lstrip()
 
229
        indent = ' ' * (len(line) - len(stripped_line))
 
230
        if stripped_line.startswith('author:'):
 
231
            lines[idx] = indent + author + '\n'
 
232
        elif stripped_line.startswith('committer:'):
 
233
            lines[idx] = indent + committer + '\n'
 
234
        elif stripped_line.startswith('timestamp:'):
 
235
            lines[idx] = indent + 'timestamp: Just now\n'
 
236
    return ''.join(lines)
 
237
 
 
238
 
222
239
class TestShortLogFormatter(TestCaseWithTransport):
223
240
 
224
241
    def test_trailing_newlines(self):
227
244
        sio = self.make_utf8_encoded_stringio()
228
245
        lf = ShortLogFormatter(to_file=sio)
229
246
        show_log(b, lf)
230
 
        self.assertEquals(sio.getvalue(), """\
 
247
        self.assertEqualDiff(sio.getvalue(), """\
231
248
    3 Joe Foo\t2005-11-21
232
249
      single line with trailing newline
233
250
 
244
261
 
245
262
class TestLongLogFormatter(TestCaseWithTransport):
246
263
 
247
 
    def normalize_log(self,log):
248
 
        """Replaces the variable lines of logs with fixed lines"""
249
 
        author = 'author: Dolor Sit <test@example.com>'
250
 
        committer = 'committer: Lorem Ipsum <test@example.com>'
251
 
        lines = log.splitlines(True)
252
 
        for idx,line in enumerate(lines):
253
 
            stripped_line = line.lstrip()
254
 
            indent = ' ' * (len(line) - len(stripped_line))
255
 
            if stripped_line.startswith('author:'):
256
 
                lines[idx] = indent + author + '\n'
257
 
            elif stripped_line.startswith('committer:'):
258
 
                lines[idx] = indent + committer + '\n'
259
 
            elif stripped_line.startswith('timestamp:'):
260
 
                lines[idx] = indent + 'timestamp: Just now\n'
261
 
        return ''.join(lines)
262
 
 
263
264
    def test_verbose_log(self):
264
265
        """Verbose log includes changed files
265
266
        
311
312
        sio = self.make_utf8_encoded_stringio()
312
313
        lf = LongLogFormatter(to_file=sio)
313
314
        show_log(b, lf, verbose=True)
314
 
        log = self.normalize_log(sio.getvalue())
315
 
        self.assertEqualDiff("""\
 
315
        log = normalize_log(sio.getvalue())
 
316
        self.assertEqualDiff(log, """\
316
317
------------------------------------------------------------
317
318
revno: 2
318
319
committer: Lorem Ipsum <test@example.com>
348
349
timestamp: Just now
349
350
message:
350
351
  first post
351
 
""", log)
 
352
""")
352
353
 
353
354
    def test_verbose_merge_revisions_contain_deltas(self):
354
355
        wt = self.make_branch_and_tree('parent')
367
368
        sio = self.make_utf8_encoded_stringio()
368
369
        lf = LongLogFormatter(to_file=sio)
369
370
        show_log(b, lf, verbose=True)
370
 
        log = self.normalize_log(sio.getvalue())
371
 
        self.assertEqualDiff("""\
 
371
        log = normalize_log(sio.getvalue())
 
372
        self.assertEqualDiff(log, """\
372
373
------------------------------------------------------------
373
374
revno: 2
374
375
committer: Lorem Ipsum <test@example.com>
401
402
added:
402
403
  f1
403
404
  f2
404
 
""", log)
 
405
""")
405
406
 
406
407
    def test_trailing_newlines(self):
407
408
        wt = self.make_branch_and_tree('.')
488
489
        logfile.flush()
489
490
        logfile.seek(0)
490
491
        log_contents = logfile.read()
491
 
        self.assertEqualDiff(log_contents, '1: Line-Log-Formatte... 2005-11-23 add a\n')
 
492
        self.assertEqualDiff(log_contents,
 
493
            '1: Line-Log-Formatte... 2005-11-23 add a\n')
492
494
 
493
495
    def test_short_log_with_merges(self):
494
496
        wt = self.make_branch_and_memory_tree('.')
510
512
            formatter = ShortLogFormatter(to_file=logfile)
511
513
            show_log(wt.branch, formatter)
512
514
            logfile.flush()
513
 
            self.assertEqualDiff("""\
 
515
            self.assertEqualDiff(logfile.getvalue(), """\
514
516
    2 Joe Foo\t2005-11-22 [merge]
515
517
      rev-2
516
518
 
517
519
    1 Joe Foo\t2005-11-22
518
520
      rev-1
519
521
 
520
 
""", logfile.getvalue())
 
522
""")
521
523
        finally:
522
524
            wt.unlock()
523
525