ArvindSelvaraj
commited on
Commit
•
dac5949
1
Parent(s):
ecfd181
Update backend.py
Browse files- backend.py +14 -35
backend.py
CHANGED
@@ -1,10 +1,9 @@
|
|
1 |
import json
|
2 |
-
import csv
|
3 |
import io
|
4 |
import requests
|
5 |
import html # For escaping HTML characters
|
6 |
from bs4 import BeautifulSoup
|
7 |
-
import pandas as pd #
|
8 |
|
9 |
# Initialize OpenAI API with Nvidia's Llama model
|
10 |
client = OpenAI(
|
@@ -89,42 +88,22 @@ def generate_testcases(user_story):
|
|
89 |
print(f"API request failed: {str(e)}")
|
90 |
return []
|
91 |
|
92 |
-
def export_test_cases(test_cases
|
93 |
if not test_cases:
|
94 |
return "No test cases to export."
|
95 |
|
96 |
-
#
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
output = io.StringIO()
|
105 |
-
csv_writer = csv.DictWriter(output, fieldnames=test_cases[0].keys(), quoting=csv.QUOTE_ALL)
|
106 |
-
csv_writer.writeheader()
|
107 |
-
csv_writer.writerows(test_cases)
|
108 |
-
return output.getvalue()
|
109 |
-
else:
|
110 |
-
raise ValueError("Test cases must be a list of dictionaries for CSV export.")
|
111 |
-
|
112 |
-
def save_test_cases_as_file(test_cases, format='json'):
|
113 |
if not test_cases:
|
114 |
return "No test cases to save."
|
115 |
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
with open('test_cases.csv', 'w', newline='') as file:
|
121 |
-
dict_writer = csv.DictWriter(file, fieldnames=test_cases[0].keys())
|
122 |
-
dict_writer.writeheader()
|
123 |
-
dict_writer.writerows(test_cases)
|
124 |
-
elif format == 'excel':
|
125 |
-
# Use pandas to export the test cases to Excel
|
126 |
-
df = pd.DataFrame(test_cases)
|
127 |
-
df.to_excel('test_cases.xlsx', index=False)
|
128 |
-
else:
|
129 |
-
return f"Unsupported format: {format}"
|
130 |
-
return f'{format} file saved'
|
|
|
1 |
import json
|
|
|
2 |
import io
|
3 |
import requests
|
4 |
import html # For escaping HTML characters
|
5 |
from bs4 import BeautifulSoup
|
6 |
+
import pandas as pd # Added pandas for Excel export
|
7 |
|
8 |
# Initialize OpenAI API with Nvidia's Llama model
|
9 |
client = OpenAI(
|
|
|
88 |
print(f"API request failed: {str(e)}")
|
89 |
return []
|
90 |
|
91 |
+
def export_test_cases(test_cases):
|
92 |
if not test_cases:
|
93 |
return "No test cases to export."
|
94 |
|
95 |
+
# Use pandas to export the test cases to Excel
|
96 |
+
df = pd.DataFrame(test_cases)
|
97 |
+
output = io.BytesIO()
|
98 |
+
df.to_excel(output, index=False)
|
99 |
+
output.seek(0)
|
100 |
+
return output.getvalue()
|
101 |
+
|
102 |
+
def save_test_cases_as_file(test_cases):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
if not test_cases:
|
104 |
return "No test cases to save."
|
105 |
|
106 |
+
# Use pandas to save the test cases to an Excel file
|
107 |
+
df = pd.DataFrame(test_cases)
|
108 |
+
df.to_excel('test_cases.xlsx', index=False)
|
109 |
+
return 'excel file saved'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|