@@ -15,10 +15,17 @@ def _fillTrashWithJunk(n):
1515 trash = Trash .instance ()
1616 trash .refreshFiles ()
1717 trash .clear ()
18- os .makedirs (trash .trashDir , exist_ok = True )
18+ trash .trashDir .mkdir (parents = True , exist_ok = True )
19+
1920 for i in range (n ):
20- with open (F"{ trash .trashDir } /19991231T235900-test{ i } .txt" , "w" ) as junk :
21- junk .write (F"test{ i } " )
21+ junkPath = Path (trash .trashDir , f"19991231T235900-test{ i } .txt" )
22+
23+ # Alternate between bogus text files and bogus symlinks
24+ if i % 2 == 0 :
25+ junkPath .write_text (f"test{ i } " )
26+ else :
27+ junkPath .symlink_to (trash .trashDir )
28+
2229 trash .refreshFiles ()
2330
2431
@@ -109,20 +116,26 @@ def testTrashFull(tempDir, mainWindow):
109116 # Trash should have been purged to make room for new patch
110117 trashInstance = Trash .instance ()
111118 assert len (trashInstance .trashFiles ) == settings .prefs .maxTrashFiles
119+ assert len (list (trashInstance .trashDir .iterdir ())) == settings .prefs .maxTrashFiles
112120 assert "a1.txt" in trashInstance .trashFiles [0 ].name
113121
114122
115123def testClearTrash (mainWindow ):
116- assert Trash .instance ().count () == 0
124+ trashInstance = Trash .instance ()
125+ assert trashInstance .count () == 0
117126
118127 mainWindow .clearRescueFolder ()
119128 acceptQMessageBox (mainWindow , "no discarded (patches|changes) to delete" )
120129
121130 _fillTrashWithJunk (40 )
122- assert Trash . instance () .count () == 40
131+ assert trashInstance .count () == 40
123132 mainWindow .clearRescueFolder ()
124133 acceptQMessageBox (mainWindow , "delete.+40.+discarded (patches|changes)" )
125- assert Trash .instance ().count () == 0
134+ assert trashInstance .count () == 0
135+
136+ trashInstance .refreshFiles ()
137+ assert trashInstance .count () == 0
138+ assert not list (trashInstance .trashDir .iterdir ())
126139
127140
128141def testOpenTrashFolder (mainWindow ):
0 commit comments