Beispiel #1
0
def test_multilline_no_transform():
    # no subprocess transformations happen here since all variables are known
    code = 'ls = 1\nl = 1\nls -l\n'
    tree = check_parse(code)
    lsnode = tree.body[2]
    assert 3 == min_line(lsnode)
    assert isinstance(lsnode.value, BinOp)
Beispiel #2
0
def test_echo_hello():
    assert check_parse('echo hello')
Beispiel #3
0
def test_indent_with_empty_line():
    code = "if True:\n" "\n" "    some_command for_sub_process_mode\n"
    assert check_parse(code)
Beispiel #4
0
def test_lookup_anon_alias():
    code = 'echo "hi" | @(lambda a, s=None: a[0]) foo bar baz\n'
    assert check_parse(code)
Beispiel #5
0
def test_which_ls():
    assert check_parse("which ls")
Beispiel #6
0
def test_echo_comma_2val():
    code = "echo 1,2\n"
    assert check_parse(code)
Beispiel #7
0
def test_multilline_num():
    code = ('x = 1\n'
            'ls -l\n')  # this second line wil be transformed
    tree = check_parse(code)
    lsnode = tree.body[1]
    assert 2 == min_line(lsnode)
Beispiel #8
0
def test_good_rhs_subproc():
    # nonsense but parsebale
    code = 'str().split() | ![grep exit]\n'
    check_parse(code)
Beispiel #9
0
def test_command_in_func_with_comment():
    code = "def f():\n" "    echo hello # comment\n"
    assert check_parse(code)
Beispiel #10
0
def test_command_in_func_with_comment():
    code = ('def f():\n' '    echo hello # comment\n')
    assert check_parse(code)
Beispiel #11
0
def test_command_in_func():
    code = ('def f():\n' '    echo hello\n')
    assert check_parse(code)
Beispiel #12
0
def test_indent_with_empty_line():
    code = ('if True:\n' '\n' '    some_command for_sub_process_mode\n')
    assert check_parse(code)
Beispiel #13
0
def test_bad_indent():
    code = ('if True:\n' 'x = 1\n')
    with pytest.raises(SyntaxError):
        check_parse(code)
Beispiel #14
0
def test_lookup_alias():
    code = ('def foo(a,  s=None):\n' '    return "bar"\n' '@(foo)\n')
    assert check_parse(code)
Beispiel #15
0
def test_simple_func():
    code = ('def prompt():\n' "    return '{user}'.format(user='******')\n")
    assert check_parse(code)
Beispiel #16
0
def test_indent_with_empty_line():
    code = ('if True:\n'
            '\n'
            '    some_command for_sub_process_mode\n')
    assert check_parse(code)
Beispiel #17
0
def test_command_in_func_with_comment():
    code = ('def f():\n'
            '    echo hello # comment\n')
    assert check_parse(code)
Beispiel #18
0
def test_pyeval_redirect():
    code = 'echo @("foo") > bar\n'
    assert check_parse(code)
Beispiel #19
0
def test_pyeval_multiline_str():
    code = 'echo @("""hello\nmom""")\n'
    assert check_parse(code)
Beispiel #20
0
def test_echo_comma():
    code = "echo ,\n"
    assert check_parse(code)
Beispiel #21
0
def test_echo_comma():
    code = "echo ,\n"
    assert check_parse(code)
Beispiel #22
0
def test_echo_comma_val():
    code = "echo ,1\n"
    assert check_parse(code)
Beispiel #23
0
def test_two_echo_line_cont(code):
    assert check_parse(code)
Beispiel #24
0
def test_echo_comma_2val():
    code = "echo 1,2\n"
    assert check_parse(code)
Beispiel #25
0
def test_echo_star_with_semi():
    assert check_parse("echo * spam ; ![echo eggs]\n")
Beispiel #26
0
def test_echo_line_cont():
    code = 'echo "1 \\\n2"\n'
    assert check_parse(code)
Beispiel #27
0
def test_bad_indent():
    code = "if True:\n" "x = 1\n"
    with pytest.raises(SyntaxError):
        check_parse(code)
Beispiel #28
0
def test_two_echo_line_cont(code):
    assert check_parse(code)
Beispiel #29
0
def test_command_in_func_with_comment():
    code = "def f():\n" "    echo hello # comment\n"
    assert check_parse(code)
Beispiel #30
0
def test_ls_dashl():
    assert check_parse("ls -l")
Beispiel #31
0
def test_bad_indent():
    code = ('if True:\n'
            'x = 1\n')
    with pytest.raises(SyntaxError):
        check_parse(code)
Beispiel #32
0
def test_which_ls():
    assert check_parse("which ls")
Beispiel #33
0
def test_command_in_func():
    code = ('def f():\n'
            '    echo hello\n')
    assert check_parse(code)
Beispiel #34
0
def test_echo_hello():
    assert check_parse("echo hello")
Beispiel #35
0
def test_echo_comma():
    code = 'echo ,\n'
    assert check_parse(code)
Beispiel #36
0
def test_echo_star_with_semi():
    assert check_parse("echo * spam ; ![echo eggs]\n")
Beispiel #37
0
def test_multilline_num(line1):
    code = line1 + '\nls -l\n'
    tree = check_parse(code)
    lsnode = tree.body[1]
    assert 2 == min_line(lsnode)
    assert isinstance(lsnode.value, Call)
Beispiel #38
0
def test_lookup_alias():
    code = "def foo(a,  s=None):\n" '    return "bar"\n' "@(foo)\n"
    assert check_parse(code)
Beispiel #39
0
def test_args_in_scope(inp):
    # Context sensitive parsing should not modify AST
    exp = pyast.parse(inp)
    obs = check_parse(inp)
    assert nodes_equal(exp, obs)
Beispiel #40
0
def test_lookup_anon_alias():
    code = 'echo "hi" | @(lambda a, s=None: a[0]) foo bar baz\n'
    assert check_parse(code)
Beispiel #41
0
def test_pyeval_multiline_str():
    code = 'echo @("""hello\nmom""")\n'
    assert check_parse(code)
Beispiel #42
0
def test_simple_func_broken():
    code = "def prompt():\n" "    return '{user}'.format(\n" "       user='******')\n"
    assert check_parse(code)
Beispiel #43
0
def test_echo_comma_val():
    code = "echo ,1\n"
    assert check_parse(code)
Beispiel #44
0
def test_bad_indent():
    code = "if True:\n" "x = 1\n"
    with pytest.raises(SyntaxError):
        check_parse(code)
Beispiel #45
0
def test_echo_line_cont():
    code = 'echo "1 \\\n2"\n'
    assert check_parse(code)
Beispiel #46
0
def test_bad_rhs_subproc():
    # nonsense but unparsable
    code = "str().split() | grep exit\n"
    with pytest.raises(SyntaxError):
        check_parse(code)
Beispiel #47
0
def test_ls_dashl():
    assert check_parse("ls -l")
Beispiel #48
0
def test_indent_with_empty_line():
    code = "if True:\n" "\n" "    some_command for_sub_process_mode\n"
    assert check_parse(code)
Beispiel #49
0
def test_echo_hello():
    assert check_parse("echo hello")
Beispiel #50
0
def test_command_in_func():
    code = "def f():\n" "    echo hello\n"
    assert check_parse(code)
Beispiel #51
0
def test_lookup_alias():
    code = "def foo(a,  s=None):\n" '    return "bar"\n' "@(foo)\n"
    assert check_parse(code)
Beispiel #52
0
def test_multilline_num():
    code = ('x = 1\n' 'ls -l\n')  # this second line wil be transformed
    tree = check_parse(code)
    lsnode = tree.body[1]
    assert 2 == min_line(lsnode)
Beispiel #53
0
def test_simple_func_broken():
    code = "def prompt():\n" "    return '{user}'.format(\n" "       user='******')\n"
    assert check_parse(code)
Beispiel #54
0
def test_good_rhs_subproc():
    # nonsense but parsebale
    code = 'str().split() | ![grep exit]\n'
    check_parse(code)
Beispiel #55
0
def test_bad_rhs_subproc():
    # nonsense but unparsable
    code = "str().split() | grep exit\n"
    with pytest.raises(SyntaxError):
        check_parse(code)
Beispiel #56
0
def test_multilline_num(line1):
    code = line1 + '\nls -l\n'
    tree = check_parse(code)
    lsnode = tree.body[1]
    assert 2 == min_line(lsnode)
    assert isinstance(lsnode.value, Call)
Beispiel #57
0
def test_command_in_func():
    code = "def f():\n" "    echo hello\n"
    assert check_parse(code)
Beispiel #58
0
def test_lookup_alias():
    code = (
        'def foo(a,  s=None):\n'
        '    return "bar"\n'
        '@(foo)\n')
    assert check_parse(code)
Beispiel #59
0
def test_pyeval_redirect():
    code = 'echo @("foo") > bar\n'
    assert check_parse(code)
Beispiel #60
0
def test_which_ls():
    assert check_parse('which ls')