/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4634.128.18 by Martin Pool
Update apport crash tests
1
# Copyright (C) 2009, 2010 Canonical Ltd
4584.3.21 by Martin Pool
Start adding tests for apport
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
18
from StringIO import StringIO
19
import sys
20
21
4634.128.18 by Martin Pool
Update apport crash tests
22
import os
23
24
25
from bzrlib import (
26
    config,
27
    crash,
4660.1.1 by Vincent Ladeuil
Let user decide what command is used to run the test suite.
28
    tests,
4634.128.18 by Martin Pool
Update apport crash tests
29
    osutils,
4584.3.21 by Martin Pool
Start adding tests for apport
30
    )
4999.3.1 by Martin Pool
Send crash reports through apport, rather than just dumping files
31
32
from bzrlib.tests import (
33
    features,
34
    TestCaseInTempDir,
35
    )
4584.3.21 by Martin Pool
Start adding tests for apport
36
from bzrlib.tests.features import ApportFeature
37
38
4634.128.18 by Martin Pool
Update apport crash tests
39
class TestApportReporting(TestCaseInTempDir):
4660.1.1 by Vincent Ladeuil
Let user decide what command is used to run the test suite.
40
4913.2.19 by John Arbash Meinel
Compatibly rename ApportFeature to features.apport.
41
    _test_needs_features = [features.apport]
4584.3.21 by Martin Pool
Start adding tests for apport
42
43
    def setUp(self):
4634.128.18 by Martin Pool
Update apport crash tests
44
        TestCaseInTempDir.setUp(self)
4584.3.21 by Martin Pool
Start adding tests for apport
45
        self.requireFeature(ApportFeature)
46
4634.128.18 by Martin Pool
Update apport crash tests
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
4584.3.21 by Martin Pool
Start adding tests for apport
55
        try:
56
            raise AssertionError("my error")
57
        except AssertionError, e:
58
            pass
4634.128.18 by Martin Pool
Update apport crash tests
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
75
        self.assertContainsRe(report, 'my error')
76
        self.assertContainsRe(report, 'AssertionError')
77
        self.assertContainsRe(report, 'test_apport_report')
4584.3.22 by Martin Pool
further tweaks to and tests of bzr apport reporting
78
        # should also be in there
4660.1.2 by Vincent Ladeuil
Review feedback, fix typo and more cleanups.
79
        self.assertContainsRe(report, '(?m)^CommandLine:')