~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_diff.py

  • Committer: John Arbash Meinel
  • Date: 2006-07-30 13:54:37 UTC
  • mto: (1946.2.6 reduce-knit-churn)
  • mto: This revision was merged to the branch mainline in revision 1898.
  • Revision ID: john@arbash-meinel.com-20060730135437-1d722abdb14bff76
(jelmer) Install new intertree tests

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 by 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
22
22
import re
23
23
 
24
24
import bzrlib
 
25
from bzrlib.branch import Branch
25
26
from bzrlib import workingtree
26
 
from bzrlib.branch import Branch
27
 
from bzrlib.tests import TestSkipped
28
27
from bzrlib.tests.blackbox import ExternalBase
29
28
 
30
29
 
36
35
 
37
36
class TestDiff(ExternalBase):
38
37
 
39
 
    def make_example_branch(self):
 
38
    def make_example_branch(test):
40
39
        # FIXME: copied from test_too_much -- share elsewhere?
41
 
        tree = self.make_branch_and_tree('.')
42
 
        open('hello', 'wb').write('foo\n')
43
 
        tree.add(['hello'])
44
 
        tree.commit('setup')
45
 
        open('goodbye', 'wb').write('baz\n')
46
 
        tree.add(['goodbye'])
47
 
        tree.commit('setup')
 
40
        test.runbzr('init')
 
41
        file('hello', 'wb').write('foo\n')
 
42
        test.runbzr('add hello')
 
43
        test.runbzr('commit -m setup hello')
 
44
        file('goodbye', 'wb').write('baz\n')
 
45
        test.runbzr('add goodbye')
 
46
        test.runbzr('commit -m setup goodbye')
48
47
 
49
48
    def test_diff(self):
50
49
        self.make_example_branch()
256
255
        self.runbzr('rename hello gruezi')
257
256
        diff = self.run_bzr_captured(['diff'], retcode=1)
258
257
        self.assertTrue("=== renamed file 'hello' => 'gruezi'" in diff[0])
259
 
 
260
 
 
261
 
class TestExternalDiff(TestDiff):
262
 
 
263
 
    def test_external_diff(self):
264
 
        """Test that we can spawn an external diff process"""
265
 
        # We have to use run_bzr_subprocess, because we need to
266
 
        # test writing directly to stdout, (there was a bug in
267
 
        # subprocess.py that we had to workaround).
268
 
        # However, if 'diff' may not be available
269
 
        self.make_example_branch()
270
 
        orig_progress = os.environ.get('BZR_PROGRESS_BAR')
271
 
        try:
272
 
            os.environ['BZR_PROGRESS_BAR'] = 'none'
273
 
            out, err = self.run_bzr_subprocess('diff', '-r', '1',
274
 
                                               '--diff-options', '-ub',
275
 
                                               retcode=None)
276
 
        finally:
277
 
            if orig_progress is None:
278
 
                del os.environ['BZR_PROGRESS_BAR']
279
 
            else:
280
 
                os.environ['BZR_PROGRESS_BAR'] = orig_progress
281
 
            
282
 
        if 'Diff is not installed on this machine' in err:
283
 
            raise TestSkipped("No external 'diff' is available")
284
 
        self.assertEqual('', err)
285
 
        # We have to skip the stuff in the middle, because it depends
286
 
        # on time.time()
287
 
        self.assertStartsWith(out, "=== added file 'goodbye'\n"
288
 
                                   "--- goodbye\t1970-01-01 00:00:00 +0000\n"
289
 
                                   "+++ goodbye\t")
290
 
        self.assertEndsWith(out, "\n@@ -0,0 +1 @@\n"
291
 
                                 "+baz\n\n")