Exemplo n.º 1
0
def test_dump_error():
    contents = u'''
from distutils import sysconfig
'''
    if isinstance(contents, bytes):
        contents = contents.decode('utf-8')
    source_to_dict(contents)
Exemplo n.º 2
0
def test_comp():
    contents = u'''
{i: j for i, j in a}
'''
    if isinstance(contents, bytes):
        contents = contents.decode('utf-8')
    source_to_dict(contents)
Exemplo n.º 3
0
def test_dump_class():
    contents = u'''
class A:pass
'''
    if isinstance(contents, bytes):
        contents = contents.decode('utf-8')
    source_to_dict(contents)
Exemplo n.º 4
0
def test_global():
    contents = u'''
def method():
  global b
  b = 10
'''
    if isinstance(contents, bytes):
        contents = contents.decode('utf-8')
    source_to_dict(contents)
Exemplo n.º 5
0
def test_dump_ast_error():
    as_dict = source_to_dict(u"x = [a  10]")
    errors = as_dict['errors']
    assert len(errors) == 1
    error = errors[0]
    assert error['__node__'] == 'CompileError'
    assert error['line'] == 1
    assert error['col'] == 8
    assert 'Expected' in error['message_only']
Exemplo n.º 6
0
def test_dump_ast():
    data = source_to_dict(u"x = [a, 10]")
    assert not data['errors']
    assert data['ast']['stats'] == [{
        "__node__": "SingleAssignment",
        "rhs": {
            "__node__":
            "List",
            "line":
            1,
            "args": [{
                "__node__": "Name",
                "line": 1,
                "col": 5,
                "name": "a"
            }, {
                "is_c_literal": "None",
                "unsigned": "",
                "value": "10",
                "constant_result": "10",
                "__node__": "Int",
                "line": 1,
                "type": "long",
                "col": 8,
                "longness": ""
            }],
            "col":
            4
        },
        "lhs": {
            "__node__": "Name",
            "line": 1,
            "col": 0,
            "name": "x"
        },
        "line": 1,
        "col": 4
    }]