Пример #1
0
    def test_config(self):
        reporter = lambda x: x
        environ = {}
        ctx = RequestContext(reporter, environ)
        assert ctx.scriptname == ''

        ctx = RequestContext(reporter, environ, prefix="foo")
        assert ctx.scriptname.startswith('foo')
Пример #2
0
    def test_context(self):
        reporter = lambda x: x
        environ = {}

        ctx = RequestContext(reporter, environ)
        top = LOCAL_STACK.pynba
        assert top is None
        assert ctx.pynba is None

        ctx.push()
        top = LOCAL_STACK.pynba
        assert ctx.pynba == top

        top = LOCAL_STACK.pynba
        ctx.pop()
        assert ctx.pynba is None
        assert ctx.pynba != top
Пример #3
0
    def test_context2(self):
        with self.assertRaises((RuntimeError, AttributeError)):
            pynba.enabled

        reporter = lambda *x, **y: x
        environ = {}
        with RequestContext(reporter, environ) as ctx:
            timer = pynba.timer(foo='bar')
            self.assertIn(timer, pynba.timers)

        ctx.flush()
        with self.assertRaises((RuntimeError, AttributeError)):
            self.assertIn(timer, pynba.timers)

        with ctx:
            ctx.flush()
Пример #4
0
    def test_context(self):
        reporter = lambda x: x
        environ = {}

        top = _CTX_STACK.top
        ctx = RequestContext(reporter, environ)
        self.assertIsNot(ctx, top)
        ctx.push()
        top = _CTX_STACK.top
        self.assertIs(ctx, top)

        ctx.pop()
        top = _CTX_STACK.top
        self.assertIsNot(ctx, top)