File: test_root.py

package info (click to toggle)
python-redbaron 0.9.2-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 772 kB
  • sloc: python: 6,650; makefile: 145; sh: 28
file content (56 lines) | stat: -rw-r--r-- 1,478 bytes parent folder | download
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
#!/usr/bin/python
# -*- coding:Utf-8 -*-

""" Tests the root method """

import pytest
# pylint: disable=redefined-outer-name
from redbaron import RedBaron


@pytest.fixture
def red():
    return RedBaron("""\
@deco
def a(c, d):
    b = c + d
""")


def test_root(red):
    nodes = [
        red.def_,
        red.def_.decorators,
        red.def_.decorators.node_list[0],
        red.def_.decorators.node_list[0].value,
        red.def_.decorators.node_list[0].value.value,
        red.def_.decorators.node_list[0].value.value[0],
        red.def_.decorators.node_list[1],
        red.def_.first_formatting,
        red.def_.first_formatting[0],
        red.def_.second_formatting,
        red.def_.third_formatting,
        red.def_.arguments,
        red.def_.arguments.node_list[0],
        red.def_.arguments.node_list[1],
        red.def_.arguments.node_list[2],
        red.def_.fourth_formatting,
        red.def_.fifth_formatting,
        red.def_.sixth_formatting,
        red.def_.value.node_list,
        red.def_.value.node_list[0],
        red.def_.value.node_list[1],
        red.def_.value.node_list[1].target,
        red.def_.value.node_list[1].value,
        red.def_.value.node_list[1].value.first,
        red.def_.value.node_list[1].value.second,
        red.def_.value.node_list[2]
    ]

    for node in nodes:
        assert red is node.root


def test_get_root():
    red = RedBaron("def a(b=c):\n    return 42")
    assert red is red.find("int").root