~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-04-18 23:19:16 UTC
  • mfrom: (5784.3.1 cleanup)
  • Revision ID: pqm@pqm.ubuntu.com-20110418231916-8x8pvhwr2q8l6gq1
(mbp) remove unnecessary TestShowDiffTreesHelper from tests (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
249
249
        self.assertEqual(out.splitlines(True) + ['\n'], lines)
250
250
 
251
251
 
252
 
class TestShowDiffTreesHelper(tests.TestCaseWithTransport):
253
 
    """Has a helper for running show_diff_trees"""
254
 
 
255
 
    def get_diff(self, tree1, tree2, specific_files=None, working_tree=None):
256
 
        output = StringIO()
257
 
        if working_tree is not None:
258
 
            extra_trees = (working_tree,)
259
 
        else:
260
 
            extra_trees = ()
261
 
        diff.show_diff_trees(tree1, tree2, output,
262
 
                             specific_files=specific_files,
263
 
                             extra_trees=extra_trees, old_label='old/',
264
 
                             new_label='new/')
265
 
        return output.getvalue()
266
 
 
267
 
 
268
 
class TestDiffDates(TestShowDiffTreesHelper):
 
252
def get_diff_as_string(tree1, tree2, specific_files=None, working_tree=None):
 
253
    output = StringIO()
 
254
    if working_tree is not None:
 
255
        extra_trees = (working_tree,)
 
256
    else:
 
257
        extra_trees = ()
 
258
    diff.show_diff_trees(tree1, tree2, output,
 
259
        specific_files=specific_files,
 
260
        extra_trees=extra_trees, old_label='old/',
 
261
        new_label='new/')
 
262
    return output.getvalue()
 
263
 
 
264
 
 
265
class TestDiffDates(tests.TestCaseWithTransport):
269
266
 
270
267
    def setUp(self):
271
268
        super(TestDiffDates, self).setUp()
306
303
        os.utime('file1', (1144195200, 1144195200)) # 2006-04-05 00:00:00 UTC
307
304
 
308
305
    def test_diff_rev_tree_working_tree(self):
309
 
        output = self.get_diff(self.wt.basis_tree(), self.wt)
 
306
        output = get_diff_as_string(self.wt.basis_tree(), self.wt)
310
307
        # note that the date for old/file1 is from rev 2 rather than from
311
308
        # the basis revision (rev 4)
312
309
        self.assertEqualDiff(output, '''\
322
319
    def test_diff_rev_tree_rev_tree(self):
323
320
        tree1 = self.b.repository.revision_tree('rev-2')
324
321
        tree2 = self.b.repository.revision_tree('rev-3')
325
 
        output = self.get_diff(tree1, tree2)
 
322
        output = get_diff_as_string(tree1, tree2)
326
323
        self.assertEqualDiff(output, '''\
327
324
=== modified file 'file2'
328
325
--- old/file2\t2006-04-01 00:00:00 +0000
336
333
    def test_diff_add_files(self):
337
334
        tree1 = self.b.repository.revision_tree(_mod_revision.NULL_REVISION)
338
335
        tree2 = self.b.repository.revision_tree('rev-1')
339
 
        output = self.get_diff(tree1, tree2)
 
336
        output = get_diff_as_string(tree1, tree2)
340
337
        # the files have the epoch time stamp for the tree in which
341
338
        # they don't exist.
342
339
        self.assertEqualDiff(output, '''\
357
354
    def test_diff_remove_files(self):
358
355
        tree1 = self.b.repository.revision_tree('rev-3')
359
356
        tree2 = self.b.repository.revision_tree('rev-4')
360
 
        output = self.get_diff(tree1, tree2)
 
357
        output = get_diff_as_string(tree1, tree2)
361
358
        # the file has the epoch time stamp for the tree in which
362
359
        # it doesn't exist.
363
360
        self.assertEqualDiff(output, '''\
374
371
        self.wt.rename_one('file1', 'file1b')
375
372
        old_tree = self.b.repository.revision_tree('rev-1')
376
373
        new_tree = self.b.repository.revision_tree('rev-4')
377
 
        out = self.get_diff(old_tree, new_tree, specific_files=['file1b'],
 
374
        out = get_diff_as_string(old_tree, new_tree, specific_files=['file1b'],
378
375
                            working_tree=self.wt)
379
376
        self.assertContainsRe(out, 'file1\t')
380
377
 
386
383
        self.wt.rename_one('file1', 'dir1/file1')
387
384
        old_tree = self.b.repository.revision_tree('rev-1')
388
385
        new_tree = self.b.repository.revision_tree('rev-4')
389
 
        out = self.get_diff(old_tree, new_tree, specific_files=['dir1'],
 
386
        out = get_diff_as_string(old_tree, new_tree, specific_files=['dir1'],
390
387
                            working_tree=self.wt)
391
388
        self.assertContainsRe(out, 'file1\t')
392
 
        out = self.get_diff(old_tree, new_tree, specific_files=['dir2'],
 
389
        out = get_diff_as_string(old_tree, new_tree, specific_files=['dir2'],
393
390
                            working_tree=self.wt)
394
391
        self.assertNotContainsRe(out, 'file1\t')
395
392
 
396
393
 
397
 
 
398
 
class TestShowDiffTrees(TestShowDiffTreesHelper):
 
394
class TestShowDiffTrees(tests.TestCaseWithTransport):
399
395
    """Direct tests for show_diff_trees"""
400
396
 
401
397
    def test_modified_file(self):
406
402
        tree.commit('one', rev_id='rev-1')
407
403
 
408
404
        self.build_tree_contents([('tree/file', 'new contents\n')])
409
 
        d = self.get_diff(tree.basis_tree(), tree)
 
405
        d = get_diff_as_string(tree.basis_tree(), tree)
410
406
        self.assertContainsRe(d, "=== modified file 'file'\n")
411
407
        self.assertContainsRe(d, '--- old/file\t')
412
408
        self.assertContainsRe(d, '\\+\\+\\+ new/file\t')
423
419
 
424
420
        tree.rename_one('dir', 'other')
425
421
        self.build_tree_contents([('tree/other/file', 'new contents\n')])
426
 
        d = self.get_diff(tree.basis_tree(), tree)
 
422
        d = get_diff_as_string(tree.basis_tree(), tree)
427
423
        self.assertContainsRe(d, "=== renamed directory 'dir' => 'other'\n")
428
424
        self.assertContainsRe(d, "=== modified file 'other/file'\n")
429
425
        # XXX: This is technically incorrect, because it used to be at another
442
438
        tree.commit('one', rev_id='rev-1')
443
439
 
444
440
        tree.rename_one('dir', 'newdir')
445
 
        d = self.get_diff(tree.basis_tree(), tree)
 
441
        d = get_diff_as_string(tree.basis_tree(), tree)
446
442
        # Renaming a directory should be a single "you renamed this dir" even
447
443
        # when there are files inside.
448
444
        self.assertEqual(d, "=== renamed directory 'dir' => 'newdir'\n")
455
451
        tree.commit('one', rev_id='rev-1')
456
452
 
457
453
        tree.rename_one('file', 'newname')
458
 
        d = self.get_diff(tree.basis_tree(), tree)
 
454
        d = get_diff_as_string(tree.basis_tree(), tree)
459
455
        self.assertContainsRe(d, "=== renamed file 'file' => 'newname'\n")
460
456
        # We shouldn't have a --- or +++ line, because there is no content
461
457
        # change
470
466
 
471
467
        tree.rename_one('file', 'newname')
472
468
        self.build_tree_contents([('tree/newname', 'new contents\n')])
473
 
        d = self.get_diff(tree.basis_tree(), tree)
 
469
        d = get_diff_as_string(tree.basis_tree(), tree)
474
470
        self.assertContainsRe(d, "=== renamed file 'file' => 'newname'\n")
475
471
        self.assertContainsRe(d, '--- old/file\t')
476
472
        self.assertContainsRe(d, '\\+\\+\\+ new/newname\t')
500
496
        tree.rename_one('c', 'new-c')
501
497
        tree.rename_one('d', 'new-d')
502
498
 
503
 
        d = self.get_diff(tree.basis_tree(), tree)
 
499
        d = get_diff_as_string(tree.basis_tree(), tree)
504
500
 
505
501
        self.assertContainsRe(d, r"file 'a'.*\(properties changed:"
506
502
                                  ".*\+x to -x.*\)")
564
560
        tree.add(['add_'+alpha], ['file-id'])
565
561
        self.build_tree_contents([('tree/mod_'+alpha, 'contents_mod\n')])
566
562
 
567
 
        d = self.get_diff(tree.basis_tree(), tree)
 
563
        d = get_diff_as_string(tree.basis_tree(), tree)
568
564
        self.assertContainsRe(d,
569
565
                "=== renamed file 'ren_%s' => 'ren_%s'\n"%(autf8, outf8))
570
566
        self.assertContainsRe(d, "=== added file 'add_%s'"%autf8)
1484
1480
        return self.applyDeprecated(
1485
1481
            deprecated_in((2, 2, 0)), diff.get_trees_and_branches_to_diff,
1486
1482
            path_list, revision_specs, old_url, new_url)
1487