~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/whitebox.py

  • Committer: Martin Pool
  • Date: 2005-05-31 03:02:45 UTC
  • Revision ID: mbp@sourcefrog.net-20050531030244-d9bbefb14ee48d88
- new bzrlib.get_bzr_revision() tells about the history of 
  bzr itself
- also display revision-id in --version output

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 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
 
import os
18
 
import unittest
19
 
 
20
 
from bzrlib import (
21
 
    osutils,
22
 
    )
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):
30
 
 
31
 
    def test_relpath(self):
32
 
        """test for branch path lookups
33
 
 
34
 
        bzrlib.osutils._relpath do a simple but subtle
35
 
        job: given a path (either relative to cwd or absolute), work out
36
 
        if it is inside a branch and return the path relative to the base.
37
 
        """
38
 
        import tempfile
39
 
 
 
1
#! /usr/bin/python
 
2
 
 
3
from bzrlib.branch import ScratchBranch
 
4
from bzrlib.errors import NotBranchError
 
5
from unittest import TestCase
 
6
import os, unittest
 
7
 
 
8
def Reporter(TestResult):
 
9
    def startTest(self, test):
 
10
        super(Reporter, self).startTest(test)
 
11
        print test.id(),
 
12
 
 
13
    def stopTest(self, test):
 
14
        print
 
15
 
 
16
class BranchPathTestCase(TestCase):
 
17
    """test for branch path lookups
 
18
 
 
19
    Branch.relpath and bzrlib.branch._relpath do a simple but subtle
 
20
    job: given a path (either relative to cwd or absolute), work out
 
21
    if it is inside a branch and return the path relative to the base.
 
22
    """
 
23
    
 
24
    def runTest(self):
 
25
        from bzrlib.branch import _relpath
 
26
        import tempfile, shutil
 
27
        
40
28
        savedir = os.getcwdu()
41
 
        dtmp = osutils.mkdtemp()
42
 
        # On Mac OSX, /tmp actually expands to /private/tmp
43
 
        dtmp = realpath(dtmp)
 
29
        dtmp = tempfile.mkdtemp()
44
30
 
45
31
        def rp(p):
46
 
            return relpath(dtmp, p)
47
 
 
 
32
            return _relpath(dtmp, p)
 
33
        
48
34
        try:
49
35
            # check paths inside dtmp while standing outside it
50
 
            self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
 
36
            self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
51
37
 
52
38
            # root = nothing
53
39
            self.assertEqual(rp(dtmp), '')
54
40
 
55
 
            self.assertRaises(PathNotChild,
 
41
            self.assertRaises(NotBranchError,
56
42
                              rp,
57
43
                              '/etc')
58
44
 
59
45
            # now some near-miss operations -- note that
60
46
            # os.path.commonprefix gets these wrong!
61
 
            self.assertRaises(PathNotChild,
 
47
            self.assertRaises(NotBranchError,
62
48
                              rp,
63
49
                              dtmp.rstrip('\\/') + '2')
64
50
 
65
 
            self.assertRaises(PathNotChild,
 
51
            self.assertRaises(NotBranchError,
66
52
                              rp,
67
53
                              dtmp.rstrip('\\/') + '2/foo')
68
54
 
76
62
 
77
63
            self.assertEqual(rp('./foo'), 'foo')
78
64
 
79
 
            self.assertEqual(rp(abspath('foo')), 'foo')
 
65
            self.assertEqual(rp(os.path.abspath('foo')), 'foo')
80
66
 
81
 
            self.assertRaises(PathNotChild,
 
67
            self.assertRaises(NotBranchError,
82
68
                              rp, '../foo')
83
69
 
84
70
        finally:
85
71
            os.chdir(savedir)
86
 
            osutils.rmtree(dtmp)
 
72
            shutil.rmtree(dtmp)
 
73
 
 
74
 
 
75
                              
 
76
if __name__ == '__main__':
 
77
    unittest.main()
 
78