~ihanick/percona-server/5.1.59-innodb_log_archiving

« back to all changes in this revision

Viewing changes to python-for-subunit2junitxml/testtools/tests/test_with_with.py

  • Committer: Stewart Smith
  • Date: 2011-10-06 06:45:16 UTC
  • Revision ID: stewart@flamingspork.com-20111006064516-rrjg17x7wwn9vr6w
add subunit support to mtr

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2011 testtools developers. See LICENSE for details.
 
2
 
 
3
from __future__ import with_statement
 
4
 
 
5
from testtools import (
 
6
    ExpectedException,
 
7
    TestCase,
 
8
    )
 
9
 
 
10
class TestExpectedException(TestCase):
 
11
    """Test the ExpectedException context manager."""
 
12
 
 
13
    def test_pass_on_raise(self):
 
14
        with ExpectedException(ValueError, 'tes.'):
 
15
            raise ValueError('test')
 
16
 
 
17
    def test_raise_on_text_mismatch(self):
 
18
        try:
 
19
            with ExpectedException(ValueError, 'tes.'):
 
20
                raise ValueError('mismatch')
 
21
        except AssertionError, e:
 
22
            self.assertEqual('"mismatch" does not match "tes.".', str(e))
 
23
        else:
 
24
            self.fail('AssertionError not raised.')
 
25
 
 
26
    def test_raise_on_error_mismatch(self):
 
27
        try:
 
28
            with ExpectedException(TypeError, 'tes.'):
 
29
                raise ValueError('mismatch')
 
30
        except ValueError, e:
 
31
            self.assertEqual('mismatch', str(e))
 
32
        else:
 
33
            self.fail('ValueError not raised.')
 
34
 
 
35
    def test_raise_if_no_exception(self):
 
36
        try:
 
37
            with ExpectedException(TypeError, 'tes.'):
 
38
                pass
 
39
        except AssertionError, e:
 
40
            self.assertEqual('TypeError not raised.', str(e))
 
41
        else:
 
42
            self.fail('AssertionError not raised.')