Skip to content

Commit 53481ee

Browse files
committed
Added a utility function to create a test-class specific temporary directory.
- Legacy-Id: 13026
1 parent 483d5f9 commit 53481ee

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

ietf/utils/test_utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@
3232
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3333
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434

35+
import os
3536
import html5lib
3637
import urllib2
3738
from unittest.util import strclass
3839

3940
import django.test
4041
from django.conf import settings
42+
from django.utils.text import slugify
4143

4244
import debug # pyflakes:ignore
4345

@@ -98,5 +100,13 @@ def assertValidHTMLResponse(self, resp):
98100
self.assertTrue(resp['Content-Type'].startswith('text/html'))
99101
self.assertValidHTML(resp.content)
100102

103+
def tempdir(self, label):
104+
slug = slugify(self.__class__.replace('.','-'))
105+
dirname = "tmp-{label}-{slug}".format(**locals())
106+
path = os.path.abspath(dirname)
107+
if not os.path.exists(path):
108+
os.mkdir(path)
109+
return path
110+
101111
def __str__(self):
102112
return "%s (%s.%s)" % (self._testMethodName, strclass(self.__class__),self._testMethodName)

0 commit comments

Comments
 (0)