def check_state(student_module):
    """All the variables are named and filled in as expected"""
    _, state = utils.exec_main(student_module)
    expected_state = {
        "goal_0":
        32,
        "goal_1":
        54,
        "scorers":
        "Ruud Gullit 32, Marco van Basten 54",
        "report":
        "Ruud Gullit scored in the 32nd minute\n" +
        "Marco van Basten scored in the 54th minute",
    }
    utils.check_state(expected_state, state)

    player = state.get("player", None)
    assert player, "There is no variable `player` declared in your code"
    assert (
        type(player) is str
    ), f"Expected `player` to contain a `str` but it contained a {type(player)}"

    expected_state = {
        "first_name":
        player[:player.find(" ")],
        "last_name_len":
        len(player[player.find(" ") + 1:]),
        "name_short":
        player[0] + "." + player[player.find(" "):],
        "chant": ((player[:player.find(" ")] + "! ") *
                  len(player[:player.find(" ")]))[:-1],
        "good_chant":
        True,
    }
    utils.check_state(expected_state, state)
示例#2
0
def check_output(student_module):
    """All output is as expected"""
    # TODO: FEATURE: check if the correct operators have been used in addition
    # to just checking the result.
    output, state = utils.exec_main(student_module)

    expected = [str(x) for x in [False, True, True, False, True, True, True]]
    output = output.split("\n")
    assert len(output) == len(
        expected
    ), f"Output was expected to be `{len(expected)}` lines long but was `{len(output)}` lines."

    for i, (o, e) in enumerate(zip(output, expected)):
        assert o == e, f"Output line {i} should be {e} but was {o}"
def check_output(student_module):
    """All the output is correct, and in the right order."""
    output, _ = utils.exec_main(student_module)
    expected_output = [
        "Leek is 2 euro per kilo.", "8", "1.6kg broccoli costs 3.74e"
    ]
    for i, line in enumerate(output.split("\n")):
        if i >= len(expected_output):
            raise AssertionError(
                "There were more lines of output than expected")
        if line == "":
            pass
        assert (
            line == expected_output[i]
        ), f"Expected line **{i}** to be\n\n`{expected_output[i]}`\n\nbut it was \n\n`{line}`"
def check_stdout(student_module):
    """Running your `main.py` prints something."""
    output, _ = utils.exec_main(student_module)
    assert output != "", "Your program didn't print anything."
示例#5
0
def check_output(student_module):
    """All output is as expected."""
    output, _ = utils.exec_main(student_module)
    assert output == "Hello, world", (
        f"Expected output\n\n`'Hello, world'`\n\nbut it was\n\n`'{output}'`\n\n"
        + " (empty)" if not output else "")
def __get_types_in_state(student_module):
    return set([type(v) for v in utils.exec_main(student_module)[1].values()])
示例#7
0
def check_state(student_module):
    """All the variables are named and filled in as expected"""
    _, state = utils.exec_main(student_module)
    expected_state = {k: True for k in ["one", "two", "three"]}
    utils.check_state(expected_state, state)