sources for test_web.py [rev. unknown]
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
""" webtest
"""
import py
def setup_module(mod):
    try:
        from pypy.translator.js.main import rpython2javascript
        from pypy.translator.js import commproxy
        mod.commproxy = commproxy
        mod.rpython2javascript = rpython2javascript
    except ImportError:
        py.test.skip("PyPy not found")
    mod.commproxy.USE_MOCHIKIT = False
    mod.rpython2javascript = rpython2javascript
    mod.commproxy = mod.commproxy
    from py.__.test.rsession.web import TestHandler as _TestHandler
    from py.__.test.rsession.web import MultiQueue
    mod._TestHandler = _TestHandler
    mod.MultiQueue = MultiQueue
def test_js_generate():
    from py.__.test.rsession import webjs
    from py.__.test.rsession.web import FUNCTION_LIST, IMPORTED_PYPY
    
    source = rpython2javascript(webjs, FUNCTION_LIST, use_pdb=False)
    assert source
def test_parse_args():
    class TestTestHandler(_TestHandler):
        def __init__(self):
            pass
    h = TestTestHandler()
    assert h.parse_args('foo=bar') == {'foo': 'bar'}
    assert h.parse_args('foo=bar%20baz') == {'foo': 'bar baz'}
    assert h.parse_args('foo%20bar=baz') == {'foo bar': 'baz'}
    assert h.parse_args('foo=bar%baz') == {'foo': 'bar\xbaz'}
    py.test.raises(ValueError, 'h.parse_args("foo")')
class TestMultiQueue(object):
    def test_get_one_sessid(self):
        mq = MultiQueue()
        mq.put(1)
        result = mq.get(1234)
        assert result == 1
    def test_get_two_sessid(self):
        mq = MultiQueue()
        mq.put(1)
        result = mq.get(1234)
        assert result == 1
        mq.put(2)
        result = mq.get(1234)
        assert result == 2
        result = mq.get(5678)
        assert result == 1
        result = mq.get(5678)
        assert result == 2
    def test_get_blocking(self):
        import thread
        result = []
        def getitem(mq, sessid):
            result.append(mq.get(sessid))
        mq = MultiQueue()
        thread.start_new_thread(getitem, (mq, 1234))
        assert not result
        mq.put(1)
        py.std.time.sleep(0.1)
        assert result == [1]
    def test_empty(self):
        mq = MultiQueue()
        assert mq.empty()
        mq.put(1)
        assert not mq.empty()
        result = mq.get(1234)
        result == 1
        assert mq.empty()
        mq.put(2)
        result = mq.get(4567)
        assert result == 1
        result = mq.get(1234)
        assert result == 2
        assert not mq.empty()
        result = mq.get(4567)
        assert result == 2
        assert mq.empty()