Commit f6cac0e3 authored by Julien Muchembled's avatar Julien Muchembled

tests: gather temporary folders in a subfolder to not pollute default /tmp

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2668 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent bb49f74b
......@@ -18,13 +18,13 @@
import traceback
import unittest
import tempfile
import logging
import time
import sys
import neo
import os
from neo.tests import getTempDirectory
from neo.tests.benchmark import BenchmarkRunner
# list of test modules
......@@ -111,8 +111,7 @@ class NeoTestRunner(unittest.TestResult):
self.modulesStats = {}
self.failedImports = {}
self.lastStart = None
self.temp_directory = tempfile.mkdtemp(prefix='neo_')
print "Base directory : %s" % (self.temp_directory, )
self.temp_directory = getTempDirectory()
def run(self, name, modules):
print '\n', name
......
......@@ -52,6 +52,24 @@ def buildUrlFromString(address):
pass
return address
def getTempDirectory():
"""get the current temp directory or a new one"""
try:
temp_dir = os.environ['TEMP']
except KeyError:
neo_dir = os.path.join(tempfile.gettempdir(), 'neo_tests')
while True:
temp_dir = os.path.join(neo_dir, repr(time()))
try:
os.makedirs(temp_dir)
break
except OSError, e:
if e.errno != errno.EEXIST:
raise
os.environ['TEMP'] = temp_dir
print 'Using temp directory %r.' % temp_dir
return temp_dir
class NeoTestBase(unittest.TestCase):
def setUp(self):
sys.stdout.write(' * %s ' % (self.id(), ))
......
......@@ -33,7 +33,7 @@ from neo.neoctl.neoctl import NeoCTL, NotReadyException
from neo.lib.protocol import ClusterStates, NodeTypes, CellStates, NodeStates
from neo.lib.util import dump, SOCKET_CONNECTORS_DICT
from neo.tests import DB_ADMIN, DB_PASSWD, NeoTestBase, buildUrlFromString, \
ADDRESS_TYPE, IP_VERSION_FORMAT_DICT, SocketLock
ADDRESS_TYPE, IP_VERSION_FORMAT_DICT, SocketLock, getTempDirectory
from neo.client.Storage import Storage
NEO_MASTER = 'neomaster'
......@@ -613,14 +613,8 @@ class NEOCluster(object):
class NEOFunctionalTest(NeoTestBase):
def getTempDirectory(self):
# get the current temp directory or a new one
temp_dir = os.environ.get('TEMP', None)
if temp_dir is None:
temp_dir = tempfile.mkdtemp(prefix='neo_')
os.environ['TEMP'] = temp_dir
print 'Using temp directory %r.' % (temp_dir, )
# build the full path based on test case and current test method
temp_dir = os.path.join(temp_dir, self.id())
temp_dir = os.path.join(getTempDirectory(), self.id())
# build the path if needed
if not os.path.exists(temp_dir):
os.makedirs(temp_dir)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment