~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/log.py

  • Committer: John Arbash Meinel
  • Date: 2005-11-21 15:41:58 UTC
  • mto: (1185.50.19 bzr-jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1512.
  • Revision ID: john@arbash-meinel.com-20051121154158-1845aa886bfac4b4
Added test for log formatting, found bug when redirecting short logs to a file instead of stdout.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from cStringIO import StringIO
19
19
 
20
20
from bzrlib.selftest import BzrTestBase, TestCaseInTempDir
21
 
from bzrlib.log import LogFormatter, show_log, LongLogFormatter
 
21
from bzrlib.log import LogFormatter, show_log, LongLogFormatter, ShortLogFormatter
22
22
from bzrlib.branch import Branch
23
23
from bzrlib.errors import InvalidRevisionNumber
24
24
 
160
160
        self.log("escaped commit message: %r", committed_msg)
161
161
        self.assert_(msg != committed_msg)
162
162
        self.assert_(len(committed_msg) > len(msg))
 
163
 
 
164
    def test_trailing_newlines(self):
 
165
        b = Branch.initialize('.')
 
166
        b.nick='test'
 
167
        wt = b.working_tree()
 
168
        open('a', 'wb').write('hello moto\n')
 
169
        b.add('a')
 
170
        wt.commit('simple log message', rev_id='a1'
 
171
                , timestamp=1132586655.459960938, timezone=-6*3600
 
172
                , committer='Joe Foo <joe@foo.com>')
 
173
        open('b', 'wb').write('goodbye\n')
 
174
        b.add('b')
 
175
        wt.commit('multiline\nlog\nmessage\n', rev_id='a2'
 
176
                , timestamp=1132586842.411175966, timezone=-6*3600
 
177
                , committer='Joe Foo <joe@foo.com>')
 
178
 
 
179
        open('c', 'wb').write('just another manic monday\n')
 
180
        b.add('c')
 
181
        wt.commit('single line with trailing newline\n', rev_id='a3'
 
182
                , timestamp=1132587176.835228920, timezone=-6*3600
 
183
                , committer = 'Joe Foo <joe@foo.com>')
 
184
 
 
185
        sio = StringIO()
 
186
        lf = ShortLogFormatter(to_file=sio)
 
187
        show_log(b, lf)
 
188
        self.assertEquals(sio.getvalue(), """\
 
189
    3 Joe Foo\t2005-11-21
 
190
      single line with trailing newline
 
191
 
 
192
    2 Joe Foo\t2005-11-21
 
193
      multiline
 
194
      log
 
195
      message
 
196
 
 
197
    1 Joe Foo\t2005-11-21
 
198
      simple log message
 
199
 
 
200
""")
 
201
 
 
202
        sio = StringIO()
 
203
        lf = LongLogFormatter(to_file=sio)
 
204
        show_log(b, lf)
 
205
        self.assertEquals(sio.getvalue(), """\
 
206
------------------------------------------------------------
 
207
revno: 3
 
208
committer: Joe Foo <joe@foo.com>
 
209
branch nick: test
 
210
timestamp: Mon 2005-11-21 09:32:56 -0600
 
211
message:
 
212
  single line with trailing newline
 
213
------------------------------------------------------------
 
214
revno: 2
 
215
committer: Joe Foo <joe@foo.com>
 
216
branch nick: test
 
217
timestamp: Mon 2005-11-21 09:27:22 -0600
 
218
message:
 
219
  multiline
 
220
  log
 
221
  message
 
222
------------------------------------------------------------
 
223
revno: 1
 
224
committer: Joe Foo <joe@foo.com>
 
225
branch nick: test
 
226
timestamp: Mon 2005-11-21 09:24:15 -0600
 
227
message:
 
228
  simple log message
 
229
""")
 
230