Exemplo n.º 1
0
def test_sub_param_and_return(tmp_path):
    tmp_file_1 = tmp_path / "test1.scriic"
    tmp_file_1.write_text(
        """
        HOWTO Test scriic
        val = SUB ./test2.scriic
        PRM param = ABC
        GO
        DO Subscriic returned [val]
        """
    )

    tmp_file_2 = tmp_path / "test2.scriic"
    tmp_file_2.write_text(
        """
        HOWTO Test subscriic with <param>
        DO Received [param]
        RETURN DEF
        """
    )

    runner = FileRunner(tmp_file_1.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 2
    assert instruction.children[0].text() == "Test subscriic with ABC"
    assert len(instruction.children[0].children) == 1
    assert instruction.children[0].children[0].text() == "Received ABC"
    assert instruction.children[1].text() == "Subscriic returned DEF"
Exemplo n.º 2
0
def test_sub(tmp_path):
    tmp_file_1 = tmp_path / "test1.scriic"
    tmp_file_1.write_text(
        """
        HOWTO Test scriic
        DO This is in file 1
        SUB ./test2.scriic
        """
    )

    tmp_file_2 = tmp_path / "test2.scriic"
    tmp_file_2.write_text(
        """
        HOWTO Test subscriic
        DO This is in file 2
        """
    )

    runner = FileRunner(tmp_file_1.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 2
    assert instruction.children[0].text() == "This is in file 1"
    assert instruction.children[1].text() == "Test subscriic"
    assert len(instruction.children[1].children) == 1
    assert instruction.children[1].children[0].text() == "This is in file 2"
Exemplo n.º 3
0
def test_sub_return(tmp_path):
    tmp_file_1 = tmp_path / "test1.scriic"
    tmp_file_1.write_text(
        """
        HOWTO Test scriic
        val = SUB ./test2.scriic
        DO Subscriic returned [val]
        """
    )

    tmp_file_2 = tmp_path / "test2.scriic"
    tmp_file_2.write_text(
        """
        HOWTO Test subscriic
        RETURN ABC
        """
    )

    runner = FileRunner(tmp_file_1.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 2
    assert instruction.children[0].text() == "Test subscriic"
    assert len(instruction.children[0].children) == 0
    assert instruction.children[1].text() == "Subscriic returned ABC"
Exemplo n.º 4
0
def test_sub_param(tmp_path):
    tmp_file_1 = tmp_path / "test1.scriic"
    tmp_file_1.write_text(
        """
        HOWTO Test scriic with <param>
        DO This is in file 1

        SUB ./test2.scriic
        PRM param = [param]
        GO
        """
    )

    tmp_file_2 = tmp_path / "test2.scriic"
    tmp_file_2.write_text(
        """
        HOWTO Test subscriic with <param>
        DO The value of param is [param]
        """
    )

    runner = FileRunner(tmp_file_1.absolute())
    instruction = runner.run({"param": "ABC"})

    assert len(instruction.children) == 2
    assert instruction.children[0].text() == "This is in file 1"
    assert instruction.children[1].text() == "Test subscriic with ABC"
    assert len(instruction.children[1].children) == 1
    assert instruction.children[1].children[0].text() == "The value of param is ABC"
Exemplo n.º 5
0
def test_do_substitution(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test <var>
        DO Test [var]!
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run({"var": "scriic"})

    assert instruction.children[0].text() == "Test scriic!"
Exemplo n.º 6
0
def test_title(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test <param>
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run({"param": "scriic"})

    assert instruction.text() == "Test scriic"
    assert len(instruction.children) == 0
Exemplo n.º 7
0
def test_sub_nonexistant_file(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text(
        """
        HOWTO Test scriic
        SUB ./nonexistant.sub
        """
    )

    runner = FileRunner(tmp_file.absolute())
    with pytest.raises(FileNotFoundError):
        runner.run()
Exemplo n.º 8
0
def test_do(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test scriic
        DO Test scriic!
        DO Test scriic again!
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run()

    assert instruction.children[0].text() == "Test scriic!"
    assert instruction.children[1].text() == "Test scriic again!"
Exemplo n.º 9
0
def test_letters_no_var(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test scriic
        LETTERS Hello
            DO Something
        END
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 5
    for i in range(5):
        assert instruction.children[i].text() == "Something"
Exemplo n.º 10
0
def test_letters_known(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test scriic
        char = LETTERS Hello
            DO [char]
        END
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 5
    for i, char in enumerate("Hello"):
        assert instruction.children[i].text() == char
Exemplo n.º 11
0
def test_repeat_known(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test scriic
        REPEAT 5
            DO Something
        END
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 5
    for child in instruction.children:
        assert child.text() == "Something"
Exemplo n.º 12
0
def test_unexpected_sub(tmp_path):
    tmp_file_1 = tmp_path / "test1.scriic"
    tmp_file_1.write_text(
        """
        HOWTO Test scriic
        SUB ./test2.scriic
        PRM param = ABC
        SUB ./test3.scriic
        GO
        """
    )

    tmp_file_2 = tmp_path / "test2.scriic"
    tmp_file_2.write_text(
        """
        HOWTO Test scriic 2 with <param>
        """
    )

    tmp_file_3 = tmp_path / "test3.scriic"
    tmp_file_3.write_text(
        """
        HOWTO Test scriic 3
        """
    )

    with pytest.raises(ScriicSyntaxException):
        runner = FileRunner(tmp_file_1.absolute())
Exemplo n.º 13
0
def test_do_with_variable(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test scriic
        var = DO Get some value
        DO Read [var]
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 2
    assert instruction.children[0].text() == "Get some value"

    instruction.children[0].display_index = 1
    assert instruction.children[1].text() == "Read the result of instruction 1"
Exemplo n.º 14
0
def test_unknown_command(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test scriic
        WHERE THERE ARE INVALID COMMANDS
        """)

    with pytest.raises(ScriicSyntaxException):
        FileRunner(tmp_file.absolute())
Exemplo n.º 15
0
def test_unfinished_sub(tmp_path):
    tmp_file_1 = tmp_path / "test1.scriic"
    tmp_file_1.write_text(
        """
        HOWTO Test scriic
        SUB ./test2.scriic
        """
    )

    tmp_file_2 = tmp_path / "test2.scriic"
    tmp_file_2.write_text(
        """
        HOWTO Test subscriic with <param>
        """
    )

    runner = FileRunner(tmp_file_1.absolute())
    with pytest.raises(ScriicRuntimeException):
        runner.run()
Exemplo n.º 16
0
def test_scriicsics_are_vaild(file_path):
    """Each Scriicsics file should parse without errors."""

    try:
        # This will attempt to parse the file
        FileRunner(file_path.absolute())
    except ScriicSyntaxException as e:
        # Create a more useful failure message
        relative_path = file_path.relative_to(scriicsics_dir)
        pytest.fail(f"{relative_path} raised a syntax exception: {e}")
Exemplo n.º 17
0
def test_no_howto(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text(
        """
        DO Something
        """
    )

    with pytest.raises(ScriicSyntaxException):
        FileRunner(tmp_file.absolute())
Exemplo n.º 18
0
def test_missing_end(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test scriic
        LETTERS char IN Hello
            DO [char]
        """)

    with pytest.raises(ScriicSyntaxException):
        FileRunner(tmp_file.absolute())
Exemplo n.º 19
0
def test_sub_missing_return(tmp_path):
    tmp_file_1 = tmp_path / "test1.scriic"
    tmp_file_1.write_text(
        """
        HOWTO Test scriic
        val = SUB ./test2.scriic
        """
    )

    tmp_file_2 = tmp_path / "test2.scriic"
    tmp_file_2.write_text(
        """
        HOWTO Test subscriic
        DO not return anything
        """
    )

    runner = FileRunner(tmp_file_1.absolute())
    with pytest.raises(ScriicRuntimeException):
        runner.run()
Exemplo n.º 20
0
def test_unexpected_go(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text(
        """
        HOWTO Test scriic
        GO
        """
    )

    with pytest.raises(ScriicSyntaxException):
        runner = FileRunner(tmp_file.absolute())
Exemplo n.º 21
0
def test_quoted_param(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text(
        """
        HOWTO Read <book_title">
        """
    )

    runner = FileRunner(tmp_file.absolute())
    assert runner.title == ["Read ", Parameter("book_title", True)]
    assert runner.required_parameters == {"book_title"}
Exemplo n.º 22
0
def test_repeat_unknown(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test scriic
        times = DO Get a number
        REPEAT times
            DO Something
        END
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 3
    assert instruction.children[0].text() == "Get a number"
    instruction.children[0].display_index = 1
    assert instruction.children[1].text() == "Something"
    instruction.children[1].display_index = 2
    assert instruction.children[2].text() == (
        "Go to instruction 2 and repeat the number of times from instruction 1"
    )
Exemplo n.º 23
0
def test_letters_unknown(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text("""
        HOWTO Test scriic
        string = DO Get a string
        char = LETTERS [string]
            DO Say [char"]
        END
        """)

    runner = FileRunner(tmp_file.absolute())
    instruction = runner.run()

    assert len(instruction.children) == 4
    assert instruction.children[0].text() == "Get a string"
    instruction.children[0].display_index = 1
    assert instruction.children[1].text() == (
        "Get the first letter of the result of instruction 1, or the next letter "
        "if you are returning from a future instruction")
    instruction.children[1].display_index = 2
    assert instruction.children[2].text() == "Say the result of instruction 2"
    assert instruction.children[3].text() == (
        "If you haven't yet reached the last letter of the result of "
        "instruction 1, go to instruction 2")
Exemplo n.º 24
0
def test_howto(tmp_path):
    tmp_file = tmp_path / "test.scriic"
    tmp_file.write_text(
        """
        HOWTO Make a <filling> sandwich on <surface>
        """
    )

    runner = FileRunner(tmp_file.absolute())
    assert runner.title == [
        "Make a ",
        Parameter("filling", False),
        " sandwich on ",
        Parameter("surface", False),
    ]
    assert runner.required_parameters == {"filling", "surface"}