~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/versioning.py

  • Committer: John Arbash Meinel
  • Date: 2005-11-08 18:36:26 UTC
  • mto: This revision was merged to the branch mainline in revision 1727.
  • Revision ID: john@arbash-meinel.com-20051108183626-71f8414338043265
Updating unified_diff to take a factory, using the new diff algorithm in the code.

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
38
37
 
39
 
        run_bzr(['init'])
40
 
        run_bzr(['mkdir', 'foo'])
 
38
        self.run_bzr('init')
 
39
        self.run_bzr('mkdir', 'foo')
41
40
        self.assert_(os.path.isdir('foo'))
42
41
 
43
 
        self.assertRaises(OSError, run_bzr, ['mkdir', 'foo'])
 
42
        self.run_bzr('mkdir', 'foo', retcode=2)
44
43
 
45
44
        from bzrlib.diff import compare_trees
46
45
        from bzrlib.branch import Branch
47
 
        b = Branch('.')
 
46
        b = Branch.open('.')
48
47
        
49
48
        delta = compare_trees(b.basis_tree(), b.working_tree())
50
49
 
63
62
        from bzrlib.branch import Branch
64
63
        from bzrlib.errors import NotVersionedError
65
64
 
66
 
        b = Branch('.', init=True)
 
65
        b = Branch.initialize('.')
67
66
 
68
67
        self.build_tree(['foo/',
69
68
                         'foo/hello'])
72
71
                          b.add,
73
72
                          'foo/hello')
74
73
        
75
 
        self.check_and_upgrade()
76
 
 
 
74
        self.check_branch()
77
75
 
78
76
    def test_add_in_unversioned(self):
79
77
        """Try to add a file in an unversioned directory.
81
79
        "bzr add" should add the parent(s) as necessary.
82
80
        """
83
81
        from bzrlib.branch import Branch
84
 
        from bzrlib.commands import run_bzr
85
82
        eq = self.assertEqual
86
83
 
87
 
        b = Branch('.', init=True)
 
84
        b = Branch.initialize('.')
88
85
 
89
86
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
90
87
        eq(list(b.unknowns()), ['inertiatic'])
91
 
        run_bzr(['add', 'inertiatic/esp'])
 
88
        self.run_bzr('add', 'inertiatic/esp')
92
89
        eq(list(b.unknowns()), [])
93
90
 
94
91
        # Multiple unversioned parents
95
92
        self.build_tree(['veil/', 'veil/cerpin/', 'veil/cerpin/taxt'])
96
93
        eq(list(b.unknowns()), ['veil'])
97
 
        run_bzr(['add', 'veil/cerpin/taxt'])
 
94
        self.run_bzr('add', 'veil/cerpin/taxt')
98
95
        eq(list(b.unknowns()), [])
99
96
 
100
97
        # Check whacky paths work
101
98
        self.build_tree(['cicatriz/', 'cicatriz/esp'])
102
99
        eq(list(b.unknowns()), ['cicatriz'])
103
 
        run_bzr(['add', 'inertiatic/../cicatriz/esp'])
 
100
        self.run_bzr('add', 'inertiatic/../cicatriz/esp')
104
101
        eq(list(b.unknowns()), [])
105
102
 
106
103
    def test_add_in_versioned(self):
109
106
        "bzr add" should do this happily.
110
107
        """
111
108
        from bzrlib.branch import Branch
112
 
        from bzrlib.commands import run_bzr
113
109
        eq = self.assertEqual
114
110
 
115
 
        b = Branch('.', init=True)
 
111
        b = Branch.initialize('.')
116
112
 
117
113
        self.build_tree(['inertiatic/', 'inertiatic/esp'])
118
114
        eq(list(b.unknowns()), ['inertiatic'])
119
 
        run_bzr(['add', '--no-recurse', 'inertiatic'])
120
 
        eq(list(b.unknowns()), ['inertiatic/esp'])
121
 
        run_bzr(['add', 'inertiatic/esp'])
 
115
        self.run_bzr('add', '--no-recurse', 'inertiatic')
 
116
        eq(list(b.unknowns()), ['inertiatic'+os.sep+'esp'])
 
117
        self.run_bzr('add', 'inertiatic/esp')
122
118
        eq(list(b.unknowns()), [])
123
119
 
124
120
    def test_subdir_add(self):
125
121
        """Add in subdirectory should add only things from there down"""
126
122
        
127
123
        from bzrlib.branch import Branch
128
 
        from bzrlib.commands import run_bzr
129
124
        
130
125
        eq = self.assertEqual
131
126
        ass = self.assert_
132
127
        chdir = os.chdir
133
128
        
134
 
        b = Branch('.', init=True)
 
129
        b = Branch.initialize('.')
 
130
        t = b.working_tree()
135
131
        self.build_tree(['src/', 'README'])
136
132
        
137
133
        eq(sorted(b.unknowns()),
138
134
           ['README', 'src'])
139
135
        
140
 
        eq(run_bzr(['add', 'src']), 0)
 
136
        self.run_bzr('add', 'src')
141
137
        
142
138
        self.build_tree(['src/foo.c'])
143
139
        
144
140
        chdir('src')
145
 
        eq(run_bzr(['add']), 0)
 
141
        self.run_bzr('add')
146
142
        
147
143
        eq(sorted(b.unknowns()), 
148
144
           ['README'])
149
 
        eq(len(b.inventory), 3)
 
145
        eq(len(t.read_working_inventory()), 3)
150
146
                
151
147
        chdir('..')
152
 
        eq(run_bzr(['add']), 0)
 
148
        self.run_bzr('add')
153
149
        eq(list(b.unknowns()), [])
154
150
 
155
 
        self.check_and_upgrade()
156
 
 
157
 
 
158
 
    def check_and_upgrade(self):
 
151
        self.check_branch()
 
152
 
 
153
    def check_branch(self):
159
154
        """After all the above changes, run the check and upgrade commands.
160
155
 
161
156
        The upgrade should be a no-op."""
162
 
        b = Branch('.')
 
157
        b = Branch.open('.')
163
158
        debug('branch has %d revisions', b.revno())
164
159
        
165
160
        debug('check branch...')
166
161
        from bzrlib.check import check
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
        check(b, False)
176
163
        
177
164
 
178
165
        
186
173
        self.build_tree(['a/', 'b/'])
187
174
        
188
175
        run_bzr('init')
189
 
        b = Branch('.')
 
176
        b = Branch.open('.')
190
177
        
191
178
        for fn in ('a/one', 'b/two', 'top'):
192
179
            file(fn, 'w').write('old contents')
197
184
        for fn in ('a/one', 'b/two', 'top'):
198
185
            file(fn, 'w').write('new contents')
199
186
            
 
187
        debug('start selective subdir commit')
200
188
        run_bzr('commit', 'a', '-m', 'commit a only')
201
189
        
202
 
        old = b.revision_tree(b.lookup_revision(1))
203
 
        new = b.revision_tree(b.lookup_revision(2))
 
190
        old = b.revision_tree(b.get_rev_id(1))
 
191
        new = b.revision_tree(b.get_rev_id(2))
204
192
        
205
193
        eq(new.get_file_by_path('b/two').read(), 'old contents')
206
194
        eq(new.get_file_by_path('top').read(), 'old contents')
209
197
        os.chdir('a')
210
198
        # commit from here should do nothing
211
199
        run_bzr('commit', '.', '-m', 'commit subdir only', '--unchanged')
212
 
        v3 = b.revision_tree(b.lookup_revision(3))
 
200
        v3 = b.revision_tree(b.get_rev_id(3))
213
201
        eq(v3.get_file_by_path('b/two').read(), 'old contents')
214
202
        eq(v3.get_file_by_path('top').read(), 'old contents')
215
203
        eq(v3.get_file_by_path('a/one').read(), 'new contents')
216
204
                
217
205
        # commit in subdirectory commits whole tree
218
206
        run_bzr('commit', '-m', 'commit whole tree from subdir')
219
 
        v4 = b.revision_tree(b.lookup_revision(4))
 
207
        v4 = b.revision_tree(b.get_rev_id(4))
220
208
        eq(v4.get_file_by_path('b/two').read(), 'new contents')        
221
209
        eq(v4.get_file_by_path('top').read(), 'new contents')
222
210
        
223
211
        # TODO: factor out some kind of assert_tree_state() method
224
212
        
 
213
 
 
214
if __name__ == '__main__':
 
215
    import unittest
 
216
    unittest.main()
 
217