~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_whitebox.py

Add notes on merge/review process.

Show diffs side-by-side

added added

removed removed

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