Example #1
0
def test_function_parameter_type_mismatch():
    try:
        code = ["def echo(msg):", "    return 1", 'echo(1)', 'a = echo("Hi")']
        analysis_code_list(code)
    except ParamTypeMismatchError:
        assert True
    else:
        assert False
Example #2
0
def test_simple_import():
    code = [
        'import os',
    ]

    try:
        analysis_code_list(code)
    except ImportError:
        assert True
    else:
        assert False
Example #3
0
def test_simple_from_import():
    code = [
        'from os.path import join',
    ]

    try:
        analysis_code_list(code)
    except ImportError:
        assert True
    else:
        assert False
Example #4
0
def test_simple_from_import():
    code = [
        'from os.path import join',
    ]

    try:
        analysis_code_list(code)
    except ImportError:
        assert True
    else:
        assert False
Example #5
0
def test_simple_import():
    code = [
        'import os',
    ]

    try:
        analysis_code_list(code)
    except ImportError:
        assert True
    else:
        assert False
Example #6
0
def test_function_parameter_type_mismatch():
    try:
        code = [
            "def echo(msg):",
            "    return 1",
            'echo(1)',
            'a = echo("Hi")'
        ]
        analysis_code_list(code)
    except ParamTypeMismatchError:
        assert True
    else:
        assert False
Example #7
0
def test_number_le_op():
    code = [
        'a = 10',
        'a != 10',
    ]

    assert analysis_code_list(code) == """export a=10
Example #8
0
def test_function_call_in_parameter():
    code = [
        "test1(echo('Hi'))",
        "test2(echo('Hi'))",
        "test3(echo('Hi'))",
    ]
    assert analysis_code_list(code) == """echo "Hi"
Example #9
0
def test_function_return_type_anlyzer():
    code = [
        'def echo(msg):',
        '    return 1',
        'a = echo("Hi")'
    ]
    assert analysis_code_list(code) == """function echo() {
Example #10
0
def test_complex_numeric_operation_with_function_call():
    code = [
        'def a():',
        '    return 1',
        'c = 3 - a()',
    ]
    assert analysis_code_list(code) == """function a() {
Example #11
0
def test_simple_numeric_operation_with_function_call():
    code = [
        'def a():',
        '    return 1',
        'b = a() + 3',
    ]
    assert analysis_code_list(code) == """function a() {
Example #12
0
def test_command():
    code = [
        'from sherlock.cmd import ls',
        'ls("-al")'
    ]

    assert analysis_code_list(code) == """if ! type "ls" &> /dev/null ; then
Example #13
0
def test_number_le_op():
    code = [
        'a = 10',
        'a != 10',
    ]

    assert analysis_code_list(code) == """export a=10
Example #14
0
def test_simple_numeric_operation_with_function_call():
    code = [
        'def a():',
        '    return 1',
        'b = a() + 3',
    ]
    assert analysis_code_list(code) == """function a() {
Example #15
0
def test_complex_numeric_operation_with_function_call():
    code = [
        'def a():',
        '    return 1',
        'c = 3 - a()',
    ]
    assert analysis_code_list(code) == """function a() {
Example #16
0
def test_function_call_in_parameter():
    code = [
        "test1(echo('Hi'))",
        "test2(echo('Hi'))",
        "test3(echo('Hi'))",
    ]
    assert analysis_code_list(code) == """echo "Hi"
Example #17
0
def test_string_not_equal_op():
    code = [
        'a = "10"',
        'if a != "10":',
        '   pass'
    ]

    assert analysis_code_list(code) == """export a="10"
Example #18
0
def test_string_is_op():
    code = [
        'a = "10"',
        'if a is "10":',
        '   pass'
    ]

    assert analysis_code_list(code) == """export a="10"
Example #19
0
def test_simple_if_statement():
    code = [
        'a = 10',
        'if a == 10:',
        '   echo("Hi")',
    ]

    assert analysis_code_list(code) == """export a=10
Example #20
0
def test_simple_if_statement():
    code = [
        'a = 10',
        'if a == 10:',
        '   echo("Hi")',
    ]

    assert analysis_code_list(code) == """export a=10
Example #21
0
def test_simple_while_statement():
    code = [
        'i = 0',
        'while i < 5:',
        '   echo(i)',
        '   i += 1'
    ]

    assert analysis_code_list(code) == """export i=0
Example #22
0
def test_list_parameter():
    code = [
        'def test(a, b):',
        '   echo(a)',
        '   echo(b)',
        'a = ["1", "2"]',
        'b = 10',
        'test(a, b)',
    ]

    assert analysis_code_list(code) == """function test() {
def test_complex_numeric_operation():
    code = [
        'a = 2 + (3 - 4) * 6 / 2',
    ]
    assert analysis_code_list(
        code) == 'export a=$(( 2 + $(( $(( $(( 3 - 4 )) * 6 )) / 2 )) ))\n'
def test_simple_add_numbers_anlyzer():
    code = [
        'a = 2 + 3',
    ]
    assert analysis_code_list(code) == 'export a=$(( 2 + 3 ))\n'
Example #25
0
def test_function_return_type_anlyzer():
    code = ['def echo(msg):', '    return 1', 'a = echo("Hi")']
    assert analysis_code_list(code) == """function echo() {
def test_aug_assign_operation():
    code = [
        'a = 1',
        'a += 1',
    ]
    assert analysis_code_list(code) == """export a=1
def test_run_command_line_command():
    code = [
        'git("commit", "-m", "Hello")',
    ]
    assert analysis_code_list(code) == 'git "commit" "-m" "Hello"\n'
def test_add_string_variable_and_number():
    code = [
        'b = "Hello"',
        'a = 2 + b',
    ]
    assert analysis_code_list(code) == """export b="Hello"
Example #29
0
def test_string_is_op():
    code = ['a = "10"', 'if a is "10":', '   pass']

    assert analysis_code_list(code) == """export a="10"
def test_simple_add_string_and_number_anlyzer():
    code = [
        'a = 2 + "Hello"',
    ]
    assert analysis_code_list(code) == 'export a=2"Hello"\n'
def test_print():
    code = [
        'print("Hello World")',
    ]
    assert analysis_code_list(code) == 'echo "Hello World"\n'
Example #32
0
def test_simple_for_statement():
    code = ['for i in range(1, 5):', '   pass']
    assert analysis_code_list(code) == """for i in $(seq 1 $(( 5 - 1 )))
Example #33
0
def test_complex_numeric_operation():
    code = [
        'a = 2 + (3 - 4) * 6 / 2',
    ]
    assert analysis_code_list(code) == 'export a=$(( 2 + $(( $(( $(( 3 - 4 )) * 6 )) / 2 )) ))\n'
Example #34
0
def test_simple_add_string_and_number_anlyzer():
    code = [
        'a = 2 + "Hello"',
    ]
    assert analysis_code_list(code) == 'export a=2"Hello"\n'
def test_range():
    code = [
        'range(1, 2)',
    ]
    assert analysis_code_list(code) == '$(seq 1 $(( 2 - 1 )))\n'
Example #36
0
def test_string_not_equal_op():
    code = ['a = "10"', 'if a != "10":', '   pass']

    assert analysis_code_list(code) == """export a="10"
Example #37
0
def test_range():
    code = [
        'range(1, 2)',
    ]
    assert analysis_code_list(code) == '$(seq 1 $(( 2 - 1 )))\n'
Example #38
0
def test_command():
    code = ['from sherlock.cmd import ls', 'ls("-al")']

    assert analysis_code_list(code) == """if ! type "ls" &> /dev/null ; then
Example #39
0
def test_simple_add_numbers_anlyzer():
    code = [
        'a = 2 + 3',
    ]
    assert analysis_code_list(code) == 'export a=$(( 2 + 3 ))\n'
Example #40
0
def test_aug_assign_operation():
    code = [
        'a = 1',
        'a += 1',
    ]
    assert analysis_code_list(code) == """export a=1
Example #41
0
def test_simple_for_statement():
    code = [
        'for i in range(1, 5):',
        '   pass'
    ]
    assert analysis_code_list(code) == """for i in $(seq 1 $(( 5 - 1 )))
Example #42
0
def test_simple_while_statement():
    code = ['i = 0', 'while i < 5:', '   echo(i)', '   i += 1']

    assert analysis_code_list(code) == """export i=0
Example #43
0
def test_run_command_line_command():
    code = [
        'git("commit", "-m", "Hello")',
    ]
    assert analysis_code_list(code) == 'git "commit" "-m" "Hello"\n'
Example #44
0
def test_print():
    code = [
        'print("Hello World")',
    ]
    assert analysis_code_list(code) == 'echo "Hello World"\n'
def test_complex_add():
    code = [
        'a = 2 + (3 + 4) + 6',
    ]
    assert analysis_code_list(
        code) == 'export a=$(( $(( 2 + $(( 3 + 4 )) )) + 6 ))\n'
Example #46
0
def test_mix_list_assign():
    code = [
        'a = ["1", "2", 1, 2]'
    ]

    assert analysis_code_list(code) == 'export a=("1" "2" 1 2)\n'
Example #47
0
def test_add_string_variable_and_number():
    code = [
        'b = "Hello"',
        'a = 2 + b',
    ]
    assert analysis_code_list(code) == """export b="Hello"
Example #48
0
def test_numeric_list_assign():
    code = [
        'a = [1, 2, 3, 4]'
    ]

    assert analysis_code_list(code) == 'export a=(1 2 3 4)\n'
Example #49
0
def test_complex_add():
    code = [
        'a = 2 + (3 + 4) + 6',
    ]
    assert analysis_code_list(code) == 'export a=$(( $(( 2 + $(( 3 + 4 )) )) + 6 ))\n'