/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_trace.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-01-14 00:01:32 UTC
  • mfrom: (4957.1.1 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20100114000132-3p3rabnonjw3gzqb
(jam) Merge bzr.stable, bringing in bug fixes #175839, #504390

Show diffs side-by-side

added added

removed removed

Lines of Context:
85
85
    def test_format_os_error(self):
86
86
        try:
87
87
            os.rmdir('nosuchfile22222')
88
 
        except OSError:
89
 
            pass
 
88
        except OSError, e:
 
89
            e_str = str(e)
90
90
        msg = _format_exception()
91
 
        self.assertContainsRe(msg,
92
 
            r'^bzr: ERROR: \[Errno .*\] No such file.*nosuchfile22222')
 
91
        # Linux seems to give "No such file" but Windows gives "The system
 
92
        # cannot find the file specified".
 
93
        self.assertEqual('bzr: ERROR: %s\n' % (e_str,), msg)
93
94
 
94
95
    def test_format_io_error(self):
95
96
        try:
97
98
        except IOError:
98
99
            pass
99
100
        msg = _format_exception()
100
 
        self.assertContainsRe(msg, r'^bzr: ERROR: \[Errno .*\] No such file.*nosuchfile')
 
101
        # Even though Windows and Linux differ for 'os.rmdir', they both give
 
102
        # 'No such file' for open()
 
103
        self.assertContainsRe(msg,
 
104
            r'^bzr: ERROR: \[Errno .*\] No such file.*nosuchfile')
101
105
 
102
106
    def test_format_unicode_error(self):
103
107
        try:
141
145
    def test_trace_unicode(self):
142
146
        """Write Unicode to trace log"""
143
147
        self.log(u'the unicode character for benzene is \N{BENZENE RING}')
144
 
        self.assertContainsRe(self._get_log(keep_log_file=True),
145
 
                              "the unicode character for benzene is")
 
148
        log = self.get_log()
 
149
        self.assertContainsRe(log, "the unicode character for benzene is")
146
150
 
147
151
    def test_trace_argument_unicode(self):
148
152
        """Write a Unicode argument to the trace log"""
149
153
        mutter(u'the unicode character for benzene is %s', u'\N{BENZENE RING}')
150
 
        self.assertContainsRe(self._get_log(keep_log_file=True),
151
 
                              'the unicode character')
 
154
        log = self.get_log()
 
155
        self.assertContainsRe(log, 'the unicode character')
152
156
 
153
157
    def test_trace_argument_utf8(self):
154
158
        """Write a Unicode argument to the trace log"""
155
159
        mutter(u'the unicode character for benzene is %s',
156
160
               u'\N{BENZENE RING}'.encode('utf-8'))
157
 
        self.assertContainsRe(self._get_log(keep_log_file=True),
158
 
                              'the unicode character')
 
161
        log = self.get_log()
 
162
        self.assertContainsRe(log, 'the unicode character')
159
163
 
160
164
    def test_report_broken_pipe(self):
161
165
        try:
174
178
    def test_mutter_callsite_1(self):
175
179
        """mutter_callsite can capture 1 level of stack frame."""
176
180
        mutter_callsite(1, "foo %s", "a string")
177
 
        log = self._get_log(keep_log_file=True)
 
181
        log = self.get_log()
178
182
        # begin with the message
179
183
        self.assertLogStartsWith(log, 'foo a string\nCalled from:\n')
180
184
        # should show two frame: this frame and the one above
186
190
    def test_mutter_callsite_2(self):
187
191
        """mutter_callsite can capture 2 levels of stack frame."""
188
192
        mutter_callsite(2, "foo %s", "a string")
189
 
        log = self._get_log(keep_log_file=True)
 
193
        log = self.get_log()
190
194
        # begin with the message
191
195
        self.assertLogStartsWith(log, 'foo a string\nCalled from:\n')
192
196
        # should show two frame: this frame and the one above
198
202
    def test_mutter_never_fails(self):
199
203
        # Even if the decode/encode stage fails, mutter should not
200
204
        # raise an exception
 
205
        # This test checks that mutter doesn't fail; the current behaviour
 
206
        # is that it doesn't fail *and writes non-utf8*.
201
207
        mutter(u'Writing a greek mu (\xb5) works in a unicode string')
202
208
        mutter('But fails in an ascii string \xb5')
203
209
        mutter('and in an ascii argument: %s', '\xb5')
204
 
        log = self._get_log(keep_log_file=True)
 
210
        log = self.get_log()
205
211
        self.assertContainsRe(log, 'Writing a greek mu')
206
212
        self.assertContainsRe(log, "But fails in an ascii string")
207
 
        self.assertContainsRe(log, u"ascii argument: \xb5")
 
213
        # However, the log content object does unicode replacement on reading
 
214
        # to let it get unicode back where good data has been written. So we
 
215
        # have to do a replaceent here as well.
 
216
        self.assertContainsRe(log, "ascii argument: \xb5".decode('utf8',
 
217
            'replace'))
208
218
 
209
219
    def test_push_log_file(self):
210
220
        """Can push and pop log file, and this catches mutter messages.
283
293
    def test_log_rollover(self):
284
294
        temp_log_name = 'test-log'
285
295
        trace_file = open(temp_log_name, 'at')
286
 
        trace_file.write('test_log_rollover padding\n' * 1000000)
 
296
        trace_file.writelines(['test_log_rollover padding\n'] * 200000)
287
297
        trace_file.close()
288
298
        _rollover_trace_maybe(temp_log_name)
289
299
        # should have been rolled over