44
55import os
66import sys
7+ import tempfile
78import unittest
89from unittest .mock import MagicMock , patch
910
1819)
1920
2021
21- class TestCollectExportEntriesNocache (unittest .TestCase ):
22+ class _TempExportPathsMixin :
23+ def setUp (self ):
24+ self ._tmp = tempfile .TemporaryDirectory ()
25+ self .addCleanup (self ._tmp .cleanup )
26+ self .tmp_ws = os .path .join (self ._tmp .name , "ws" )
27+ self .tmp_out = os .path .join (self ._tmp .name , "out" )
28+ os .makedirs (self .tmp_ws , exist_ok = True )
29+ os .makedirs (self .tmp_out , exist_ok = True )
30+
31+
32+ class TestCollectExportEntriesNocache (_TempExportPathsMixin , unittest .TestCase ):
2233 def test_nocache_env_passed_to_prepare_workspace_orchestration (self ):
2334 with patch .dict (os .environ , {"CURSOR_CHAT_BROWSER_NOCACHE" : "1" }):
2435 with patch (
@@ -30,27 +41,30 @@ def test_nocache_env_passed_to_prepare_workspace_orchestration(self):
3041 return_value = None ,
3142 ):
3243 collect_export_entries (
33- workspace_path = "/tmp/ws" ,
44+ workspace_path = self . tmp_ws ,
3445 exclusion_rules = [],
3546 since = "all" ,
3647 last_export_ms = 0 ,
37- out_dir = "/tmp/out" ,
48+ out_dir = self . tmp_out ,
3849 include_composer = False ,
3950 include_cli = False ,
4051 )
4152 mock_prepare .assert_called_once ()
4253 self .assertTrue (mock_prepare .call_args .kwargs ["nocache" ])
4354
4455
45- class TestCollectExportEntriesCorruptComposer (unittest .TestCase ):
56+ class TestCollectExportEntriesCorruptComposer (
57+ _TempExportPathsMixin ,
58+ unittest .TestCase ,
59+ ):
4660 def test_non_dict_composer_row_is_skipped (self ):
4761 ctx = MagicMock ()
4862 ctx .project_name_to_workspace_id = {}
4963 ctx .workspace_path_to_id = {}
5064 ctx .composer_id_to_workspace_id = {}
5165 ctx .invalid_workspace_ids = set ()
5266 orch = WorkspaceOrchestration (
53- workspace_path = "/tmp/ws" ,
67+ workspace_path = self . tmp_ws ,
5468 workspace_entries = [],
5569 fingerprint = {},
5670 ctx = ctx ,
@@ -80,11 +94,11 @@ def __getitem__(self, key: str) -> str:
8094 return_value = db_data ,
8195 ):
8296 exported = collect_export_entries (
83- workspace_path = "/tmp/ws" ,
97+ workspace_path = self . tmp_ws ,
8498 exclusion_rules = [],
8599 since = "all" ,
86100 last_export_ms = 0 ,
87- out_dir = "/tmp/out" ,
101+ out_dir = self . tmp_out ,
88102 include_cli = False ,
89103 )
90104 self .assertEqual (exported , [])
0 commit comments