/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_version_info.py

  • Committer: John Arbash Meinel
  • Date: 2008-07-09 21:42:24 UTC
  • mto: This revision was merged to the branch mainline in revision 3543.
  • Revision ID: john@arbash-meinel.com-20080709214224-r75k87r6a01pfc3h
Restore a real weave merge to 'bzr merge --weave'.

To do so efficiently, we only add the simple LCAs to the final weave
object, unless we run into complexities with the merge graph.
This gives the same effective result as adding all the texts,
with the advantage of not having to extract all of them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Tests for version_info"""
18
18
 
23
23
 
24
24
from bzrlib import (
25
25
    errors,
26
 
    registry,
27
26
    symbol_versioning,
28
27
    tests,
29
28
    version_info_formats,
54
53
 
55
54
        return wt
56
55
 
57
 
    def test_rio_null(self):
58
 
        wt = self.make_branch_and_tree('branch')
59
 
 
60
 
        sio = StringIO()
61
 
        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt)
62
 
        builder.generate(sio)
63
 
        val = sio.getvalue()
64
 
        self.assertContainsRe(val, 'build-date:')
65
 
        self.assertContainsRe(val, 'revno: 0')
66
 
 
67
56
    def test_rio_version_text(self):
68
57
        wt = self.create_branch()
69
58
 
97
86
        self.assertContainsRe(val, 'id: r3')
98
87
        self.assertContainsRe(val, 'message: \xc3\xa52') # utf8 encoding '\xe5'
99
88
 
100
 
    def test_rio_version_hook(self):
101
 
        def update_stanza(rev, stanza):
102
 
            stanza.add('bla', 'bloe')
103
 
        RioVersionInfoBuilder.hooks.install_named_hook(
104
 
            'revision', update_stanza, None)
105
 
        wt = self.create_branch()
106
 
 
107
 
        def regen(**kwargs):
108
 
            sio = StringIO()
109
 
            builder = RioVersionInfoBuilder(wt.branch, working_tree=wt,
110
 
                                            **kwargs)
111
 
            builder.generate(sio)
112
 
            sio.seek(0)
113
 
            stanzas = list(read_stanzas(sio))
114
 
            self.assertEqual(1, len(stanzas))
115
 
            return stanzas[0]
116
 
 
117
 
        stanza = regen()
118
 
        self.assertEqual(['bloe'], stanza.get_all('bla'))
119
 
 
120
89
    def test_rio_version(self):
121
90
        wt = self.create_branch()
122
91
 
149
118
        stanza = regen(check_for_clean=True, include_file_revisions=True)
150
119
        self.assertEqual(['False'], stanza.get_all('clean'))
151
120
 
152
 
        # This assumes it's being run against a tree that does not update the
153
 
        # root revision on every commit.
 
121
        # XXX: This assumes it's being run against a repository that updates
 
122
        # the root revision on every commit.  Newer ones that use
 
123
        # RootCommitBuilder won't update it on each commit.
154
124
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
155
125
        self.assertEqual(['', 'a', 'b', 'c'], file_rev_stanza.get_all('path'))
156
 
        self.assertEqual(['r1', 'r3', 'r2', 'unversioned'],
 
126
        self.assertEqual(['r3', 'r3', 'r2', 'unversioned'],
157
127
            file_rev_stanza.get_all('revision'))
158
128
        os.remove('branch/c')
159
129
 
169
139
        wt.rename_one('b', 'd')
170
140
        stanza = regen(check_for_clean=True, include_file_revisions=True)
171
141
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
172
 
        self.assertEqual(['', 'a', 'b', 'c', 'd'],
 
142
        self.assertEqual(['', 'a', 'b', 'c', 'd'], 
173
143
                          file_rev_stanza.get_all('path'))
174
 
        self.assertEqual(['r1', 'modified', 'renamed to d', 'new',
 
144
        self.assertEqual(['r3', 'modified', 'renamed to d', 'new', 
175
145
                          'renamed from b'],
176
146
                         file_rev_stanza.get_all('revision'))
177
147
 
181
151
        stanza = regen(check_for_clean=True, include_file_revisions=True)
182
152
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
183
153
        self.assertEqual(['', 'a', 'c', 'd'], file_rev_stanza.get_all('path'))
184
 
        self.assertEqual(['r1', 'r4', 'unversioned', 'removed'],
 
154
        self.assertEqual(['r4', 'r4', 'unversioned', 'removed'],
185
155
                         file_rev_stanza.get_all('revision'))
186
156
 
187
 
    def test_python_null(self):
188
 
        wt = self.make_branch_and_tree('branch')
189
 
 
190
 
        sio = StringIO()
191
 
        builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt)
192
 
        builder.generate(sio)
193
 
        val = sio.getvalue()
194
 
        self.assertContainsRe(val, "'revision_id': None")
195
 
        self.assertContainsRe(val, "'revno': 0")
196
 
 
197
157
    def test_python_version(self):
198
158
        wt = self.create_branch()
199
159
 
234
194
        self.build_tree(['branch/c'])
235
195
        tvi = regen(check_for_clean=True, include_file_revisions=True)
236
196
        self.assertEqual(False, tvi.version_info['clean'])
237
 
        self.assertEqual(['', 'a', 'b', 'c'],
 
197
        self.assertEqual(['', 'a', 'b', 'c'], 
238
198
                         sorted(tvi.file_revisions.keys()))
239
199
        self.assertEqual('r3', tvi.file_revisions['a'])
240
200
        self.assertEqual('r2', tvi.file_revisions['b'])
252
212
        wt.add('c')
253
213
        wt.rename_one('b', 'd')
254
214
        tvi = regen(check_for_clean=True, include_file_revisions=True)
255
 
        self.assertEqual(['', 'a', 'b', 'c', 'd'],
 
215
        self.assertEqual(['', 'a', 'b', 'c', 'd'], 
256
216
                          sorted(tvi.file_revisions.keys()))
257
217
        self.assertEqual('modified', tvi.file_revisions['a'])
258
218
        self.assertEqual('renamed to d', tvi.file_revisions['b'])
263
223
        wt.remove(['c', 'd'])
264
224
        os.remove('branch/d')
265
225
        tvi = regen(check_for_clean=True, include_file_revisions=True)
266
 
        self.assertEqual(['', 'a', 'c', 'd'],
 
226
        self.assertEqual(['', 'a', 'c', 'd'], 
267
227
                          sorted(tvi.file_revisions.keys()))
268
228
        self.assertEqual('r4', tvi.file_revisions['a'])
269
229
        self.assertEqual('unversioned', tvi.file_revisions['c'])
270
230
        self.assertEqual('removed', tvi.file_revisions['d'])
271
231
 
272
 
    def test_custom_null(self):
273
 
        sio = StringIO()
274
 
        wt = self.make_branch_and_tree('branch')
275
 
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
276
 
            template='revno: {revno}')
277
 
        builder.generate(sio)
278
 
        self.assertEquals("revno: 0", sio.getvalue())
279
 
 
280
 
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt, 
281
 
            template='{revno} revid: {revision_id}')
282
 
        # revision_id is not available yet
283
 
        self.assertRaises(errors.MissingTemplateVariable, 
284
 
            builder.generate, sio)
285
 
 
286
232
    def test_custom_version_text(self):
287
233
        wt = self.create_branch()
288
234
 
326
272
 
327
273
    def setUp(self):
328
274
        super(TestVersionInfoFormatRegistry, self).setUp()
329
 
        self.overrideAttr(version_info_formats,
330
 
                          'format_registry', registry.Registry())
 
275
        registry = version_info_formats.format_registry
 
276
        self._default_key = registry._default_key
 
277
        self._dict = registry._dict.copy()
 
278
        self._help_dict = registry._help_dict.copy()
 
279
        self._info_dict = registry._info_dict.copy()
 
280
        self.addCleanup(self._cleanup)
 
281
 
 
282
    def _cleanup(self):
 
283
        # Restore the registry to pristine state after the test runs
 
284
        registry = version_info_formats.format_registry
 
285
        registry._default_key = self._default_key
 
286
        registry._dict = self._dict
 
287
        registry._help_dict = self._help_dict
 
288
        registry._info_dict = self._info_dict
331
289
 
332
290
    def test_register_remove(self):
333
291
        registry = version_info_formats.format_registry