~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_crash.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-13 23:16:20 UTC
  • mfrom: (4957 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4960.
  • Revision ID: andrew.bennetts@canonical.com-20100113231620-n6in2yjib2v6z03g
MergeĀ lp:bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009, 2010 Canonical Ltd
 
1
# Copyright (C) 2009 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
18
18
from StringIO import StringIO
19
19
import sys
20
20
 
21
 
 
22
 
import os
23
 
 
24
 
 
25
21
from bzrlib import (
26
 
    config,
27
22
    crash,
28
 
    osutils,
29
 
    symbol_versioning,
30
23
    tests,
31
24
    )
32
25
 
33
26
from bzrlib.tests import features
34
27
 
35
28
 
36
 
class TestApportReporting(tests.TestCaseInTempDir):
 
29
class TestApportReporting(tests.TestCase):
37
30
 
38
31
    _test_needs_features = [features.apport]
39
32
 
40
 
    def test_apport_report(self):
41
 
        crash_dir = osutils.joinpath((self.test_base_dir, 'crash'))
42
 
        os.mkdir(crash_dir)
43
 
        os.environ['APPORT_CRASH_DIR'] = crash_dir
44
 
        self.assertEquals(crash_dir, config.crash_dir())
45
 
 
46
 
        stderr = StringIO()
47
 
 
 
33
    def test_apport_report_contents(self):
48
34
        try:
49
35
            raise AssertionError("my error")
50
36
        except AssertionError, e:
51
37
            pass
52
 
 
53
 
        crash_filename = crash.report_bug_to_apport(sys.exc_info(),
54
 
            stderr)
55
 
 
56
 
        # message explaining the crash
57
 
        self.assertContainsRe(stderr.getvalue(),
58
 
            "    apport-bug %s" % crash_filename)
59
 
 
60
 
        crash_file = open(crash_filename)
61
 
        try:
62
 
            report = crash_file.read()
63
 
        finally:
64
 
            crash_file.close()
65
 
 
66
 
        self.assertContainsRe(report,
67
 
            '(?m)^BzrVersion:') # should be in the traceback
 
38
        outf = StringIO()
 
39
        crash._write_apport_report_to_file(sys.exc_info(), outf)
 
40
        report = outf.getvalue()
 
41
 
 
42
        self.assertContainsRe(report, '(?m)^BzrVersion:')
 
43
        # should be in the traceback
68
44
        self.assertContainsRe(report, 'my error')
69
45
        self.assertContainsRe(report, 'AssertionError')
70
 
        self.assertContainsRe(report, 'test_apport_report')
 
46
        self.assertContainsRe(report, 'test_apport_report_contents')
71
47
        # should also be in there
72
48
        self.assertContainsRe(report, '(?m)^CommandLine:')