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
|
#!/usr/bin/python
# -*- coding:Utf-8 -*-
""" Tests the position feature """
import pytest
import redbaron
# pylint: disable=redefined-outer-name
from redbaron import RedBaron, Path
redbaron.DEBUG = True
fst = RedBaron("""\
@deco
def a(c, d):
b = c + d
e = 1
""")
positions = [
(fst.def_.decorators[0], [(1, 1)]),
(fst.def_.decorators[0].value.value[0], [(1, 2), (1, 3), (1, 4), (1, 5)]),
# How to get this one ? (2, 0) and (2, 1) does not work, see out of scope
#(fst.def_.decorators[1], [(?, ?)]),
(fst.def_, [(3, 1), (3, 2), (3, 3)]),
(fst.def_.first_formatting[0], [(3, 4)]),
(fst.def_, [(3, 5), (3, 6)]),
(fst.def_.arguments.node_list[0].target, [(3, 7)]),
(fst.def_.arguments.node_list[1], [(3, 8)]),
(fst.def_.arguments.node_list[1].second_formatting[0], [(3, 9)]),
(fst.def_.arguments.node_list[2].target, [(3, 10)]),
(fst.def_, [(3, 11), (3, 12)]),
(fst.def_.value.node_list[0], [(4, 1), (4, 2), (4, 3), (4, 4)]),
(fst.def_.value.node_list[1].target, [(4, 5)]),
(fst.def_.value.node_list[1].first_formatting[0], [(4, 6)]),
(fst.def_.value.node_list[1], [(4, 7)]),
(fst.def_.value.node_list[1].second_formatting[0], [(4, 8)]),
(fst.def_.value.node_list[1].value.first, [(4, 9)]),
(fst.def_.value.node_list[1].value.first_formatting[0], [(4, 10)]),
(fst.def_.value.node_list[1].value, [(4, 11)]),
(fst.def_.value.node_list[1].value.second_formatting[0], [(4, 12)]),
(fst.def_.value.node_list[1].value.second, [(4, 13)]),
(fst.def_.value.node_list[2], [(5, 1), (5, 2), (5, 3), (5, 4)]),
(fst.def_.value.node_list[3].target, [(5, 5)]),
(fst.def_.value.node_list[3].first_formatting[0], [(5, 6)]),
(fst.def_.value.node_list[3], [(5, 7)]),
(fst.def_.value.node_list[3].second_formatting[0], [(5, 8)]),
(fst.def_.value.node_list[3].value, [(5, 9)]),
# out of scope
(fst, [(2, 0), (2, 1)]),
]
@pytest.fixture(params=positions)
def position_fixture(request):
return request.param
def test_find_by_position(position_fixture):
node, positions = position_fixture
for position in positions:
assert node == fst.find_by_position(position)
def test_path_str():
red = RedBaron("name")
assert str(Path(red[0]))
|