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()
|
reset_tweaks_to_default()
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
from calibre.utils.recycle_bin import nuke_recycle
|
||||||
|
nuke_recycle()
|
||||||
self.library_path = self.mkdtemp()
|
self.library_path = self.mkdtemp()
|
||||||
self.create_db(self.library_path)
|
self.create_db(self.library_path)
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
from calibre.utils.recycle_bin import restore_recyle
|
||||||
|
restore_recyle()
|
||||||
gc.collect(), gc.collect()
|
gc.collect(), gc.collect()
|
||||||
shutil.rmtree(self.library_path)
|
shutil.rmtree(self.library_path)
|
||||||
|
|
||||||
|
@ -36,8 +36,16 @@ elif islinux:
|
|||||||
|
|
||||||
can_recycle = callable(recycle)
|
can_recycle = callable(recycle)
|
||||||
|
|
||||||
def delete_file(path):
|
def nuke_recycle():
|
||||||
if callable(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:
|
try:
|
||||||
recycle(path)
|
recycle(path)
|
||||||
return
|
return
|
||||||
@ -59,7 +67,7 @@ def delete_tree(path, permanent=False):
|
|||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
else:
|
else:
|
||||||
if callable(recycle):
|
if can_recycle:
|
||||||
try:
|
try:
|
||||||
recycle(path)
|
recycle(path)
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user