Skip to content

Commit

Permalink
Delete node_checker.py and implement logic directly in views.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Haakon Karstensen authored and Haakon Karstensen committed Nov 5, 2024
1 parent a421d32 commit df91008
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
22 changes: 0 additions & 22 deletions server/server_comm/test_runner/node_checker.py

This file was deleted.

20 changes: 13 additions & 7 deletions server/server_comm/test_runner/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import ast
from urllib.parse import urlencode

import requests
Expand All @@ -9,8 +10,6 @@
from rest_framework.response import Response
from rest_framework.views import APIView

from . import node_checker


class RunTestFlow(APIView):
"""
Expand Down Expand Up @@ -111,13 +110,20 @@ def run_node(self, node):
try:
result = None
if node.node_type == Node.ASSERT:
node_checker.check_valid_input(node.function)
try:
tree = ast.parse(node.function)
except SyntaxError:
raise ValueError("Input is not correct syntax for Python.")

for node in ast.walk(tree):
if isinstance(node, ast.Return):
if isinstance(node.value, ast.Constant) and isinstance(
node.value.value, bool
):
return True
ValueError("Input does not return type of boolean.")
try:
result = exec(node.function)
if result:
result = "Assert OK"
else:
result = "Assert failed"
except Exception as e:
return f"Exection failed: {str(e)}"

Expand Down

0 comments on commit df91008

Please sign in to comment.