File: test_ensure_ctxmgr.py

package info (click to toggle)
python-sure 2.0.1%2Bgit.2023.02.06.3aef950b7c-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 744 kB
  • sloc: python: 3,512; makefile: 255; sh: 12
file content (32 lines) | stat: -rw-r--r-- 1,157 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-

import sure


def test_ensure_simple_assertion():
    """Test ensure simple assertion"""

    def __test_something():
        # same calculated value
        name = 'Hodor'
        with sure.ensure('the return value actually looks like: {0}', name):
            sure.expect(name).should.contain('whatever')


    # check if the test function raises the custom AssertionError
    sure.expect(__test_something).when.called_with().should.throw(AssertionError, \
                                                                  'the return value actually looks like: Hodor')


def test_ensure_just_assertion_error():
    """Test that ensure only captures AssertionErrors"""
    def __test_something():
        # same calculated value
        with sure.ensure('neverused'):
            raise Exception('This is not an AssertionError')


    # check if the test function does not override the original exception
    # if it is not an AssertionError exception
    sure.expect(__test_something).when.called_with().should.throw(Exception, \
                                                                  'This is not an AssertionError')