-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
36 lines (27 loc) · 947 Bytes
/
app.py
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
from flask import Flask, render_template, jsonify, request
from main import TestLlamaIndex
import unittest
import io
import sys
app = Flask(__name__)
@app.route('/')
def index():
test_cases = [method for method in dir(TestLlamaIndex) if method.startswith('test_')]
return render_template('index.html', test_cases=test_cases)
@app.route('/run_test', methods=['POST'])
def run_test():
test_name = request.json['test_name']
captured_output = io.StringIO()
sys.stdout = captured_output
suite = unittest.TestSuite()
suite.addTest(TestLlamaIndex(test_name))
runner = unittest.TextTestRunner(stream=captured_output)
result = runner.run(suite)
sys.stdout = sys.__stdout__
output = captured_output.getvalue()
return jsonify({
'success': result.wasSuccessful(),
'output': output
})
if __name__ == '__main__':
app.run(debug=True, port=8000, host='0.0.0.0')