~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_crash.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-02-03 10:06:19 UTC
  • mfrom: (4999.3.2 apport)
  • Revision ID: pqm@pqm.ubuntu.com-20100203100619-f76bo5y5bd5c14wk
(mbp) use apport to send bugs, not just store them

Show diffs side-by-side

added added

removed removed

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