A simple web-based Python code evaluator using Flask.
The Code Evaluator is a web-based application developed using the Flask framework. Its primary functionality revolves around the evaluation of Python code, facilitating a comparative analysis between the resultant output and the anticipated output. This application has been meticulously crafted to serve as a valuable instrument for the automated testing and validation of Python code fragments. Furthermore, it offers a distinctive feature in the form of a visual differentiation tool that enables users to discern disparities between the actual and expected output. Additionally, users can also employ file upload capabilities to specify the anticipated output.
- Evaluate Python code snippets.
- Compare the actual output with the expected output.
- Visual diff between actual and expected output.
- Option to upload an expected output file.
- Option to manually enter the expected output.
- Create an assignment with a description and the expected output (see below).
Before you begin, ensure you have met the following requirements:
- Python 3.x installed.
- A virtual environment for managing project dependencies (optional but recommended).
-
Clone the repository:
git clone https://github.com/ochotzas/code-evaluator.git
-
Navigate to the project directory:
cd code-evaluator
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
source venv/bin/activate
-
Install the project dependencies:
pip install -r requirements.txt
-
Start the Flask application:
python app.py
-
Open a web browser and go to http://localhost:8080 to access the Code Evaluator.
-
Enter your Python code in the "Enter Python Code" textarea.
-
Optionally, upload an expected output file or manually enter the expected output in the "Expected Output" textarea.
-
Click the "Evaluate Code" button to run the code and see the evaluation results.
or (see below Evaluate Code & Post/Create Assignment)
Use the API by calling the endpoint /evaluate
with a POST request and passing the Python code and expected output as
form data.
Example:
curl --location 'http://localhost:8080/evaluate' \
--header 'Content-Type: application/json' \
--data '{
"code": "print(\"Hello, World!\")",
"expected_output": "Hello, World!\n"
}'
In this case, the response will be a JSON object with the following structure:
{
"message": "Output matches the expected output.",
"success": true
}
Use the API by calling the endpoint /post-assignment
with a POST request
and passing the assignment description and expected output like the following example:
{
"description": "Write a Python program to print \"Hello, World!\".",
"expected_output": "Hello, World!\n"
}
In this case, the response will be a JSON object with the following structure:
{
"key": "uid",
"message": "Assignment created successfully.",
"success": true
}
The key
is a unique identifier for the assignment.
You can use this key to retrieve the assignment details by calling the http://localhost:8080/?assigment=uid for example.
-
Home page.
-
Assignment page with the description and expected output.
-
Assignment page with user's wrong output.
-
Assignment page with user's correct output.
-
Assignment page with user's syntax error.
Contributions are welcome! If you'd like to contribute to this project, please follow these guidelines:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them.
- Push your changes to your fork.
- Create a pull request describing your changes.
This project is licensed under the MIT License.