PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/core/test_errors.py

https://bitbucket.org/prologic/circuits/
Python | 60 lines | 38 code | 20 blank | 2 comment | 0 complexity | bef688ba8e9f8b72a1f0fe74855e65d1 MD5 | raw file
 1#!/usr/bin/env python
 2
 3import pytest
 4
 5from circuits import Event, Component
 6
 7
 8class test(Event):
 9    """test Event"""
10
11
12class App(Component):
13
14    def __init__(self):
15        super(App, self).__init__()
16
17        self.etype = None
18        self.evalue = None
19        self.etraceback = None
20        self.handler = None
21        self.fevent = None
22
23    def test(self):
24        return x  # NOQA
25
26    def exception(self, etype, evalue, etraceback, handler=None, fevent=None):
27        self.etype = etype
28        self.evalue = evalue
29        self.etraceback = etraceback
30        self.handler = handler
31        self.fevent = fevent
32
33
34def reraise(e):
35    raise e
36
37
38@pytest.fixture
39def app(request, manager, watcher):
40    app = App().register(manager)
41    watcher.wait("registered")
42
43    def finalizer():
44        app.unregister()
45
46    request.addfinalizer(finalizer)
47
48    return app
49
50
51def test_main(app, watcher):
52    e = test()
53    app.fire(e)
54    watcher.wait("exception")
55
56    assert app.etype == NameError
57    pytest.raises(NameError, lambda e: reraise(e), app.evalue)
58    assert isinstance(app.etraceback, list)
59    assert app.handler == app.test
60    assert app.fevent == e