Improve TempfileCheckMixin.
This commit is contained in:
@@ -8,20 +8,22 @@ from ..settings import setting_temporary_directory
|
|||||||
|
|
||||||
|
|
||||||
class TempfileCheckMixin(object):
|
class TempfileCheckMixin(object):
|
||||||
def _get_temporary_entries_count(self):
|
def _get_temporary_entries(self):
|
||||||
return len(os.listdir(setting_temporary_directory.value))
|
return os.listdir(setting_temporary_directory.value)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TempfileCheckMixin, self).setUp()
|
super(TempfileCheckMixin, self).setUp()
|
||||||
self._temporary_items = self._get_temporary_entries_count()
|
self._temporary_entries = self._get_temporary_entries()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.assertEqual(
|
for temporary_entry in self._get_temporary_entries():
|
||||||
self._temporary_items, self._get_temporary_entries_count(),
|
self.assertFalse(
|
||||||
|
temporary_entry not in self._temporary_entries,
|
||||||
msg='Orphan temporary file. The number of temporary file and '
|
msg='Orphan temporary file. The number of temporary file and '
|
||||||
'directories at the start and at the end of the test are not the '
|
'directories at the start and at the end of the test are not the '
|
||||||
'same.'
|
'same.'
|
||||||
)
|
)
|
||||||
|
|
||||||
super(TempfileCheckMixin, self).tearDown()
|
super(TempfileCheckMixin, self).tearDown()
|
||||||
|
|
||||||
|
|
||||||
@@ -41,7 +43,8 @@ class OpenFileCheckMixin(object):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
if not getattr(self, '_skip_file_descriptor_test', False):
|
if not getattr(self, '_skip_file_descriptor_test', False):
|
||||||
for new_open_file in self._get_open_files():
|
for new_open_file in self._get_open_files():
|
||||||
self.assertFalse(new_open_file not in self._open_files,
|
self.assertFalse(
|
||||||
|
new_open_file not in self._open_files,
|
||||||
msg='File descriptor leak. The number of file descriptors '
|
msg='File descriptor leak. The number of file descriptors '
|
||||||
'at the start and at the end of the test are not the same.'
|
'at the start and at the end of the test are not the same.'
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user