/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_whitebox.py

  • Committer: Marius Kruger
  • Date: 2010-07-10 21:28:56 UTC
  • mto: (5384.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5385.
  • Revision ID: marius.kruger@enerweb.co.za-20100710212856-uq4ji3go0u5se7hx
* Update documentation
* add NEWS

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2008-2012 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import os
 
18
import unittest
18
19
 
19
 
import breezy
20
 
from .. import (
21
 
    errors,
 
20
from bzrlib import (
22
21
    osutils,
23
 
    tests,
24
22
    )
25
 
from ..osutils import relpath, pathjoin, abspath, realpath
26
 
 
27
 
 
28
 
class MoreTests(tests.TestCaseWithTransport):
 
23
from bzrlib.tests import TestCaseWithTransport, TestCase
 
24
from bzrlib.branch import Branch
 
25
from bzrlib.errors import PathNotChild
 
26
from bzrlib.osutils import relpath, pathjoin, abspath, realpath
 
27
 
 
28
 
 
29
class MoreTests(TestCaseWithTransport):
29
30
 
30
31
    def test_relpath(self):
31
32
        """test for branch path lookups
32
33
 
33
 
        breezy.osutils._relpath do a simple but subtle
 
34
        bzrlib.osutils._relpath do a simple but subtle
34
35
        job: given a path (either relative to cwd or absolute), work out
35
36
        if it is inside a branch and return the path relative to the base.
36
37
        """
 
38
        import tempfile
 
39
 
 
40
        savedir = os.getcwdu()
37
41
        dtmp = osutils.mkdtemp()
38
 
        self.addCleanup(osutils.rmtree, dtmp)
39
42
        # On Mac OSX, /tmp actually expands to /private/tmp
40
43
        dtmp = realpath(dtmp)
41
44
 
42
45
        def rp(p):
43
46
            return relpath(dtmp, p)
44
47
 
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,
56
 
                          dtmp.rstrip('\\/') + '2/foo')
57
 
 
58
 
        # now operations based on relpath of files in current
59
 
        # directory, or nearby
60
 
 
61
 
        os.chdir(dtmp)
62
 
        self.assertEqual('foo/bar/quux', rp('foo/bar/quux'))
63
 
        self.assertEqual('foo', rp('foo'))
64
 
        self.assertEqual('foo', rp('./foo'))
65
 
        self.assertEqual('foo', rp(abspath('foo')))
66
 
        self.assertRaises(errors.PathNotChild, rp, '../foo')
 
48
        try:
 
49
            # check paths inside dtmp while standing outside it
 
50
            self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
 
51
 
 
52
            # root = nothing
 
53
            self.assertEqual(rp(dtmp), '')
 
54
 
 
55
            self.assertRaises(PathNotChild,
 
56
                              rp,
 
57
                              '/etc')
 
58
 
 
59
            # now some near-miss operations -- note that
 
60
            # os.path.commonprefix gets these wrong!
 
61
            self.assertRaises(PathNotChild,
 
62
                              rp,
 
63
                              dtmp.rstrip('\\/') + '2')
 
64
 
 
65
            self.assertRaises(PathNotChild,
 
66
                              rp,
 
67
                              dtmp.rstrip('\\/') + '2/foo')
 
68
 
 
69
            # now operations based on relpath of files in current
 
70
            # directory, or nearby
 
71
            os.chdir(dtmp)
 
72
 
 
73
            self.assertEqual(rp('foo/bar/quux'), 'foo/bar/quux')
 
74
 
 
75
            self.assertEqual(rp('foo'), 'foo')
 
76
 
 
77
            self.assertEqual(rp('./foo'), 'foo')
 
78
 
 
79
            self.assertEqual(rp(abspath('foo')), 'foo')
 
80
 
 
81
            self.assertRaises(PathNotChild,
 
82
                              rp, '../foo')
 
83
 
 
84
        finally:
 
85
            os.chdir(savedir)
 
86
            osutils.rmtree(dtmp)