From 0b5edb4ad61a0492897376b60c69849cf9ec76c9 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Wed, 26 Oct 2016 02:16:44 -0400 Subject: [PATCH] Add support to ignore certain temporary file patterns to the TempfileCheckMixin --- mayan/apps/common/tests/mixins.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/mayan/apps/common/tests/mixins.py b/mayan/apps/common/tests/mixins.py index cd8be439a0..d43db85616 100644 --- a/mayan/apps/common/tests/mixins.py +++ b/mayan/apps/common/tests/mixins.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals +import glob import os import psutil @@ -32,8 +33,29 @@ class ContentTypeCheckMixin(object): class TempfileCheckMixin(object): + # Ignore the jvmstat instrumentation file + ignore_globs = ('hsperfdata_*',) + def _get_temporary_entries_count(self): - return len(os.listdir(setting_temporary_directory.value)) + ignored_result = [] + + # Expand globs by joining the temporary directory and then flattening + # the list of lists into a single list + for item in self.ignore_globs: + ignored_result.extend( + glob.glob( + os.path.join(setting_temporary_directory.value, item) + ) + ) + + # Remove the path and leave only the expanded filename + ignored_result = map(lambda x: os.path.split(x)[-1], ignored_result) + + return len( + set( + os.listdir(setting_temporary_directory.value) + ) - set(ignored_result) + ) def setUp(self): super(TempfileCheckMixin, self).setUp()