~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_whitebox.py

  • Committer: Jelmer Vernooij
  • Date: 2016-04-03 16:32:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6617.
  • Revision ID: jelmer@jelmer.uk-20160403163231-h72bo0uyek2gikw0
Don't put French text in doc/en/user-reference when LANGUAGE=fr_CH.UTF_8.

Show diffs side-by-side

added added

removed removed

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