Example #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)
Example #2
0
def test_echo_hello():
    assert check_parse('echo hello')
Example #3
0
def test_indent_with_empty_line():
    code = "if True:\n" "\n" "    some_command for_sub_process_mode\n"
    assert check_parse(code)
Example #4
0
def test_lookup_anon_alias():
    code = 'echo "hi" | @(lambda a, s=None: a[0]) foo bar baz\n'
    assert check_parse(code)
Example #5
0
def test_which_ls():
    assert check_parse("which ls")
Example #6
0
def test_echo_comma_2val():
    code = "echo 1,2\n"
    assert check_parse(code)
Example #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)
Example #8
0
def test_good_rhs_subproc():
    # nonsense but parsebale
    code = 'str().split() | ![grep exit]\n'
    check_parse(code)
Example #9
0
def test_command_in_func_with_comment():
    code = "def f():\n" "    echo hello # comment\n"
    assert check_parse(code)
Example #10
0
def test_command_in_func_with_comment():
    code = ('def f():\n' '    echo hello # comment\n')
    assert check_parse(code)
Example #11
0
def test_command_in_func():
    code = ('def f():\n' '    echo hello\n')
    assert check_parse(code)
Example #12
0
def test_indent_with_empty_line():
    code = ('if True:\n' '\n' '    some_command for_sub_process_mode\n')
    assert check_parse(code)
Example #13
0
def test_bad_indent():
    code = ('if True:\n' 'x = 1\n')
    with pytest.raises(SyntaxError):
        check_parse(code)
Example #14
0
def test_lookup_alias():
    code = ('def foo(a,  s=None):\n' '    return "bar"\n' '@(foo)\n')
    assert check_parse(code)
Example #15
0
def test_simple_func():
    code = ('def prompt():\n' "    return '{user}'.format(user='******')\n")
    assert check_parse(code)
Example #16
0
def test_indent_with_empty_line():
    code = ('if True:\n'
            '\n'
            '    some_command for_sub_process_mode\n')
    assert check_parse(code)
Example #17
0
def test_command_in_func_with_comment():
    code = ('def f():\n'
            '    echo hello # comment\n')
    assert check_parse(code)
Example #18
0
def test_pyeval_redirect():
    code = 'echo @("foo") > bar\n'
    assert check_parse(code)
Example #19
0
def test_pyeval_multiline_str():
    code = 'echo @("""hello\nmom""")\n'
    assert check_parse(code)
Example #20
0
def test_echo_comma():
    code = "echo ,\n"
    assert check_parse(code)
Example #21
0
def test_echo_comma():
    code = "echo ,\n"
    assert check_parse(code)
Example #22
0
def test_echo_comma_val():
    code = "echo ,1\n"
    assert check_parse(code)
Example #23
0
def test_two_echo_line_cont(code):
    assert check_parse(code)
Example #24
0
def test_echo_comma_2val():
    code = "echo 1,2\n"
    assert check_parse(code)
Example #25
0
def test_echo_star_with_semi():
    assert check_parse("echo * spam ; ![echo eggs]\n")
Example #26
0
def test_echo_line_cont():
    code = 'echo "1 \\\n2"\n'
    assert check_parse(code)
Example #27
0
def test_bad_indent():
    code = "if True:\n" "x = 1\n"
    with pytest.raises(SyntaxError):
        check_parse(code)
Example #28
0
def test_two_echo_line_cont(code):
    assert check_parse(code)
Example #29
0
def test_command_in_func_with_comment():
    code = "def f():\n" "    echo hello # comment\n"
    assert check_parse(code)
Example #30
0
def test_ls_dashl():
    assert check_parse("ls -l")
Example #31
0
def test_bad_indent():
    code = ('if True:\n'
            'x = 1\n')
    with pytest.raises(SyntaxError):
        check_parse(code)
Example #32
0
def test_which_ls():
    assert check_parse("which ls")
Example #33
0
def test_command_in_func():
    code = ('def f():\n'
            '    echo hello\n')
    assert check_parse(code)
Example #34
0
def test_echo_hello():
    assert check_parse("echo hello")
Example #35
0
def test_echo_comma():
    code = 'echo ,\n'
    assert check_parse(code)
Example #36
0
def test_echo_star_with_semi():
    assert check_parse("echo * spam ; ![echo eggs]\n")
Example #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)
Example #38
0
def test_lookup_alias():
    code = "def foo(a,  s=None):\n" '    return "bar"\n' "@(foo)\n"
    assert check_parse(code)
Example #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)
Example #40
0
def test_lookup_anon_alias():
    code = 'echo "hi" | @(lambda a, s=None: a[0]) foo bar baz\n'
    assert check_parse(code)
Example #41
0
def test_pyeval_multiline_str():
    code = 'echo @("""hello\nmom""")\n'
    assert check_parse(code)
Example #42
0
def test_simple_func_broken():
    code = "def prompt():\n" "    return '{user}'.format(\n" "       user='******')\n"
    assert check_parse(code)
Example #43
0
def test_echo_comma_val():
    code = "echo ,1\n"
    assert check_parse(code)
Example #44
0
def test_bad_indent():
    code = "if True:\n" "x = 1\n"
    with pytest.raises(SyntaxError):
        check_parse(code)
Example #45
0
def test_echo_line_cont():
    code = 'echo "1 \\\n2"\n'
    assert check_parse(code)
Example #46
0
def test_bad_rhs_subproc():
    # nonsense but unparsable
    code = "str().split() | grep exit\n"
    with pytest.raises(SyntaxError):
        check_parse(code)
Example #47
0
def test_ls_dashl():
    assert check_parse("ls -l")
Example #48
0
def test_indent_with_empty_line():
    code = "if True:\n" "\n" "    some_command for_sub_process_mode\n"
    assert check_parse(code)
Example #49
0
def test_echo_hello():
    assert check_parse("echo hello")
Example #50
0
def test_command_in_func():
    code = "def f():\n" "    echo hello\n"
    assert check_parse(code)
Example #51
0
def test_lookup_alias():
    code = "def foo(a,  s=None):\n" '    return "bar"\n' "@(foo)\n"
    assert check_parse(code)
Example #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)
Example #53
0
def test_simple_func_broken():
    code = "def prompt():\n" "    return '{user}'.format(\n" "       user='******')\n"
    assert check_parse(code)
Example #54
0
def test_good_rhs_subproc():
    # nonsense but parsebale
    code = 'str().split() | ![grep exit]\n'
    check_parse(code)
Example #55
0
def test_bad_rhs_subproc():
    # nonsense but unparsable
    code = "str().split() | grep exit\n"
    with pytest.raises(SyntaxError):
        check_parse(code)
Example #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)
Example #57
0
def test_command_in_func():
    code = "def f():\n" "    echo hello\n"
    assert check_parse(code)
Example #58
0
def test_lookup_alias():
    code = (
        'def foo(a,  s=None):\n'
        '    return "bar"\n'
        '@(foo)\n')
    assert check_parse(code)
Example #59
0
def test_pyeval_redirect():
    code = 'echo @("foo") > bar\n'
    assert check_parse(code)
Example #60
0
def test_which_ls():
    assert check_parse('which ls')