未验证 提交 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,7 +143,7 @@ def set_dir(dirname): ...@@ -143,7 +143,7 @@ def set_dir(dirname):
_FILE_HANDLER.close() _FILE_HANDLER.close()
del _FILE_HANDLER del _FILE_HANDLER
if not os.path.isdir(dirname): shutil.rmtree(dirname, ignore_errors=True)
_makedirs(dirname) _makedirs(dirname)
LOG_DIR = dirname LOG_DIR = dirname
_set_file(os.path.join(dirname, 'log.log')) _set_file(os.path.join(dirname, 'log.log'))
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
import unittest import unittest
from parl.utils import logger from parl.utils import logger
import threading as th import threading as th
import os.path
class TestLogger(unittest.TestCase): class TestLogger(unittest.TestCase):
...@@ -45,6 +46,15 @@ class TestLogger(unittest.TestCase): ...@@ -45,6 +46,15 @@ class TestLogger(unittest.TestCase):
logger.auto_set_dir(action='n') logger.auto_set_dir(action='n')
logger.auto_set_dir(action='k') 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__': if __name__ == '__main__':
unittest.main() unittest.main()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册