mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Ensure the recycle bin is not used while running tests
This commit is contained in:
parent
44545b0c34
commit
cc7c53289f
@ -27,10 +27,14 @@ class BaseTest(unittest.TestCase):
|
||||
reset_tweaks_to_default()
|
||||
|
||||
def setUp(self):
|
||||
from calibre.utils.recycle_bin import nuke_recycle
|
||||
nuke_recycle()
|
||||
self.library_path = self.mkdtemp()
|
||||
self.create_db(self.library_path)
|
||||
|
||||
def tearDown(self):
|
||||
from calibre.utils.recycle_bin import restore_recyle
|
||||
restore_recyle()
|
||||
gc.collect(), gc.collect()
|
||||
shutil.rmtree(self.library_path)
|
||||
|
||||
|
@ -36,8 +36,16 @@ elif islinux:
|
||||
|
||||
can_recycle = callable(recycle)
|
||||
|
||||
def delete_file(path):
|
||||
if callable(recycle):
|
||||
def nuke_recycle():
|
||||
global can_recycle
|
||||
can_recycle = False
|
||||
|
||||
def restore_recyle():
|
||||
global can_recycle
|
||||
can_recycle = callable(recycle)
|
||||
|
||||
def delete_file(path, permanent=False):
|
||||
if not permanent and can_recycle:
|
||||
try:
|
||||
recycle(path)
|
||||
return
|
||||
@ -59,7 +67,7 @@ def delete_tree(path, permanent=False):
|
||||
time.sleep(1)
|
||||
shutil.rmtree(path)
|
||||
else:
|
||||
if callable(recycle):
|
||||
if can_recycle:
|
||||
try:
|
||||
recycle(path)
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user