示例#1
0
def test_no_command():
    temp = utils.tempdir()
    src_path = temp / "src.sh"
    dest_path = temp / "dest.py"

    with open(src_path, "w") as src_f:
        src_f.write("# start\n")
        src_f.write("# description\n")
        src_f.write("end\n")

    bash_to_python(src_path, dest_path)

    with open(dest_path, "r") as dest_f:
        generated_cmd = dest_f.read()

    expected_cmd = "# start\n" "# description\n" "end\n"
    assert generated_cmd == expected_cmd
示例#2
0
def test_last_line_break():
    """Test that line endings are correct"""
    temp = utils.tempdir()
    src_path = temp / "src.sh"
    dest_path = temp / "dest.py"

    with open(src_path, "w") as src_f:
        src_f.write("# start\n")
        src_f.write("# end\n")

    bash_to_python(src_path, dest_path)

    with open(dest_path, "r") as dest_f:
        generated_cmd = dest_f.read()

    expected_cmd = "# start\n" "# end\n"

    assert generated_cmd == expected_cmd
示例#3
0
def test_bash_cmd():
    temp = utils.tempdir()
    src_path = temp / "src.sh"
    dest_path = temp / "dest.py"

    with open(src_path, "w") as src_f:
        src_f.write(BASH)
        src_f.write("\n")
        src_f.write("tvmc\n")
        src_f.write(BASH)
        src_f.write("\n")

    bash_to_python(src_path, dest_path)

    with open(dest_path, "r") as dest_f:
        generated_cmd = dest_f.read()

    expected_cmd = "# .. code-block:: bash\n" "#\n" "#\t  tvmc\n" "#\n"

    assert generated_cmd == expected_cmd
示例#4
0
def test_multiline_comment():
    temp = utils.tempdir()
    src_path = temp / "src.sh"
    dest_path = temp / "dest.py"

    with open(src_path, "w") as src_f:
        src_f.write(BASH_MULTILINE_COMMENT_START)
        src_f.write("\n")
        src_f.write("comment\n")
        src_f.write(BASH_MULTILINE_COMMENT_END)
        src_f.write("\n")

    bash_to_python(src_path, dest_path)

    with open(dest_path, "r") as dest_f:
        generated_cmd = dest_f.read()

    expected_cmd = '"""\n' "comment\n" '"""\n'

    assert generated_cmd == expected_cmd
示例#5
0
def test_bash_ignore_cmd():
    temp = utils.tempdir()
    src_path = temp / "src.sh"
    dest_path = temp / "dest.py"

    with open(src_path, "w") as src_f:
        src_f.write("# start\n")
        src_f.write(BASH_IGNORE)
        src_f.write("\n")
        src_f.write("tvmc\n")
        src_f.write(BASH_IGNORE)
        src_f.write("\n")
        src_f.write("# end\n")

    bash_to_python(src_path, dest_path)

    with open(dest_path, "r") as dest_f:
        generated_cmd = dest_f.read()

    expected_cmd = "# start\n" "# end\n"
    assert generated_cmd == expected_cmd
示例#6
0
def test_bash_ignore_cmd():
    """Test that ignored bash commands are not turned into code blocks"""
    temp = utils.tempdir()
    src_path = temp / "src.sh"
    dest_path = temp / "dest.py"

    with open(src_path, "w") as src_f:
        src_f.write("# start\n")
        src_f.write(BASH_IGNORE)
        src_f.write("\n")
        src_f.write("tvmc\n")
        src_f.write(BASH_IGNORE)
        src_f.write("\n")
        src_f.write("# end\n")

    bash_to_python(src_path, dest_path)

    with open(dest_path, "r") as dest_f:
        generated_cmd = dest_f.read()

    expected_cmd = "# start\n" "# end\n"
    assert generated_cmd == expected_cmd
示例#7
0
def test_text_and_bash_command():
    """Test a file with a bash code block"""
    temp = utils.tempdir()
    src_path = temp / "src.sh"
    dest_path = temp / "dest.py"

    with open(src_path, "w") as src_f:
        src_f.write("# start\n")
        src_f.write(BASH)
        src_f.write("\n")
        src_f.write("tvmc\n")
        src_f.write(BASH)
        src_f.write("\n")
        src_f.write("# end\n")

    bash_to_python(src_path, dest_path)

    with open(dest_path, "r") as dest_f:
        generated_cmd = dest_f.read()

    expected_cmd = "# start\n" "# .. code-block:: bash\n" "#\n" "#\t  tvmc\n" "#\n" "# end\n"

    assert generated_cmd == expected_cmd