~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_whitebox.py

  • Committer: Martin Pool
  • Date: 2006-03-24 19:11:33 UTC
  • mto: This revision was merged to the branch mainline in revision 1626.
  • Revision ID: mbp@sourcefrog.net-20060324191133-4f45292db5c5d487
(weave-merge) don't treat killed-both lines as points of agreement; 
makes sure that killed-[ab] lines next to change reasons aren't 
omitted from conflict descriptions.

Add more weave merge tests about line deletion.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2008-2012 Canonical Ltd
2
 
#
3
 
# This program is free software; you can redistribute it and/or modify
4
 
# it under the terms of the GNU General Public License as published by
5
 
# the Free Software Foundation; either version 2 of the License, or
6
 
# (at your option) any later version.
7
 
#
8
 
# This program is distributed in the hope that it will be useful,
9
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
# GNU General Public License for more details.
12
 
#
13
 
# You should have received a copy of the GNU General Public License
14
 
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
 
 
17
1
import os
 
2
import unittest
18
3
 
19
 
import bzrlib
20
 
from bzrlib import (
21
 
    errors,
22
 
    osutils,
23
 
    tests,
24
 
    )
 
4
from bzrlib.tests import TestCaseWithTransport, TestCase
 
5
from bzrlib.branch import ScratchBranch, Branch
 
6
from bzrlib.errors import PathNotChild
25
7
from bzrlib.osutils import relpath, pathjoin, abspath, realpath
26
8
 
27
9
 
28
 
class MoreTests(tests.TestCaseWithTransport):
 
10
class MoreTests(TestCaseWithTransport):
29
11
 
30
12
    def test_relpath(self):
31
13
        """test for branch path lookups
32
 
 
 
14
    
33
15
        bzrlib.osutils._relpath do a simple but subtle
34
16
        job: given a path (either relative to cwd or absolute), work out
35
17
        if it is inside a branch and return the path relative to the base.
36
18
        """
37
 
        dtmp = osutils.mkdtemp()
38
 
        self.addCleanup(osutils.rmtree, dtmp)
 
19
        import tempfile, shutil
 
20
        
 
21
        savedir = os.getcwdu()
 
22
        dtmp = tempfile.mkdtemp()
39
23
        # On Mac OSX, /tmp actually expands to /private/tmp
40
24
        dtmp = realpath(dtmp)
41
25
 
42
26
        def rp(p):
43
27
            return relpath(dtmp, p)
44
 
 
45
 
        # check paths inside dtmp while standing outside it
46
 
        self.assertEqual('foo', rp(pathjoin(dtmp, 'foo')))
47
 
 
48
 
        # root = nothing
49
 
        self.assertEqual('', rp(dtmp))
50
 
        self.assertRaises(errors.PathNotChild, rp, '/etc')
51
 
 
52
 
        # now some near-miss operations -- note that
53
 
        # os.path.commonprefix gets these wrong!
54
 
        self.assertRaises(errors.PathNotChild, rp, dtmp.rstrip('\\/') + '2')
55
 
        self.assertRaises(errors.PathNotChild, rp, dtmp.rstrip('\\/') + '2/foo')
56
 
 
57
 
        # now operations based on relpath of files in current
58
 
        # directory, or nearby
59
 
 
60
 
        os.chdir(dtmp)
61
 
        self.assertEqual('foo/bar/quux', rp('foo/bar/quux'))
62
 
        self.assertEqual('foo', rp('foo'))
63
 
        self.assertEqual('foo', rp('./foo'))
64
 
        self.assertEqual('foo', rp(abspath('foo')))
65
 
        self.assertRaises(errors.PathNotChild, rp, '../foo')
 
28
        
 
29
        try:
 
30
            # check paths inside dtmp while standing outside it
 
31
            self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
 
32
 
 
33
            # root = nothing
 
34
            self.assertEqual(rp(dtmp), '')
 
35
 
 
36
            self.assertRaises(PathNotChild,
 
37
                              rp,
 
38
                              '/etc')
 
39
 
 
40
            # now some near-miss operations -- note that
 
41
            # os.path.commonprefix gets these wrong!
 
42
            self.assertRaises(PathNotChild,
 
43
                              rp,
 
44
                              dtmp.rstrip('\\/') + '2')
 
45
 
 
46
            self.assertRaises(PathNotChild,
 
47
                              rp,
 
48
                              dtmp.rstrip('\\/') + '2/foo')
 
49
 
 
50
            # now operations based on relpath of files in current
 
51
            # directory, or nearby
 
52
            os.chdir(dtmp)
 
53
 
 
54
            self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
 
55
 
 
56
            self.assertEqual(rp('foo'), 'foo')
 
57
 
 
58
            self.assertEqual(rp('./foo'), 'foo')
 
59
 
 
60
            self.assertEqual(rp(abspath('foo')), 'foo')
 
61
 
 
62
            self.assertRaises(PathNotChild,
 
63
                              rp, '../foo')
 
64
 
 
65
        finally:
 
66
            os.chdir(savedir)
 
67
            shutil.rmtree(dtmp)