~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/versioning.py

bugfix from Aaron Bentley - bzrlib.graph.max_distance had an off-by-1 error

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
    
35
35
    def test_mkdir(self): 
36
36
        """Basic 'bzr mkdir' operation"""
 
37
        from bzrlib.commands import run_bzr
37
38
 
38
 
        self.run_bzr('init')
39
 
        self.run_bzr('mkdir', 'foo')
 
39
        run_bzr(['init'])
 
40
        run_bzr(['mkdir', 'foo'])
40
41
        self.assert_(os.path.isdir('foo'))
41
42
 
42
 
        self.run_bzr('mkdir', 'foo', retcode=2)
 
43
        self.assertRaises(OSError, run_bzr, ['mkdir', 'foo'])
43
44
 
44
45
        from bzrlib.diff import compare_trees
45
46
        from bzrlib.branch import Branch
71
72
                          b.add,
72
73
                          'foo/hello')
73
74
        
74
 
        self.check_branch()
 
75
        self.check_and_upgrade()
 
76
 
75
77
 
76
78
    def test_add_in_unversioned(self):
77
79
        """Try to add a file in an unversioned directory.
79
81
        "bzr add" should add the parent(s) as necessary.
80
82
        """
81
83
        from bzrlib.branch import Branch
 
84
        from bzrlib.commands import run_bzr
82
85
        eq = self.assertEqual
83
86
 
84
87
        b = Branch.initialize('.')
85
88
 
86
89
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
87
90
        eq(list(b.unknowns()), ['inertiatic'])
88
 
        self.run_bzr('add', 'inertiatic/esp')
 
91
        run_bzr(['add', 'inertiatic/esp'])
89
92
        eq(list(b.unknowns()), [])
90
93
 
91
94
        # Multiple unversioned parents
92
95
        self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
93
96
        eq(list(b.unknowns()), ['veil'])
94
 
        self.run_bzr('add', 'veil/cerpin/taxt')
 
97
        run_bzr(['add', 'veil/cerpin/taxt'])
95
98
        eq(list(b.unknowns()), [])
96
99
 
97
100
        # Check whacky paths work
98
101
        self.build_tree(['cicatriz/', 'cicatriz/esp'])
99
102
        eq(list(b.unknowns()), ['cicatriz'])
100
 
        self.run_bzr('add', 'inertiatic/../cicatriz/esp')
 
103
        run_bzr(['add', 'inertiatic/../cicatriz/esp'])
101
104
        eq(list(b.unknowns()), [])
102
105
 
103
106
    def test_add_in_versioned(self):
106
109
        "bzr add" should do this happily.
107
110
        """
108
111
        from bzrlib.branch import Branch
 
112
        from bzrlib.commands import run_bzr
109
113
        eq = self.assertEqual
110
114
 
111
115
        b = Branch.initialize('.')
112
116
 
113
117
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
114
118
        eq(list(b.unknowns()), ['inertiatic'])
115
 
        self.run_bzr('add', '--no-recurse', 'inertiatic')
116
 
        eq(list(b.unknowns()), ['inertiatic'+os.sep+'esp'])
117
 
        self.run_bzr('add', 'inertiatic/esp')
 
119
        run_bzr(['add', '--no-recurse', 'inertiatic'])
 
120
        eq(list(b.unknowns()), ['inertiatic/esp'])
 
121
        run_bzr(['add', 'inertiatic/esp'])
118
122
        eq(list(b.unknowns()), [])
119
123
 
120
124
    def test_subdir_add(self):
121
125
        """Add in subdirectory should add only things from there down"""
122
126
        
123
127
        from bzrlib.branch import Branch
 
128
        from bzrlib.commands import run_bzr
124
129
        
125
130
        eq = self.assertEqual
126
131
        ass = self.assert_
132
137
        eq(sorted(b.unknowns()),
133
138
           ['README', 'src'])
134
139
        
135
 
        self.run_bzr('add', 'src')
 
140
        eq(run_bzr(['add', 'src']), 0)
136
141
        
137
142
        self.build_tree(['src/foo.c'])
138
143
        
139
144
        chdir('src')
140
 
        self.run_bzr('add')
 
145
        eq(run_bzr(['add']), 0)
141
146
        
142
147
        eq(sorted(b.unknowns()), 
143
148
           ['README'])
144
149
        eq(len(b.inventory), 3)
145
150
                
146
151
        chdir('..')
147
 
        self.run_bzr('add')
 
152
        eq(run_bzr(['add']), 0)
148
153
        eq(list(b.unknowns()), [])
149
154
 
150
 
        self.check_branch()
151
 
 
152
 
    def check_branch(self):
 
155
        self.check_and_upgrade()
 
156
 
 
157
 
 
158
    def check_and_upgrade(self):
153
159
        """After all the above changes, run the check and upgrade commands.
154
160
 
155
161
        The upgrade should be a no-op."""
158
164
        
159
165
        debug('check branch...')
160
166
        from bzrlib.check import check
161
 
        check(b, False)
 
167
        check(b)
 
168
        
 
169
        debug('upgrade branch...')
 
170
        from bzrlib.upgrade import upgrade
 
171
        upgrade(b)
 
172
        
 
173
        debug('check branch...')
 
174
        from bzrlib.check import check
 
175
        check(b)
162
176
        
163
177
 
164
178
        
183
197
        for fn in ('a/one', 'b/two', 'top'):
184
198
            file(fn, 'w').write('new contents')
185
199
            
186
 
        debug('start selective subdir commit')
187
200
        run_bzr('commit', 'a', '-m', 'commit a only')
188
201
        
189
202
        old = b.revision_tree(b.get_rev_id(1))
209
222
        
210
223
        # TODO: factor out some kind of assert_tree_state() method
211
224
        
212
 
 
213
 
if __name__ == '__main__':
214
 
    import unittest
215
 
    unittest.main()
216