~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_whitebox.py

MergeĀ fromĀ jam-integration.

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
1
import os
18
2
import unittest
19
3
 
20
 
from bzrlib import (
21
 
    osutils,
22
 
    )
23
 
from bzrlib.tests import TestCaseWithTransport, TestCase
24
 
from bzrlib.branch import Branch
 
4
from bzrlib.tests import TestCaseInTempDir, TestCase
 
5
from bzrlib.branch import ScratchBranch, Branch
25
6
from bzrlib.errors import PathNotChild
26
7
from bzrlib.osutils import relpath, pathjoin, abspath, realpath
27
8
 
28
9
 
29
 
class MoreTests(TestCaseWithTransport):
 
10
class TestBranch(TestCaseInTempDir):
 
11
 
 
12
    def test_no_changes(self):
 
13
        from bzrlib.errors import PointlessCommit
 
14
        
 
15
        b = Branch.initialize(u'.')
 
16
 
 
17
        self.build_tree(['hello.txt'])
 
18
 
 
19
        self.assertRaises(PointlessCommit,
 
20
                          b.working_tree().commit,
 
21
                          'commit without adding',
 
22
                          allow_pointless=False)
 
23
 
 
24
        b.working_tree().commit('commit pointless tree',
 
25
                 allow_pointless=True)
 
26
 
 
27
        b.working_tree().add('hello.txt')
 
28
        
 
29
        b.working_tree().commit('commit first added file',
 
30
                 allow_pointless=False)
 
31
        
 
32
        self.assertRaises(PointlessCommit,
 
33
                          b.working_tree().commit,
 
34
                          'commit after adding file',
 
35
                          allow_pointless=False)
 
36
        
 
37
        b.working_tree().commit('commit pointless revision with one file',
 
38
                 allow_pointless=True)
 
39
 
 
40
 
 
41
class MoreTests(TestCaseInTempDir):
 
42
 
 
43
    def test_rename_dirs(self):
 
44
        """Test renaming directories and the files within them."""
 
45
        b = Branch.initialize(u'.')
 
46
        self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
 
47
        b.working_tree().add(['dir', 'dir/sub', 'dir/sub/file'])
 
48
 
 
49
        b.working_tree().commit('create initial state')
 
50
 
 
51
        # TODO: lift out to a test helper that checks the shape of
 
52
        # an inventory
 
53
        
 
54
        revid = b.revision_history()[0]
 
55
        self.log('first revision_id is {%s}' % revid)
 
56
        
 
57
        inv = b.get_revision_inventory(revid)
 
58
        self.log('contents of inventory: %r' % inv.entries())
 
59
 
 
60
        self.check_inventory_shape(inv,
 
61
                                   ['dir', 'dir/sub', 'dir/sub/file'])
 
62
 
 
63
        b.working_tree().rename_one('dir', 'newdir')
 
64
 
 
65
        self.check_inventory_shape(b.working_tree().read_working_inventory(),
 
66
                                   ['newdir', 'newdir/sub', 'newdir/sub/file'])
 
67
 
 
68
        b.working_tree().rename_one('newdir/sub', 'newdir/newsub')
 
69
        self.check_inventory_shape(b.working_tree().read_working_inventory(),
 
70
                                   ['newdir', 'newdir/newsub',
 
71
                                    'newdir/newsub/file'])
30
72
 
31
73
    def test_relpath(self):
32
74
        """test for branch path lookups
33
 
 
 
75
    
34
76
        bzrlib.osutils._relpath do a simple but subtle
35
77
        job: given a path (either relative to cwd or absolute), work out
36
78
        if it is inside a branch and return the path relative to the base.
37
79
        """
38
 
        import tempfile
39
 
 
 
80
        import tempfile, shutil
 
81
        
40
82
        savedir = os.getcwdu()
41
 
        dtmp = osutils.mkdtemp()
 
83
        dtmp = tempfile.mkdtemp()
42
84
        # On Mac OSX, /tmp actually expands to /private/tmp
43
85
        dtmp = realpath(dtmp)
44
86
 
45
87
        def rp(p):
46
88
            return relpath(dtmp, p)
47
 
 
 
89
        
48
90
        try:
49
91
            # check paths inside dtmp while standing outside it
50
92
            self.assertEqual(rp(pathjoin(dtmp, 'foo')), 'foo')
83
125
 
84
126
        finally:
85
127
            os.chdir(savedir)
86
 
            osutils.rmtree(dtmp)
 
128
            shutil.rmtree(dtmp)