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)
def test_echo_hello(): assert check_parse('echo hello')
def test_indent_with_empty_line(): code = "if True:\n" "\n" " some_command for_sub_process_mode\n" assert check_parse(code)
def test_lookup_anon_alias(): code = 'echo "hi" | @(lambda a, s=None: a[0]) foo bar baz\n' assert check_parse(code)
def test_which_ls(): assert check_parse("which ls")
def test_echo_comma_2val(): code = "echo 1,2\n" assert check_parse(code)
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)
def test_good_rhs_subproc(): # nonsense but parsebale code = 'str().split() | ![grep exit]\n' check_parse(code)
def test_command_in_func_with_comment(): code = "def f():\n" " echo hello # comment\n" assert check_parse(code)
def test_command_in_func_with_comment(): code = ('def f():\n' ' echo hello # comment\n') assert check_parse(code)
def test_command_in_func(): code = ('def f():\n' ' echo hello\n') assert check_parse(code)
def test_indent_with_empty_line(): code = ('if True:\n' '\n' ' some_command for_sub_process_mode\n') assert check_parse(code)
def test_bad_indent(): code = ('if True:\n' 'x = 1\n') with pytest.raises(SyntaxError): check_parse(code)
def test_lookup_alias(): code = ('def foo(a, s=None):\n' ' return "bar"\n' '@(foo)\n') assert check_parse(code)
def test_simple_func(): code = ('def prompt():\n' " return '{user}'.format(user='******')\n") assert check_parse(code)
def test_pyeval_redirect(): code = 'echo @("foo") > bar\n' assert check_parse(code)
def test_pyeval_multiline_str(): code = 'echo @("""hello\nmom""")\n' assert check_parse(code)
def test_echo_comma(): code = "echo ,\n" assert check_parse(code)
def test_echo_comma_val(): code = "echo ,1\n" assert check_parse(code)
def test_two_echo_line_cont(code): assert check_parse(code)
def test_echo_star_with_semi(): assert check_parse("echo * spam ; ![echo eggs]\n")
def test_echo_line_cont(): code = 'echo "1 \\\n2"\n' assert check_parse(code)
def test_bad_indent(): code = "if True:\n" "x = 1\n" with pytest.raises(SyntaxError): check_parse(code)
def test_ls_dashl(): assert check_parse("ls -l")
def test_echo_hello(): assert check_parse("echo hello")
def test_echo_comma(): code = 'echo ,\n' assert check_parse(code)
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)
def test_lookup_alias(): code = "def foo(a, s=None):\n" ' return "bar"\n' "@(foo)\n" assert check_parse(code)
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)
def test_simple_func_broken(): code = "def prompt():\n" " return '{user}'.format(\n" " user='******')\n" assert check_parse(code)
def test_bad_rhs_subproc(): # nonsense but unparsable code = "str().split() | grep exit\n" with pytest.raises(SyntaxError): check_parse(code)
def test_command_in_func(): code = "def f():\n" " echo hello\n" assert check_parse(code)
def test_lookup_alias(): code = ( 'def foo(a, s=None):\n' ' return "bar"\n' '@(foo)\n') assert check_parse(code)
def test_which_ls(): assert check_parse('which ls')