File: test_viewcode.py

package info (click to toggle)
pypy 7.0.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 107,216 kB
  • sloc: python: 1,201,787; ansic: 62,419; asm: 5,169; cpp: 3,017; sh: 2,534; makefile: 545; xml: 243; lisp: 45; awk: 4
file content (73 lines) | stat: -rw-r--r-- 1,409 bytes parent folder | download | duplicates (7)
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
from cStringIO import StringIO
from rpython.jit.backend.tool.viewcode import format_code_dump_with_labels
from rpython.jit.backend.tool.viewcode import find_objdump
import os
import py
import tempfile
from rpython.tool.udir import udir

def test_format_code_dump_with_labels():
    lines = StringIO("""
aa00 <.data>:
aa00: one
aa01: two
aa03: three
aa04: for
aa05: five
aa06: six
aa0c: seven
aa12: eight
""".strip()).readlines()
    #
    label_list = [(0x00, 'AAA'), (0x03, 'BBB'), (0x0c, 'CCC')]
    lines = format_code_dump_with_labels(0xAA00, lines, label_list)
    out = ''.join(lines)
    assert out == """
aa00 <.data>:

AAA
aa00: one
aa01: two

BBB
aa03: three
aa04: for
aa05: five
aa06: six

CCC
aa0c: seven
aa12: eight
""".strip()


def test_format_code_dump_with_labels_no_labels():
    input = """
aa00 <.data>:
aa00: one
aa01: two
aa03: three
aa04: for
aa05: five
aa06: six
aa0c: seven
aa12: eight
""".strip()
    lines = StringIO(input).readlines()
    #
    lines = format_code_dump_with_labels(0xAA00, lines, label_list=None)
    out = ''.join(lines)
    assert out.strip() == input

def test_find_objdump():
    old = os.environ['PATH']
    os.environ['PATH'] = ''
    py.test.raises(Exception, find_objdump)

    #
    path = udir.join('objdump')
    print >>path, 'hello world'
    os.environ['PATH'] = path.dirname
    assert find_objdump() == 'objdump'
    #
    os.environ['PATH'] = old