Fix test_unwatch_log() to cleanup after itself

Use get_temp_file_patch() so a unique directory is used
for test files, and so that anything created will get
cleaned-up on completion.

Change-Id: Ie3473906f87fdf270f1a67c16ed511b38b597755
This commit is contained in:
Brian Haley 2016-10-27 11:46:09 -04:00
parent 5f1994dd79
commit 23ffde81a5

View File

@ -37,10 +37,11 @@ class FakeEntry(object):
class TestUnwatchLog(base.BaseTestCase):
def test_unwatch_log(self):
temp_file_name = self.get_temp_file_path('unwatch_log_temp_file_name')
stream_handler = logging.StreamHandler()
logger = logging.Logger('fake')
logger.addHandler(stream_handler)
logger.addHandler(handlers.WatchedFileHandler('/tmp/filename1'))
logger.addHandler(handlers.WatchedFileHandler(temp_file_name))
with mock.patch('logging.getLogger', return_value=logger):
daemon.unwatch_log()
@ -48,7 +49,7 @@ class TestUnwatchLog(base.BaseTestCase):
logger.handlers.remove(stream_handler)
observed = logger.handlers[0]
self.assertEqual(logging.FileHandler, type(observed))
self.assertEqual('/tmp/filename1', observed.baseFilename)
self.assertEqual(temp_file_name, observed.baseFilename)
class TestPrivileges(base.BaseTestCase):