未验证 提交 0ffd40bf 编写于 作者: B Bo Zhou 提交者: GitHub

clear the directory for the function (#145)

* clear the directory for the function

* add the unit test

* unit test bug

* yapf
上级 7318f63e
......@@ -143,8 +143,8 @@ def set_dir(dirname):
_FILE_HANDLER.close()
del _FILE_HANDLER
if not os.path.isdir(dirname):
_makedirs(dirname)
shutil.rmtree(dirname, ignore_errors=True)
_makedirs(dirname)
LOG_DIR = dirname
_set_file(os.path.join(dirname, 'log.log'))
......
......@@ -15,6 +15,7 @@
import unittest
from parl.utils import logger
import threading as th
import os.path
class TestLogger(unittest.TestCase):
......@@ -45,6 +46,15 @@ class TestLogger(unittest.TestCase):
logger.auto_set_dir(action='n')
logger.auto_set_dir(action='k')
def test_set_dir(self):
logger.set_dir('./logger_dir')
temp_file = './logger_dir/tmp.file'
with open(temp_file, 'w') as t_file:
t_file.write("Are you OK? From Mr.Lei")
self.assertTrue(os.path.isfile(temp_file))
logger.set_dir('./logger_dir')
self.assertFalse(os.path.isfile(temp_file))
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册