44import errno
55import os
66import shutil
7+ import tempfile
78import unittest
89from unittest import mock
910
@@ -39,7 +40,7 @@ def func(*_args, **_kwargs):
3940
4041
4142def clean_folder (folder ):
42- if os .path .isfile (folder ):
43+ if os .path .isdir (folder ):
4344 for filename in os .listdir (folder ):
4445 file_path = os .path .join (folder , filename )
4546 try :
@@ -53,16 +54,12 @@ def clean_folder(folder):
5354
5455# pylint: disable=unused-variable
5556class TestLocalFileBlob (unittest .TestCase ):
56- @classmethod
57- def setup_class (cls ):
58- os .makedirs (TEST_FOLDER , exist_ok = True )
59-
60- @classmethod
61- def tearDownClass (cls ):
62- shutil .rmtree (TEST_FOLDER , True )
57+ def setUp (self ):
58+ global TEST_FOLDER
59+ TEST_FOLDER = tempfile .mkdtemp ()
6360
6461 def tearDown (self ):
65- clean_folder (TEST_FOLDER )
62+ shutil . rmtree (TEST_FOLDER , ignore_errors = True )
6663
6764 def test_delete (self ):
6865 blob = LocalFileBlob (os .path .join (TEST_FOLDER , "foobar" ))
@@ -320,9 +317,12 @@ def test_lease_with_existing_lock(self):
320317
321318# pylint: disable=protected-access, too-many-public-methods
322319class TestLocalFileStorage (unittest .TestCase ):
323- @classmethod
324- def tearDownClass (cls ):
325- shutil .rmtree (TEST_FOLDER , True )
320+ def setUp (self ):
321+ global TEST_FOLDER
322+ TEST_FOLDER = tempfile .mkdtemp ()
323+
324+ def tearDown (self ):
325+ shutil .rmtree (TEST_FOLDER , ignore_errors = True )
326326
327327 def test_get_nothing (self ):
328328 with LocalFileStorage (os .path .join (TEST_FOLDER , "test" , "a" )) as stor :
@@ -374,7 +374,7 @@ def test_check_storage_size_full(self):
374374 os .makedirs (test_path , exist_ok = True )
375375 with mock .patch .object (LocalFileStorage , "_check_and_set_folder_permissions" , return_value = True ):
376376 with LocalFileStorage (test_path , 1 ) as stor :
377- stor .put (test_input )
377+ stor .put (test_input , lease_period = 0 )
378378 self .assertFalse (stor ._check_storage_size ())
379379
380380 def test_check_storage_size_not_full (self ):
0 commit comments