Esempio n. 1
0
def test_inject_before():
    '''Test that inject_before injects code on the line before the node.'''
    q = project_query(TEST_PROJECT_PATH).flatten().assignments()

    node_at_start = q.path_contains('ONE_LINER')[0]

    change = node_at_start.change.inject_before('foobar = "baz"\n')
    assert_in("+foobar = \"baz\"\n ONE_LINER = 'foobar'", str(change))

    node_at_end = q.path_contains('BASE_PAY')[0]
    change = node_at_end.change.inject_before('foobar = "baz"\n')
    assert_in("+foobar = \"baz\"\n BASE_PAY = 100", str(change))
Esempio n. 2
0
def test_change_value():
    '''Test that we can take a AssignmentNode and overwrite its current body with
    code generated from a new python value.'''

    q = project_query(TEST_PROJECT_PATH)

    setting_node = q.flatten().assignments().path_contains('MULTILINE_SETTING')[0]

    change = setting_node.change.value(42)
    assert_equal(change.new_text, '42')

    change = setting_node.change.value([42])
    assert_equal(change.new_text, '[\n    42\n]')
Esempio n. 3
0
def test_change_value():
    '''Test that we can take a AssignmentNode and overwrite its current body with
    code generated from a new python value.'''

    q = project_query(TEST_PROJECT_PATH)

    setting_node = q.flatten().assignments().path_contains(
        'MULTILINE_SETTING')[0]

    change = setting_node.change.value(42)
    assert_equal(change.new_text, '42')

    change = setting_node.change.value([42])
    assert_equal(change.new_text, '[\n    42\n]')
Esempio n. 4
0
def test_inject_before():
    '''Test that inject_before injects code on the line before the node.'''
    q = project_query(TEST_PROJECT_PATH).flatten().assignments()

    node_at_start = q.path_contains('ONE_LINER')[0]

    change = node_at_start.change.inject_before('foobar = "baz"\n')
    assert_in(
        "+foobar = \"baz\"\n ONE_LINER = 'foobar'",
        str(change))

    node_at_end = q.path_contains('BASE_PAY')[0]
    change = node_at_end.change.inject_before('foobar = "baz"\n')
    assert_in(
        "+foobar = \"baz\"\n BASE_PAY = 100",
        str(change))