~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_version_info.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-12 03:53:21 UTC
  • mfrom: (4948 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4964.
  • Revision ID: andrew.bennetts@canonical.com-20100112035321-hofpz5p10224ryj3
Merge lp:bzr, resolving conflicts.

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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Tests for version_info"""
18
18
 
53
53
 
54
54
        return wt
55
55
 
 
56
    def test_rio_null(self):
 
57
        wt = self.make_branch_and_tree('branch')
 
58
 
 
59
        sio = StringIO()
 
60
        builder = RioVersionInfoBuilder(wt.branch, working_tree=wt)
 
61
        builder.generate(sio)
 
62
        val = sio.getvalue()
 
63
        self.assertContainsRe(val, 'build-date:')
 
64
        self.assertContainsRe(val, 'revno: 0')
 
65
 
56
66
    def test_rio_version_text(self):
57
67
        wt = self.create_branch()
58
68
 
86
96
        self.assertContainsRe(val, 'id: r3')
87
97
        self.assertContainsRe(val, 'message: \xc3\xa52') # utf8 encoding '\xe5'
88
98
 
 
99
    def test_rio_version_hook(self):
 
100
        def update_stanza(rev, stanza):
 
101
            stanza.add('bla', 'bloe')
 
102
        RioVersionInfoBuilder.hooks.install_named_hook(
 
103
            'revision', update_stanza, None)
 
104
        wt = self.create_branch()
 
105
 
 
106
        def regen(**kwargs):
 
107
            sio = StringIO()
 
108
            builder = RioVersionInfoBuilder(wt.branch, working_tree=wt,
 
109
                                            **kwargs)
 
110
            builder.generate(sio)
 
111
            sio.seek(0)
 
112
            stanzas = list(read_stanzas(sio))
 
113
            self.assertEqual(1, len(stanzas))
 
114
            return stanzas[0]
 
115
 
 
116
        stanza = regen()
 
117
        self.assertEqual(['bloe'], stanza.get_all('bla'))
 
118
 
89
119
    def test_rio_version(self):
90
120
        wt = self.create_branch()
91
121
 
118
148
        stanza = regen(check_for_clean=True, include_file_revisions=True)
119
149
        self.assertEqual(['False'], stanza.get_all('clean'))
120
150
 
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.
 
151
        # This assumes it's being run against a tree that does not update the
 
152
        # root revision on every commit.
124
153
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
125
154
        self.assertEqual(['', 'a', 'b', 'c'], file_rev_stanza.get_all('path'))
126
 
        self.assertEqual(['r3', 'r3', 'r2', 'unversioned'],
 
155
        self.assertEqual(['r1', 'r3', 'r2', 'unversioned'],
127
156
            file_rev_stanza.get_all('revision'))
128
157
        os.remove('branch/c')
129
158
 
139
168
        wt.rename_one('b', 'd')
140
169
        stanza = regen(check_for_clean=True, include_file_revisions=True)
141
170
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
142
 
        self.assertEqual(['', 'a', 'b', 'c', 'd'], 
 
171
        self.assertEqual(['', 'a', 'b', 'c', 'd'],
143
172
                          file_rev_stanza.get_all('path'))
144
 
        self.assertEqual(['r3', 'modified', 'renamed to d', 'new', 
 
173
        self.assertEqual(['r1', 'modified', 'renamed to d', 'new',
145
174
                          'renamed from b'],
146
175
                         file_rev_stanza.get_all('revision'))
147
176
 
151
180
        stanza = regen(check_for_clean=True, include_file_revisions=True)
152
181
        file_rev_stanza = get_one_stanza(stanza, 'file-revisions')
153
182
        self.assertEqual(['', 'a', 'c', 'd'], file_rev_stanza.get_all('path'))
154
 
        self.assertEqual(['r4', 'r4', 'unversioned', 'removed'],
 
183
        self.assertEqual(['r1', 'r4', 'unversioned', 'removed'],
155
184
                         file_rev_stanza.get_all('revision'))
156
185
 
 
186
    def test_python_null(self):
 
187
        wt = self.make_branch_and_tree('branch')
 
188
 
 
189
        sio = StringIO()
 
190
        builder = PythonVersionInfoBuilder(wt.branch, working_tree=wt)
 
191
        builder.generate(sio)
 
192
        val = sio.getvalue()
 
193
        self.assertContainsRe(val, "'revision_id': None")
 
194
        self.assertContainsRe(val, "'revno': 0")
 
195
 
157
196
    def test_python_version(self):
158
197
        wt = self.create_branch()
159
198
 
194
233
        self.build_tree(['branch/c'])
195
234
        tvi = regen(check_for_clean=True, include_file_revisions=True)
196
235
        self.assertEqual(False, tvi.version_info['clean'])
197
 
        self.assertEqual(['', 'a', 'b', 'c'], 
 
236
        self.assertEqual(['', 'a', 'b', 'c'],
198
237
                         sorted(tvi.file_revisions.keys()))
199
238
        self.assertEqual('r3', tvi.file_revisions['a'])
200
239
        self.assertEqual('r2', tvi.file_revisions['b'])
212
251
        wt.add('c')
213
252
        wt.rename_one('b', 'd')
214
253
        tvi = regen(check_for_clean=True, include_file_revisions=True)
215
 
        self.assertEqual(['', 'a', 'b', 'c', 'd'], 
 
254
        self.assertEqual(['', 'a', 'b', 'c', 'd'],
216
255
                          sorted(tvi.file_revisions.keys()))
217
256
        self.assertEqual('modified', tvi.file_revisions['a'])
218
257
        self.assertEqual('renamed to d', tvi.file_revisions['b'])
223
262
        wt.remove(['c', 'd'])
224
263
        os.remove('branch/d')
225
264
        tvi = regen(check_for_clean=True, include_file_revisions=True)
226
 
        self.assertEqual(['', 'a', 'c', 'd'], 
 
265
        self.assertEqual(['', 'a', 'c', 'd'],
227
266
                          sorted(tvi.file_revisions.keys()))
228
267
        self.assertEqual('r4', tvi.file_revisions['a'])
229
268
        self.assertEqual('unversioned', tvi.file_revisions['c'])
230
269
        self.assertEqual('removed', tvi.file_revisions['d'])
231
270
 
 
271
    def test_custom_null(self):
 
272
        sio = StringIO()
 
273
        wt = self.make_branch_and_tree('branch')
 
274
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt,
 
275
            template='revno: {revno}')
 
276
        builder.generate(sio)
 
277
        self.assertEquals("revno: 0", sio.getvalue())
 
278
 
 
279
        builder = CustomVersionInfoBuilder(wt.branch, working_tree=wt, 
 
280
            template='{revno} revid: {revision_id}')
 
281
        # revision_id is not available yet
 
282
        self.assertRaises(errors.MissingTemplateVariable, 
 
283
            builder.generate, sio)
 
284
 
232
285
    def test_custom_version_text(self):
233
286
        wt = self.create_branch()
234
287