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()
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']
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()
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 from the root state, `Ex\(\)`\. 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')
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 from the root state, `Ex\(\)`\." ): s.check_for_loop().check_body().check_object('x')
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']
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')