コード例 #1
0
def test_has_equal_ast_on_check_function_v2():
    code = "round(1)"
    s = setup_state(code, code)
    with helper.set_v2_only_env("1"):
        with pytest.raises(
            InstructorError,
            match=r"`has_equal_ast\(\)` should not be called on `check_function\(\)`\.",
        ):
            s.check_function("round").has_equal_ast()
コード例 #2
0
def test_has_equal_ast_on_check_object_v2():
    code = "x = 1"
    s = setup_state(code, code)
    with helper.set_v2_only_env("1"):
        with pytest.raises(
            InstructorError,
            match=r"`has_equal_ast\(\)` should not be called on `check_object\(\)`\.",
        ):
            s.check_object("x").has_equal_ast()
コード例 #3
0
def test_check_object_not_on_root_v2():
    code = "for i in range(3): x = 1"
    s = setup_state(code, code)
    with helper.set_v2_only_env("1"):
        with pytest.raises(
            InstructorError,
            match=r"`check_object\(\)` should only be called focusing on a full script, following `Ex\(\)` or `run\(\)`\. If you want to check the value of an object in e.g. a for loop, use `has_equal_value\(name = 'my_obj'\)` instead.",
        ):
            s.check_for_loop().check_body().check_object("x")
コード例 #4
0
ファイル: test_v2_only.py プロジェクト: datacamp/pythonwhat
def test_with_env_old_fail(data, sct, should_err):
    data["DC_SCT"] = sct
    with helper.set_v2_only_env("1"):
        relooooad()
        if should_err:
            with pytest.raises((NameError, AttributeError)):
                sct_payload = helper.run(data)
        else:
            sct_payload = helper.run(data)
            assert not sct_payload["correct"]
コード例 #5
0
ファイル: test_v2_only.py プロジェクト: datacamp/pythonwhat
def test_without_env_all_works(data, sct):
    data["DC_SCT"] = sct
    with helper.set_v2_only_env(""):
        relooooad()
        sct_payload = helper.run(data)
        assert not sct_payload["correct"]
コード例 #6
0
def test_check_object_not_on_root():
    code = "for i in range(3): x = 1"
    s = setup_state(code, code)
    with helper.set_v2_only_env(""):
        s.check_for_loop().check_body().check_object("x")