~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_diff.py

(jameinel) Fix bug #397739,
 resolve 'lp:foo' locally as long as we have a launchpad-login to use
 bzr+ssh. (John A Meinel)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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
33
33
    transform,
34
34
    )
35
35
from bzrlib.symbol_versioning import deprecated_in
36
 
from bzrlib.tests import test_win32utils
 
36
from bzrlib.tests import features
 
37
from bzrlib.tests.blackbox.test_diff import subst_dates
37
38
 
38
39
 
39
40
class _AttribFeature(tests.Feature):
143
144
        self.check_patch(lines)
144
145
 
145
146
    def test_external_diff_binary_lang_c(self):
146
 
        old_env = {}
147
147
        for lang in ('LANG', 'LC_ALL', 'LANGUAGE'):
148
 
            old_env[lang] = osutils.set_or_unset_env(lang, 'C')
149
 
        try:
150
 
            lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
151
 
            # Older versions of diffutils say "Binary files", newer
152
 
            # versions just say "Files".
153
 
            self.assertContainsRe(lines[0],
154
 
                                  '(Binary f|F)iles old and new differ\n')
155
 
            self.assertEquals(lines[1:], ['\n'])
156
 
        finally:
157
 
            for lang, old_val in old_env.iteritems():
158
 
                osutils.set_or_unset_env(lang, old_val)
 
148
            self.overrideEnv(lang, 'C')
 
149
        lines = external_udiff_lines(['\x00foobar\n'], ['foo\x00bar\n'])
 
150
        # Older versions of diffutils say "Binary files", newer
 
151
        # versions just say "Files".
 
152
        self.assertContainsRe(lines[0], '(Binary f|F)iles old and new differ\n')
 
153
        self.assertEquals(lines[1:], ['\n'])
159
154
 
160
155
    def test_no_external_diff(self):
161
156
        """Check that NoDiff is raised when diff is not available"""
162
 
        # Use os.environ['PATH'] to make sure no 'diff' command is available
163
 
        orig_path = os.environ['PATH']
164
 
        try:
165
 
            os.environ['PATH'] = ''
166
 
            self.assertRaises(errors.NoDiff, diff.external_diff,
167
 
                              'old', ['boo\n'], 'new', ['goo\n'],
168
 
                              StringIO(), diff_opts=['-u'])
169
 
        finally:
170
 
            os.environ['PATH'] = orig_path
 
157
        # Make sure no 'diff' command is available
 
158
        # XXX: Weird, using None instead of '' breaks the test -- vila 20101216
 
159
        self.overrideEnv('PATH', '')
 
160
        self.assertRaises(errors.NoDiff, diff.external_diff,
 
161
                          'old', ['boo\n'], 'new', ['goo\n'],
 
162
                          StringIO(), diff_opts=['-u'])
171
163
 
172
164
    def test_internal_diff_default(self):
173
165
        # Default internal diff encoding is utf8
521
513
        self.assertNotContainsRe(d, r"file 'e'")
522
514
        self.assertNotContainsRe(d, r"file 'f'")
523
515
 
524
 
 
525
516
    def test_binary_unicode_filenames(self):
526
517
        """Test that contents of files are *not* encoded in UTF-8 when there
527
518
        is a binary file in the diff.
580
571
        self.assertContainsRe(d, "=== modified file 'mod_%s'"%autf8)
581
572
        self.assertContainsRe(d, "=== removed file 'del_%s'"%autf8)
582
573
 
 
574
    def test_unicode_filename_path_encoding(self):
 
575
        """Test for bug #382699: unicode filenames on Windows should be shown
 
576
        in user encoding.
 
577
        """
 
578
        self.requireFeature(tests.UnicodeFilenameFeature)
 
579
        # The word 'test' in Russian
 
580
        _russian_test = u'\u0422\u0435\u0441\u0442'
 
581
        directory = _russian_test + u'/'
 
582
        test_txt = _russian_test + u'.txt'
 
583
        u1234 = u'\u1234.txt'
 
584
 
 
585
        tree = self.make_branch_and_tree('.')
 
586
        self.build_tree_contents([
 
587
            (test_txt, 'foo\n'),
 
588
            (u1234, 'foo\n'),
 
589
            (directory, None),
 
590
            ])
 
591
        tree.add([test_txt, u1234, directory])
 
592
 
 
593
        sio = StringIO()
 
594
        diff.show_diff_trees(tree.basis_tree(), tree, sio,
 
595
            path_encoding='cp1251')
 
596
 
 
597
        output = subst_dates(sio.getvalue())
 
598
        shouldbe = ('''\
 
599
=== added directory '%(directory)s'
 
600
=== added file '%(test_txt)s'
 
601
--- a/%(test_txt)s\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
602
+++ b/%(test_txt)s\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
603
@@ -0,0 +1,1 @@
 
604
+foo
 
605
 
 
606
=== added file '?.txt'
 
607
--- a/?.txt\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
608
+++ b/?.txt\tYYYY-MM-DD HH:MM:SS +ZZZZ
 
609
@@ -0,0 +1,1 @@
 
610
+foo
 
611
 
 
612
''' % {'directory': _russian_test.encode('cp1251'),
 
613
       'test_txt': test_txt.encode('cp1251'),
 
614
      })
 
615
        self.assertEqualDiff(output, shouldbe)
 
616
 
583
617
 
584
618
class DiffWasIs(diff.DiffPath):
585
619
 
1298
1332
                         diff_obj._get_command('old-path', 'new-path'))
1299
1333
 
1300
1334
    def test_from_string_path_with_backslashes(self):
1301
 
        self.requireFeature(test_win32utils.BackslashDirSeparatorFeature)
 
1335
        self.requireFeature(features.backslashdir_feature)
1302
1336
        tool = 'C:\\Tools\\Diff.exe'
1303
1337
        diff_obj = diff.DiffFromTool.from_string(tool, None, None, None)
1304
1338
        self.addCleanup(diff_obj.finish)