コード例 #1
0
def test_dot_proxy_list_getslice():
    red = RedBaron("a.b.c.d")
    result = red[0].value[1:3]
    expected_result = DotProxyList(NodeList([red[0].value[1],
                                             red[0].value[2]]))
    assert len(result) == len(expected_result)
    assert result[0] == expected_result[0]
コード例 #2
0
def test_comma_proxy_list_getslice():
    red = RedBaron("[1, 2, 3, 4, 5, 6]")
    comma_proxy_list = red[0].value
    result = comma_proxy_list[1:2]
    expected_result = CommaProxyList(NodeList([comma_proxy_list[1]]))
    assert len(result) == len(expected_result)
    assert result[0] == expected_result[0]
コード例 #3
0
def test_decorator_line_proxy_list_getslice():
    red = RedBaron("@a\n@b\n@c\ndef a():\n    pass\n")
    result = red[0].decorators[1:3]
    expected_result = DecoratorsLineProxyList(
        NodeList([red[0].decorators[1], red[0].decorators[2]]))
    assert len(result) == len(expected_result)
    assert result[0] == expected_result[0]
コード例 #4
0
def test_line_proxy_list_getslice():
    red = RedBaron(
        "while a:\n    pass\n    caramba\n    compote\n    plop\n    z\n")
    result = red[0].value[1:3]
    expected_result = LineProxyList(
        NodeList([red[0].value[1], red[0].value[2]]))
    assert len(result) == len(expected_result)
    assert result[0] == expected_result[0]
コード例 #5
0
def test_map():
    red = RedBaron("[1, 2, 3]")
    assert red('int').map(lambda x: x.value) == NodeList(["1", "2", "3"])
コード例 #6
0
def test_root_as_line_proxy_list_getslice():
    red = RedBaron("\n\na\nb\nc\n")
    result = red[1:3]
    expected_result = LineProxyList(NodeList([red[1], red[2]]))
    assert len(result) == len(expected_result)
    assert result[0] == expected_result[0]
コード例 #7
0
def test_decrease_indentation_space_node():
    code = [SpaceNode({"type": "space", "value": "\n "}), node("# hello")]
    red = NodeList(code)
    red.decrease_indentation("  ")
    assert red.dumps() == "\n# hello"