File: test_exc.py

package info (click to toggle)
python-bottle 0.13.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,540 kB
  • sloc: python: 6,417; makefile: 70; sh: 30
file content (41 lines) | stat: -rw-r--r-- 1,135 bytes parent folder | download
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
33
34
35
36
37
38
39
40
41
import bottle
from .tools import ServerTestBase

class SomeError(Exception):
    pass

class TestAppException(ServerTestBase):

    def test_no_exc(self):
        @bottle.route('/')
        def test(): return 'test'
        self.assertBody('test', '/')

    def test_memory_error(self):
        @bottle.route('/')
        def test(): raise MemoryError
        with self.assertRaises(MemoryError):
            self.urlopen("/")

    def test_system_Exit(self):
        @bottle.route('/')
        def test(): raise SystemExit
        with self.assertRaises(SystemExit):
            self.urlopen("/")

    def test_other_error(self):
        @bottle.route('/')
        def test(): raise SomeError
        self.assertStatus(500, '/')
        self.assertInBody('SomeError')

    def test_noncatched_error(self):
        @bottle.route('/')
        def test(): raise SomeError
        bottle.request.environ['exc_info'] = None
        self.app.catchall = False
        with self.assertRaises(SomeError):
            self.urlopen("/")
        self.app.catchall = True
        self.assertStatus(500, '/')
        self.assertInBody('SomeError')