Ensure the recycle bin is not used while running tests

This commit is contained in:
Kovid Goyal 2013-08-06 13:08:40 +05:30
parent 44545b0c34
commit cc7c53289f
2 changed files with 15 additions and 3 deletions

View File

@ -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)

View File

@ -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