MCPcopy Create free account
hub / github.com/idank/explainshell / TestBatchFileCleanup

Class TestBatchFileCleanup

tests/extraction/llm/test_openai_provider.py:773–871  ·  view source on GitHub ↗

collect_results should delete input/output/error files after collection.

Source from the content-addressed store, hash-verified

771
772@patch("explainshell.extraction.llm.providers.openai.OpenAI")
773class TestBatchFileCleanup(unittest.TestCase):
774 """collect_results should delete input/output/error files after collection."""
775
776 def _make_provider(self) -> OpenAIProvider:
777 return OpenAIProvider("openai/gpt-5-mini")
778
779 def test_all_files_deleted_after_collect(self, _cls: MagicMock) -> None:
780 provider = self._make_provider()
781 job = _make_batch(
782 status="completed",
783 input_file_id="file-in",
784 output_file_id="file-out",
785 error_file_id="file-err",
786 )
787 output_line = json.dumps(
788 {
789 "custom_id": "0:0",
790 "response": {
791 "body": {
792 "output": [
793 {
794 "type": "message",
795 "content": [
796 {"type": "output_text", "text": '{"options":[]}'}
797 ],
798 }
799 ],
800 "usage": {},
801 }
802 },
803 }
804 )
805 provider.client.files.content.return_value = SimpleNamespace(text=output_line)
806 provider.client.files.delete.return_value = None
807
808 provider.collect_results(job)
809
810 deleted = [c.args[0] for c in provider.client.files.delete.call_args_list]
811 self.assertEqual(deleted, ["file-in", "file-out", "file-err"])
812
813 def test_no_output_file_still_cleans_input(self, _cls: MagicMock) -> None:
814 provider = self._make_provider()
815 job = _make_batch(
816 status="cancelled",
817 input_file_id="file-in",
818 output_file_id=None,
819 )
820 provider.client.files.delete.return_value = None
821
822 provider.collect_results(job)
823
824 deleted = [c.args[0] for c in provider.client.files.delete.call_args_list]
825 self.assertEqual(deleted, ["file-in"])
826
827 def test_delete_failure_does_not_prevent_results(self, _cls: MagicMock) -> None:
828 provider = self._make_provider()
829 job = _make_batch(
830 status="completed",

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected