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

  • Committer: Martin Pool
  • Date: 2010-02-02 16:31:56 UTC
  • mto: (4999.3.1 apport)
  • mto: This revision was merged to the branch mainline in revision 5002.
  • Revision ID: mbp@sourcefrog.net-20100202163156-7y1g0mae6j0ahnea
Update apport crash tests

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
19
19
import sys
20
20
 
21
21
 
22
 
from bzrlib.crash import (
23
 
    report_bug,
24
 
    _write_apport_report_to_file,
 
22
import os
 
23
 
 
24
 
 
25
from bzrlib import (
 
26
    config,
 
27
    crash,
 
28
    osutils,
25
29
    )
26
 
from bzrlib.tests import TestCase
 
30
from bzrlib.tests import TestCaseInTempDir
27
31
from bzrlib.tests.features import ApportFeature
28
32
 
29
33
 
30
 
class TestApportReporting(TestCase):
 
34
class TestApportReporting(TestCaseInTempDir):
31
35
 
32
36
    def setUp(self):
33
 
        TestCase.setUp(self)
 
37
        TestCaseInTempDir.setUp(self)
34
38
        self.requireFeature(ApportFeature)
35
39
 
36
 
    def test_apport_report_contents(self):
 
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
 
37
48
        try:
38
49
            raise AssertionError("my error")
39
50
        except AssertionError, e:
40
51
            pass
41
 
        outf = StringIO()
42
 
        _write_apport_report_to_file(sys.exc_info(),
43
 
            outf)
44
 
        report = outf.getvalue()
45
 
 
46
 
        self.assertContainsRe(report,
47
 
            '(?m)^BzrVersion:')
48
 
        # should be in the traceback
49
 
        self.assertContainsRe(report,
50
 
            'my error')
51
 
        self.assertContainsRe(report,
52
 
            'AssertionError')
53
 
        self.assertContainsRe(report,
54
 
            'test_apport_report_contents')
 
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
 
68
        self.assertContainsRe(report, 'my error')
 
69
        self.assertContainsRe(report, 'AssertionError')
 
70
        self.assertContainsRe(report, 'test_apport_report')
55
71
        # should also be in there
56
72
        self.assertContainsRe(report,
57
73
            '(?m)^CommandLine:.*selftest')