/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 breezy/tests/test_whitebox.py

  • Committer: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 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
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import os
18
 
import unittest
19
18
 
20
 
from bzrlib import (
 
19
import breezy
 
20
from .. import (
 
21
    errors,
21
22
    osutils,
 
23
    tests,
22
24
    )
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):
 
25
from ..osutils import relpath, pathjoin, abspath, realpath
 
26
 
 
27
 
 
28
class MoreTests(tests.TestCaseWithTransport):
30
29
 
31
30
    def test_relpath(self):
32
31
        """test for branch path lookups
33
32
 
34
 
        bzrlib.osutils._relpath do a simple but subtle
 
33
        breezy.osutils._relpath do a simple but subtle
35
34
        job: given a path (either relative to cwd or absolute), work out
36
35
        if it is inside a branch and return the path relative to the base.
37
36
        """
38
 
        import tempfile
39
 
 
40
 
        savedir = os.getcwdu()
41
37
        dtmp = osutils.mkdtemp()
 
38
        self.addCleanup(osutils.rmtree, dtmp)
42
39
        # On Mac OSX, /tmp actually expands to /private/tmp
43
40
        dtmp = realpath(dtmp)
44
41
 
45
42
        def rp(p):
46
43
            return relpath(dtmp, p)
47
44
 
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)
 
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')