Delete memory files whose resolution_status is not 'RESOLVED'.
(self)
| 110 | file_utils.store_response_files(memory_folder_path, response_files, memory_files) |
| 111 | |
| 112 | def delete_unresolved_memory_files(self): |
| 113 | """Delete memory files whose resolution_status is not 'RESOLVED'.""" |
| 114 | memory_path = os.path.join(self.memory_folder, CONFORMANCE_TEST_MEMORY_SUBFOLDER) |
| 115 | if not os.path.exists(memory_path): |
| 116 | return |
| 117 | |
| 118 | memory_files = file_utils.list_all_text_files(memory_path) |
| 119 | for file_name in memory_files: |
| 120 | file_path = os.path.join(memory_path, file_name) |
| 121 | try: |
| 122 | with open(file_path, "r") as f: |
| 123 | content = json.load(f) |
| 124 | if content.get("resolution_status") == "RESOLVED": |
| 125 | continue |
| 126 | else: |
| 127 | os.remove(file_path) |
| 128 | except (json.JSONDecodeError, OSError): |
| 129 | # Not a valid JSON file, unlikely to be a valid memory file, delete it |
| 130 | console.error(f"Memory file is not a valid JSON file: {file_name}. Deleting it.") |
| 131 | os.remove(file_path) |
| 132 | |
| 133 | console.debug(f"Deleted temporary memory file: {file_name}") |