~bzr-pqm/bzr/bzr.dev

768 by Martin Pool
- start some tests for directory renames
1
import os
2
import unittest
3
1185.31.25 by John Arbash Meinel
Renamed all of the tests from selftest/foo.py to tests/test_foo.py
4
from bzrlib.tests import TestCaseInTempDir, TestCase
768 by Martin Pool
- start some tests for directory renames
5
from bzrlib.branch import ScratchBranch, Branch
1501 by Robert Collins
Move revert from Branch to WorkingTree.
6
from bzrlib.errors import NotBranchError
778 by Martin Pool
- simple revert of text files
7
8
1141 by Martin Pool
- rename FunctionalTest to TestCaseInTempDir
9
class TestBranch(TestCaseInTempDir):
1102 by Martin Pool
- merge test refactoring from robertc
10
11
    def test_no_changes(self):
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
12
        from bzrlib.errors import PointlessCommit
882 by Martin Pool
- Optionally raise EmptyCommit if there are no changes. Test for this.
13
        
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
14
        b = Branch.initialize('.')
882 by Martin Pool
- Optionally raise EmptyCommit if there are no changes. Test for this.
15
16
        self.build_tree(['hello.txt'])
17
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
18
        self.assertRaises(PointlessCommit,
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
19
                          b.working_tree().commit,
882 by Martin Pool
- Optionally raise EmptyCommit if there are no changes. Test for this.
20
                          'commit without adding',
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
21
                          allow_pointless=False)
882 by Martin Pool
- Optionally raise EmptyCommit if there are no changes. Test for this.
22
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
23
        b.working_tree().commit('commit pointless tree',
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
24
                 allow_pointless=True)
883 by Martin Pool
- more tests for detecting empty commits
25
1508.1.5 by Robert Collins
Move add from Branch to WorkingTree.
26
        b.working_tree().add('hello.txt')
883 by Martin Pool
- more tests for detecting empty commits
27
        
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
28
        b.working_tree().commit('commit first added file',
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
29
                 allow_pointless=False)
883 by Martin Pool
- more tests for detecting empty commits
30
        
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
31
        self.assertRaises(PointlessCommit,
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
32
                          b.working_tree().commit,
883 by Martin Pool
- more tests for detecting empty commits
33
                          'commit after adding file',
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
34
                          allow_pointless=False)
883 by Martin Pool
- more tests for detecting empty commits
35
        
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
36
        b.working_tree().commit('commit pointless revision with one file',
885 by Martin Pool
- commit command refuses unless something is changed or --unchanged is given
37
                 allow_pointless=True)
883 by Martin Pool
- more tests for detecting empty commits
38
811 by Martin Pool
- Test case for validate_revision_id
39
1278 by Martin Pool
- remove test that tried to commit absent parents
40
class MoreTests(TestCaseInTempDir):
1390 by Robert Collins
pair programming worx... merge integration and weave
41
1102 by Martin Pool
- merge test refactoring from robertc
42
    def test_rename_dirs(self):
43
        """Test renaming directories and the files within them."""
1185.11.5 by John Arbash Meinel
Merged up-to-date against mainline, still broken.
44
        b = Branch.initialize('.')
768 by Martin Pool
- start some tests for directory renames
45
        self.build_tree(['dir/', 'dir/sub/', 'dir/sub/file'])
1508.1.5 by Robert Collins
Move add from Branch to WorkingTree.
46
        b.working_tree().add(['dir', 'dir/sub', 'dir/sub/file'])
768 by Martin Pool
- start some tests for directory renames
47
1457.1.17 by Robert Collins
Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)
48
        b.working_tree().commit('create initial state')
768 by Martin Pool
- start some tests for directory renames
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
1508.1.7 by Robert Collins
Move rename_one from Branch to WorkingTree. (Robert Collins).
62
        b.working_tree().rename_one('dir', 'newdir')
771 by Martin Pool
- more tests of directory renames
63
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
64
        self.check_inventory_shape(b.working_tree().read_working_inventory(),
771 by Martin Pool
- more tests of directory renames
65
                                   ['newdir', 'newdir/sub', 'newdir/sub/file'])
66
1508.1.7 by Robert Collins
Move rename_one from Branch to WorkingTree. (Robert Collins).
67
        b.working_tree().rename_one('newdir/sub', 'newdir/newsub')
1497 by Robert Collins
Move Branch.read_working_inventory to WorkingTree.
68
        self.check_inventory_shape(b.working_tree().read_working_inventory(),
771 by Martin Pool
- more tests of directory renames
69
                                   ['newdir', 'newdir/newsub',
70
                                    'newdir/newsub/file'])
71
1102 by Martin Pool
- merge test refactoring from robertc
72
    def test_relpath(self):
73
        """test for branch path lookups
74
    
1457.1.2 by Robert Collins
move branch._relpath into osutils as relpath
75
        bzrlib.osutils._relpath do a simple but subtle
1102 by Martin Pool
- merge test refactoring from robertc
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
        """
1457.1.2 by Robert Collins
move branch._relpath into osutils as relpath
79
        from bzrlib.osutils import relpath
601 by Martin Pool
- whitebox tests for branch path handling
80
        import tempfile, shutil
81
        
82
        savedir = os.getcwdu()
83
        dtmp = tempfile.mkdtemp()
907.1.7 by John Arbash Meinel
Fixed test failure on Mac OSX.
84
        # On Mac OSX, /tmp actually expands to /private/tmp
85
        dtmp = os.path.realpath(dtmp)
601 by Martin Pool
- whitebox tests for branch path handling
86
87
        def rp(p):
1457.1.2 by Robert Collins
move branch._relpath into osutils as relpath
88
            return relpath(dtmp, p)
601 by Martin Pool
- whitebox tests for branch path handling
89
        
90
        try:
91
            # check paths inside dtmp while standing outside it
92
            self.assertEqual(rp(os.path.join(dtmp, 'foo')), 'foo')
93
94
            # root = nothing
95
            self.assertEqual(rp(dtmp), '')
96
97
            self.assertRaises(NotBranchError,
98
                              rp,
99
                              '/etc')
100
101
            # now some near-miss operations -- note that
102
            # os.path.commonprefix gets these wrong!
103
            self.assertRaises(NotBranchError,
104
                              rp,
105
                              dtmp.rstrip('\\/') + '2')
106
107
            self.assertRaises(NotBranchError,
108
                              rp,
109
                              dtmp.rstrip('\\/') + '2/foo')
110
111
            # now operations based on relpath of files in current
112
            # directory, or nearby
113
            os.chdir(dtmp)
114
1185.1.40 by Robert Collins
Merge what applied of Alexander Belchenko's win32 patch.
115
            FOO_BAR_QUUX = os.path.join('foo', 'bar', 'quux')
116
            self.assertEqual(rp('foo/bar/quux'), FOO_BAR_QUUX)
601 by Martin Pool
- whitebox tests for branch path handling
117
118
            self.assertEqual(rp('foo'), 'foo')
119
120
            self.assertEqual(rp('./foo'), 'foo')
121
122
            self.assertEqual(rp(os.path.abspath('foo')), 'foo')
123
124
            self.assertRaises(NotBranchError,
125
                              rp, '../foo')
126
127
        finally:
128
            os.chdir(savedir)
129
            shutil.rmtree(dtmp)