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"
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"
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"
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"
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!"
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
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()
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!"
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"
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
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"
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())
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"
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())
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()
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}")
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())
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())
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()
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())
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"}
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" )
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")
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"}