~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_trace.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-05-18 13:02:52 UTC
  • mfrom: (5830.3.6 i18n-msgfmt)
  • Revision ID: pqm@pqm.ubuntu.com-20110518130252-ky96qcvzt6o0zg3f
(mbp) add build_mo command to setup.py (INADA Naoki)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011, 2016 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
 
21
21
from cStringIO import StringIO
22
22
import errno
23
 
import logging
24
23
import os
25
24
import re
26
25
import sys
82
81
        except MemoryError:
83
82
            pass
84
83
        msg = _format_exception()
85
 
        self.assertEqual(msg,
 
84
        self.assertEquals(msg,
86
85
            "bzr: out of memory\nUse -Dmem_dump to dump memory to a file.\n")
87
86
 
88
87
    def test_format_mem_dump(self):
114
113
        msg = _format_exception()
115
114
        # Even though Windows and Linux differ for 'os.rmdir', they both give
116
115
        # 'No such file' for open()
117
 
        # However it now gets translated so we can not test for a specific message
118
116
        self.assertContainsRe(msg,
119
 
            r'^bzr: ERROR: \[Errno .*\] .*nosuchfile')
 
117
            r'^bzr: ERROR: \[Errno .*\] No such file.*nosuchfile')
120
118
 
121
119
    def test_format_pywintypes_error(self):
122
120
        self.requireFeature(features.pywintypes)
130
128
        #                with errno, function name, and locale error message
131
129
        self.assertContainsRe(msg,
132
130
            r"^bzr: ERROR: \(2, 'RemoveDirectory[AW]?', .*\)")
133
 
            
134
 
    def test_format_sockets_error(self):
135
 
        try:
136
 
            import socket
137
 
            sock = socket.socket()
138
 
            sock.send("This should fail.")
139
 
        except socket.error:
140
 
            pass
141
 
        msg = _format_exception()
142
 
        
143
 
        self.assertNotContainsRe(msg,
144
 
            r"Traceback (most recent call last):")
145
131
 
146
132
    def test_format_unicode_error(self):
147
133
        try:
204
190
    def test_report_broken_pipe(self):
205
191
        try:
206
192
            raise IOError(errno.EPIPE, 'broken pipe foofofo')
207
 
        except IOError as e:
 
193
        except IOError, e:
208
194
            msg = _format_exception()
209
 
            self.assertEqual(msg, "bzr: broken pipe\n")
 
195
            self.assertEquals(msg, "bzr: broken pipe\n")
210
196
        else:
211
197
            self.fail("expected error not raised")
212
198
 
255
241
        # have to do a replaceent here as well.
256
242
        self.assertContainsRe(log, "ascii argument: \xb5".decode('utf8',
257
243
            'replace'))
258
 
 
 
244
        
259
245
    def test_show_error(self):
260
246
        show_error('error1')
261
247
        show_error(u'error2 \xb5 blah')
347
333
        self.assertEqual(0, get_verbosity_level())
348
334
 
349
335
 
350
 
class TestLogging(TestCase):
351
 
    """Check logging functionality robustly records information"""
352
 
 
353
 
    def test_note(self):
354
 
        trace.note("Noted")
355
 
        self.assertEqual("    INFO  Noted\n", self.get_log())
356
 
 
357
 
    def test_warning(self):
358
 
        trace.warning("Warned")
359
 
        self.assertEqual(" WARNING  Warned\n", self.get_log())
360
 
 
361
 
    def test_log(self):
362
 
        logging.getLogger("bzr").error("Errored")
363
 
        self.assertEqual("   ERROR  Errored\n", self.get_log())
364
 
 
365
 
    def test_log_sub(self):
366
 
        logging.getLogger("bzr.test_log_sub").debug("Whispered")
367
 
        self.assertEqual("   DEBUG  Whispered\n", self.get_log())
368
 
 
369
 
    def test_log_unicode_msg(self):
370
 
        logging.getLogger("bzr").debug(u"\xa7")
371
 
        self.assertEqual(u"   DEBUG  \xa7\n", self.get_log())
372
 
 
373
 
    def test_log_unicode_arg(self):
374
 
        logging.getLogger("bzr").debug("%s", u"\xa7")
375
 
        self.assertEqual(u"   DEBUG  \xa7\n", self.get_log())
376
 
 
377
 
    def test_log_utf8_msg(self):
378
 
        logging.getLogger("bzr").debug("\xc2\xa7")
379
 
        self.assertEqual(u"   DEBUG  \xa7\n", self.get_log())
380
 
 
381
 
    def test_log_utf8_arg(self):
382
 
        logging.getLogger("bzr").debug("%s", "\xc2\xa7")
383
 
        self.assertEqual(u"   DEBUG  \xa7\n", self.get_log())
384
 
 
385
 
    def test_log_bytes_msg(self):
386
 
        logging.getLogger("bzr").debug("\xa7")
387
 
        log = self.get_log()
388
 
        self.assertContainsString(log, "UnicodeDecodeError: ")
389
 
        self.assertContainsString(log,
390
 
            "Logging record unformattable: '\\xa7' % ()\n")
391
 
 
392
 
    def test_log_bytes_arg(self):
393
 
        logging.getLogger("bzr").debug("%s", "\xa7")
394
 
        log = self.get_log()
395
 
        self.assertContainsString(log, "UnicodeDecodeError: ")
396
 
        self.assertContainsString(log,
397
 
            "Logging record unformattable: '%s' % ('\\xa7',)\n")
398
 
 
399
 
    def test_log_mixed_strings(self):
400
 
        logging.getLogger("bzr").debug(u"%s", "\xa7")
401
 
        log = self.get_log()
402
 
        self.assertContainsString(log, "UnicodeDecodeError: ")
403
 
        self.assertContainsString(log,
404
 
            "Logging record unformattable: u'%s' % ('\\xa7',)\n")
405
 
 
406
 
    def test_log_repr_broken(self):
407
 
        class BadRepr(object):
408
 
            def __repr__(self):
409
 
                raise ValueError("Broken object")
410
 
        logging.getLogger("bzr").debug("%s", BadRepr())
411
 
        log = self.get_log()
412
 
        self.assertContainsRe(log, "ValueError: Broken object\n")
413
 
        self.assertContainsRe(log, "Logging record unformattable: '%s' % .*\n")
414
 
 
415
 
 
416
336
class TestBzrLog(TestCaseInTempDir):
417
337
 
418
338
    def test_log_rollover(self):