コード例 #1
0
def test_is_in_context(example, output):
    from refactorlib.parse import parse

    lxmlnode = parse(example)

    top_level_directives = lxmlnode.xpath('/cheetah/*/*[1][self::Directive]')
    top_level_directives = [
        b'#' + d.name.encode('UTF-8') + b' ' + d.var.totext(with_tail=False)
        if d.var is not None else
        b'#' + d.name.encode('UTF-8')
        for d in top_level_directives
    ]

    # for each Placeholder, print if it's "in context" of each top-level
    # directive

    new_output = []
    for placeholder in lxmlnode.xpath('//Placeholder'):
        new_output.append(
            b'Placeholder: ' + placeholder.totext(with_tail=False)
        )
        for d in top_level_directives:
            new_output.append(
                b'    ' + d + b' ' +
                six.text_type(placeholder.is_in_context(d)).encode('UTF-8')
            )
        new_output.append(b'')

    new_output = b'\n'.join(new_output)
    assert_same_content(output, new_output)
コード例 #2
0
def test_is_in_context(example, output):
    from refactorlib.parse import parse

    lxmlnode = parse(example)

    top_level_directives = lxmlnode.xpath('/cheetah/*/*[1][self::Directive]')
    top_level_directives = [
        b'#' + d.name.encode('UTF-8') + b' ' +
        d.var.totext(with_tail=False) if d.var is not None else b'#' +
        d.name.encode('UTF-8') for d in top_level_directives
    ]

    # for each Placeholder, print if it's "in context" of each top-level
    # directive

    new_output = []
    for placeholder in lxmlnode.xpath('//Placeholder'):
        new_output.append(b'Placeholder: ' +
                          placeholder.totext(with_tail=False))
        for d in top_level_directives:
            new_output.append(
                b'    ' + d + b' ' +
                str(placeholder.is_in_context(d)).encode('UTF-8'))
        new_output.append(b'')

    new_output = b'\n'.join(new_output)
    assert_same_content(output, new_output)
コード例 #3
0
ファイル: xmlfrom.py プロジェクト: bukzor/RefactorLib
def xmlfrom(filename):
    from refactorlib.parse import parse
    from lxml.etree import tostring

    tree = parse(filename).getroottree()
    encoding = tree.docinfo.encoding
    return tostring(tree, encoding=encoding)
コード例 #4
0
def test_encoding_detection(example):
    from refactorlib.python.parse import detect_encoding
    text = open(example).read()
    example = parse(example)
    detected_encoding = detect_encoding(text)

    assert (example.encoding == detected_encoding
            or (example.encoding, detected_encoding) == ('UTF-8', None))
コード例 #5
0
ファイル: parse_test.py プロジェクト: bukzor/RefactorLib
def test_encoding_detection(example):
    from refactorlib.python.parse import detect_encoding
    text = open(example, 'rb').read()
    example = parse(example)
    detected_encoding = detect_encoding(text)

    assert (
        example.encoding == detected_encoding or
        (example.encoding, detected_encoding) == ('UTF-8', None)
    )
コード例 #6
0
def test_is_in_context(example, output):
    from refactorlib.parse import parse

    lxmlnode = parse(example)

    top_level_directives = lxmlnode.xpath('/cheetah/*/*[1][self::Directive]')
    top_level_directives = [
        "#%s %s" %
        (d.name, d.var.totext(with_tail=False)) if d.var else "#%s" % (d.name)
        for d in top_level_directives
    ]

    #for each Placeholder, print if it's "in context" of each top-level directive

    new_output = []
    for placeholder in lxmlnode.xpath('//Placeholder'):
        new_output.append('Placeholder: %s' %
                          placeholder.totext(with_tail=False))
        for d in top_level_directives:
            new_output.append('    %s %s' % (d, placeholder.is_in_context(d)))
        new_output.append('')

    new_output = '\n'.join(new_output)
    assert_same_content(output, new_output)
コード例 #7
0
def test_matches_known_good_parsing(example, output):
    example = parse(example).tostring()
    assert_same_content(output, example)
コード例 #8
0
def test_can_make_round_trip(example):
    text = open(example).read()
    example = parse(example)
    assert text == example.totext().decode('UTF-8')
コード例 #9
0
ファイル: parse_test.py プロジェクト: bukzor/RefactorLib
def test_can_make_round_trip(example):
    text = open(example, 'rb').read()
    example = parse(example)
    assert text == example.totext()
コード例 #10
0
ファイル: parse_test.py プロジェクト: bukzor/RefactorLib
def test_matches_known_good_parsing(example, output):
    example = parse(example).tostring()
    assert_same_content(output, example)
コード例 #11
0
#!/usr/bin/env python

from refactorlib.parse import parse

c = parse('simple.tmpl')

import pudb
pudb.set_trace()

for decorator in c.find_calls('foo'):
    print decorator.tostring()
    decorator.remove_self()

print c.totext()
コード例 #12
0
ファイル: parse_test.py プロジェクト: bukzor/RefactorLib
def test_can_make_round_trip(example):
    text = open(example, 'rb').read()
    example = parse(example)
    assert text == example.totext()
コード例 #13
0
ファイル: parse_test.py プロジェクト: bukzor/RefactorLib
def test_can_make_round_trip(example):
    text = open(example).read()
    example = parse(example)
    assert text == example.totext().decode('UTF-8')
コード例 #14
0
ファイル: test.py プロジェクト: campaul/RefactorLib
#!/usr/bin/env python

from refactorlib.parse import parse

c = parse('simple.tmpl')

import pudb; pudb.set_trace()

for decorator in c.find_calls('foo'):
	print decorator.tostring()
	decorator.remove_self()

print c.totext()