2016-06-05 14:32:59 -04:00
|
|
|
"""Xonsh AST tests."""
|
|
|
|
from xonsh import ast
|
2016-06-10 02:50:56 -04:00
|
|
|
from xonsh.ast import Tuple, Name, Store, min_line
|
|
|
|
|
2016-07-01 21:52:37 +03:00
|
|
|
import pytest
|
2016-06-10 02:50:56 -04:00
|
|
|
|
2016-07-01 21:52:37 +03:00
|
|
|
from tools import check_parse
|
2016-06-10 02:50:56 -04:00
|
|
|
|
2016-06-05 14:32:59 -04:00
|
|
|
|
2016-07-01 21:52:37 +03:00
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def xonsh_execer_autouse(xonsh_execer):
|
|
|
|
return xonsh_execer
|
2016-06-05 14:32:59 -04:00
|
|
|
|
|
|
|
def test_gather_names_name():
|
|
|
|
node = Name(id='y', ctx=Store())
|
|
|
|
exp = {'y'}
|
|
|
|
obs = ast.gather_names(node)
|
2016-06-22 17:12:33 -04:00
|
|
|
assert exp == obs
|
2016-06-05 14:32:59 -04:00
|
|
|
|
|
|
|
|
|
|
|
def test_gather_names_tuple():
|
|
|
|
node = Tuple(elts=[Name(id='y', ctx=Store()),
|
|
|
|
Name(id='z', ctx=Store())])
|
|
|
|
exp = {'y', 'z'}
|
|
|
|
obs = ast.gather_names(node)
|
2016-06-22 17:12:33 -04:00
|
|
|
assert exp == obs
|
2016-06-10 02:50:56 -04:00
|
|
|
|
|
|
|
def test_multilline_num():
|
|
|
|
code = ('x = 1\n'
|
|
|
|
'ls -l\n') # this second line wil be transformed
|
|
|
|
tree = check_parse(code)
|
|
|
|
lsnode = tree.body[1]
|
2016-06-22 17:12:33 -04:00
|
|
|
assert 2 == min_line(lsnode)
|