diff options
author | 2021-02-25 14:36:59 +0100 | |
---|---|---|
committer | 2021-02-25 14:40:47 +0100 | |
commit | 99f9a0a940a91f2b9894ebf10b0359bba41d1856 (patch) | |
tree | ad9a62ee6870e55dc51d62d56f93780ea33ae88b | |
parent | Add return code 7 for processes killed by NsJail (diff) |
Make use of .raise_for_status()
Co-authored-by: Hassan Abouelela <[email protected]>
-rw-r--r-- | backend/routes/forms/unittesting.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/backend/routes/forms/unittesting.py b/backend/routes/forms/unittesting.py index 57bf5db..cc9f814 100644 --- a/backend/routes/forms/unittesting.py +++ b/backend/routes/forms/unittesting.py @@ -2,9 +2,9 @@ import ast from collections import namedtuple from itertools import count from textwrap import indent -from typing import Optional import httpx +from httpx import HTTPStatusError from backend.constants import SNEKBOX_URL from backend.models import FormResponse, Form @@ -46,15 +46,13 @@ def _make_user_code(code: str) -> str: return f'USER_CODE = r"""{code}"""' -async def _post_eval(code: str) -> Optional[dict[str, str]]: +async def _post_eval(code: str) -> dict[str, str]: """Post the eval to snekbox and return the response.""" async with httpx.AsyncClient() as client: data = {"input": code} response = await client.post(SNEKBOX_URL, json=data, timeout=10) - if not response.status_code == 200: - return - + response.raise_for_status() return response.json() @@ -89,9 +87,9 @@ async def execute_unittest(form_response: FormResponse, form: Form) -> list[Unit result = "Invalid generated unit code." # The runner is correctly formatted, we can run it. else: - response = await _post_eval(code) - - if not response: + try: + response = await _post_eval(code) + except HTTPStatusError: return_code = 99 result = "Unable to contact code runner." else: |