def test_check_file_use_fs_no_parse(state, tf):
    state.solution_code = {tf.name: '3 + 3'}
    child = cf.check_file(state, tf.name, parse=False, use_fs=True)
    assert child.student_code == '1 + 1'
    assert child.student_ast is None
    assert child.solution_ast is None
    with pytest.raises(TypeError):
        assert check_node(child, 'Expr', 0)
def test_check_file_no_parse(state, temp_file_sum):
    child = cf.check_file(state, temp_file_sum.name, parse=False)
    has_code(child, "1 + 1", fixed=True)
    assert child.student_code == "1 + 1"
    assert child.student_ast is False
    assert child.solution_ast is None  # no solution code is provided
    with pytest.raises(TypeError):
        assert check_node(child, "Expr", 0)
def test_check_file_use_fs(state, tf):
    state.solution_code = {tf.name: '3 + 3'}
    child = cf.check_file(state, tf.name, use_fs=True)
    assert child.student_code == '1 + 1'
    assert_equal_ast(child.student_ast, ast.parse(child.student_code))
    assert child.solution_code == '3 + 3'
    assert_equal_ast(child.solution_ast, ast.parse(child.solution_code))
    assert check_node(child, 'Expr', 0)
Beispiel #4
0
def test_check_file(code_state):
    child = cf.check_file(code_state,
                          'script1.py',
                          use_fs=False,
                          use_solution=True)
    assert child.student_code == "1 + 1"
    assert_equal_ast(child.student_ast, ast.parse(child.student_code))
    assert_equal_ast(child.solution_ast, ast.parse(child.solution_code))
Beispiel #5
0
def test_check_file_no_parse(code_state):
    child = cf.check_file(code_state,
                          'script1.py',
                          use_fs=False,
                          parse=False,
                          use_solution=True)
    assert child.student_code == "1 + 1"
    assert child.student_ast is None
    assert child.solution_ast is None
Beispiel #6
0
def test_python_file_existence(temp_py_file):
    expected_content = cf.get_file_content(temp_py_file.name)
    chain = setup_state("", "", pec="")

    # test with just student content
    child = cf.check_file(chain._state, temp_py_file.name)
    assert expected_content in child.student_code
    assert child.student_ast is not None
    assert child.solution_code is None
    assert child.solution_ast is None

    # test with solution content
    child = cf.check_file(chain._state,
                          temp_py_file.name,
                          solution_code=expected_content)
    assert expected_content in child.student_code
    assert child.student_ast is not None
    assert expected_content in child.solution_code
    assert child.solution_ast is not None
def test_check_file(state, temp_file_sum):
    child = cf.check_file(state, temp_file_sum.name, solution_code="3 + 3")
    assert child.student_code == "1 + 1"
    assert_equal_ast(child.student_ast, ast.parse(child.student_code))

    assert child.solution_code == "3 + 3"
    assert_equal_ast(child.solution_ast, ast.parse(child.solution_code))

    assert child.path == Path(temp_file_sum.name)
    assert child.path.parent == Path(temp_file_sum.name).parent
    assert child.path.name == Path(temp_file_sum.name).name

    grandchild = check_node(child, "Expr", 0)
    assert grandchild.path == child.path
def test_check_file_not_readable(state, temp_file_unicode):
    Path(temp_file_unicode.name).write_bytes("é".encode("latin-1"))
    child = cf.check_file(state, temp_file_unicode.name, parse=False)
    assert child.student_code is None
def test_check_file_dir(state):
    with pytest.raises(TF) as exception:
        with TemporaryDirectory() as td:
            cf.check_file(state, td)
    assert "found a directory" in str(exception)
def test_check_file_missing(state):
    with pytest.raises(TF) as exception:
        cf.check_file(state, "foo")
    assert "Did you create the file" in str(exception)
def test_check_no_sol(state, temp_file):
    child = cf.check_file(state, temp_file.name)
    assert child.solution_code is None
Beispiel #12
0
def test_check_no_sol(state, tf):
    child = cf.check_file(state, tf.name, use_fs=True, use_solution=False)
    assert child.solution_code == None