-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_test_validation.py
More file actions
79 lines (65 loc) · 2.24 KB
/
Copy pathapi_test_validation.py
File metadata and controls
79 lines (65 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from fastapi.testclient import TestClient
import pytest
from api import app # Replace with the actual import of your FastAPI app
@pytest.fixture
def client():
with TestClient(app) as test_client:
yield test_client
def test_py_1(client):
valid_code = """
def add_numbers(a, b):
return a + b
result = add_numbers(3, 4)
print(result)
"""
response = client.post("/get_code_hints", json={"code": valid_code})
assert response.status_code == 200
data = response.json()
assert data['is_python'] is True
def test_valid_code_1(client):
valid_code = """
def add_numbers(a, b):
return a + b
result = add_numbers(3, 4)
print(result)
"""
response = client.post("/get_code_hints", json={"code": valid_code})
assert response.status_code == 200
data = response.json()
assert data['runtime_error_free'] is True
assert data['runtime_error_line'] is None
def test_valid_code_2(client):
valid_code = """
class MyClass:
def __init__(self, name):
self.name = name
obj = MyClass("Test")
print(obj.name)
"""
response = client.post("/get_code_hints", json={"code": valid_code})
assert response.status_code == 200
data = response.json()
assert data['runtime_error_free'] is True
assert data['runtime_error_line'] is None
def test_invalid_code_1(client):
invalid_code = """
for i in range(5)
print(i)
"""
response = client.post("/get_code_hints", json={"code": invalid_code})
assert response.status_code == 200
data = response.json()
assert data['runtime_error_free'] is False
assert isinstance(data['runtime_error_line'], int)
assert data['runtime_error_line'] > 0 # Assuming the error line is identified correctly
def test_invalid_code_2(client):
invalid_code = """
def my_function()
return "Hello, world!"
"""
response = client.post("/get_code_hints", json={"code": invalid_code})
assert response.status_code == 200
data = response.json()
assert data['runtime_error_free'] is False
assert isinstance(data['runtime_error_line'], int)
assert data['runtime_error_line'] > 0 # Assuming the error line is identified correctly