sources for test_repr.py [rev. 38799]
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
import py
from py.__.test.representation import Presenter
from py.__.test.terminal.out import getout
from StringIO import StringIO
import sys
def newconfig(*args):
    tmpdir = py.test.ensuretemp("newconfig")
    args = list(args)
    args.append(tmpdir)
    return py.test.config._reparse(args)
    
def test_repr_source():
    source = py.code.Source("""
    def f(x):
        pass
    """).strip()
    config = newconfig()
    s = StringIO()
    out = getout(s)
    p = Presenter(out, config)
    p.repr_source(source, "|", 0)
    lines = s.getvalue().split("\n")
    assert len(lines) == 3
    assert lines[0].startswith("|")
    assert lines[0].find("def f(x)") != -1
    assert lines[1].find("pass") != -1
def test_repr_failure_explanation():
    """ We check here if indentation is right
    """
    def f():
        def g():
            1/0
        try:
            g()
        except:
            e = py.code.ExceptionInfo()
        return e
    config = newconfig()
    s = StringIO()
    out = getout(s)
    p = Presenter(out, config)
    source = py.code.Source(f)
    e = f()
    p.repr_failure_explanation(e, source)
    assert s.getvalue().startswith(">   ")
def test_repr_local():
    config = newconfig('--showlocals')
    s = StringIO()
    out = getout(s)
    p = Presenter(out, config)
    p.repr_locals(locals())
    for key in locals().keys():
        assert s.getvalue().find(key) != -1
def test_repr_traceback_long():
    py.test.skip("unfinished")
    config = py.test.config._reparse([])
    s = StringIO()
    out = getout(s)
    p = Presenter(out, config)
    # errr... here we should
    # a) prepare an item
    # b) prepare excinfo
    # c) prepare some traceback info, with few different ideas,
    #    like recursion detected etc.
    # test it...