~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

  • Committer: Vincent Ladeuil
  • Date: 2016-01-21 10:50:35 UTC
  • mfrom: (6609 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6610.
  • Revision ID: v.ladeuil+lp@free.fr-20160121105035-r67vcb49o142g2li
Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011 Canonical Ltd
 
1
# Copyright (C) 2005-2014 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
17
17
import os
18
18
from cStringIO import StringIO
19
19
import subprocess
20
 
import sys
21
20
import tempfile
22
21
 
23
22
from bzrlib import (
32
31
    tests,
33
32
    transform,
34
33
    )
35
 
from bzrlib.symbol_versioning import deprecated_in
36
 
from bzrlib.tests import features, EncodingAdapter
37
 
from bzrlib.tests.blackbox.test_diff import subst_dates
38
34
from bzrlib.tests import (
39
35
    features,
40
 
    )
 
36
    EncodingAdapter,
 
37
)
 
38
from bzrlib.tests.blackbox.test_diff import subst_dates
 
39
from bzrlib.tests.scenarios import load_tests_apply_scenarios
 
40
 
 
41
 
 
42
load_tests = load_tests_apply_scenarios
41
43
 
42
44
 
43
45
def udiff_lines(old, new, allow_binary=False):
63
65
    return lines
64
66
 
65
67
 
 
68
class TestDiffOptions(tests.TestCase):
 
69
 
 
70
    def test_unified_added(self):
 
71
        """Check for default style '-u' only if no other style specified
 
72
        in 'diff-options'.
 
73
        """
 
74
        # Verify that style defaults to unified, id est '-u' appended
 
75
        # to option list, in the absence of an alternative style.
 
76
        self.assertEqual(['-a', '-u'], diff.default_style_unified(['-a']))
 
77
 
 
78
 
 
79
class TestDiffOptionsScenarios(tests.TestCase):
 
80
 
 
81
    scenarios = [(s, dict(style=s)) for s in diff.style_option_list]
 
82
    style = None # Set by load_tests_apply_scenarios from scenarios
 
83
 
 
84
    def test_unified_not_added(self):
 
85
        # Verify that for all valid style options, '-u' is not
 
86
        # appended to option list.
 
87
        ret_opts = diff.default_style_unified(diff_opts=["%s" % (self.style,)])
 
88
        self.assertEqual(["%s" % (self.style,)], ret_opts)
 
89
 
 
90
 
66
91
class TestDiff(tests.TestCase):
67
92
 
68
93
    def test_add_nl(self):
1391
1416
        diff_obj._execute('old', 'new')
1392
1417
        self.assertEqual(output.getvalue().rstrip(), 'old new')
1393
1418
 
1394
 
    def test_excute_missing(self):
 
1419
    def test_execute_missing(self):
1395
1420
        diff_obj = diff.DiffFromTool(['a-tool-which-is-unlikely-to-exist'],
1396
1421
                                     None, None, None)
1397
1422
        self.addCleanup(diff_obj.finish)
1471
1496
    def test_encodable_filename(self):
1472
1497
        # Just checks file path for external diff tool.
1473
1498
        # We cannot change CPython's internal encoding used by os.exec*.
1474
 
        import sys
1475
1499
        diffobj = diff.DiffFromTool(['dummy', '@old_path', '@new_path'],
1476
1500
                                    None, None, None)
1477
1501
        for _, scenario in EncodingAdapter.encoding_scenarios:
1489
1513
            self.assert_(fullpath.startswith(diffobj._root + '/safe'))
1490
1514
 
1491
1515
    def test_unencodable_filename(self):
1492
 
        import sys
1493
1516
        diffobj = diff.DiffFromTool(['dummy', '@old_path', '@new_path'],
1494
1517
                                    None, None, None)
1495
1518
        for _, scenario in EncodingAdapter.encoding_scenarios: