mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-29 20:04:30 +01:00
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
import json
|
|
|
|
|
|
class RegressionManager:
|
|
"""Abstracts interaction with the regression tests file"""
|
|
|
|
def __init__(self, filename: str):
|
|
self.filename = filename
|
|
self.load()
|
|
|
|
def load(self) -> None:
|
|
try:
|
|
with open(self.filename, "r") as f:
|
|
file_content = (
|
|
f.read().strip()
|
|
) # read the content and remove any leading/trailing whitespace
|
|
if file_content: # if file is not empty, load the json
|
|
self.tests = json.loads(file_content)
|
|
else: # if file is empty, assign an empty dictionary
|
|
self.tests = {}
|
|
except FileNotFoundError:
|
|
self.tests = {}
|
|
except json.decoder.JSONDecodeError: # If JSON is invalid
|
|
self.tests = {}
|
|
self.save()
|
|
|
|
def save(self) -> None:
|
|
with open(self.filename, "w") as f:
|
|
json.dump(self.tests, f, indent=4)
|
|
|
|
def add_test(self, test_name: str, test_details: dict) -> None:
|
|
self.tests[test_name] = test_details
|
|
self.save()
|
|
|
|
def remove_test(self, test_name: str) -> None:
|
|
if test_name in self.tests:
|
|
del self.tests[test_name]
|
|
self.save()
|