Use separate temp directories for separate tests.

Makes unit tests for the previous commit work even when not run alone.
Should have done this from the beginning, but didn't find the trick
for getting the module name.
This commit is contained in:
Tommi Virtanen 2007-09-01 16:36:01 -07:00
parent 0132515356
commit fd11351859
2 changed files with 17 additions and 6 deletions

View file

@ -1,7 +1,6 @@
from nose.tools import eq_ as eq
import os
import shutil
from gitosis import repository
@ -39,8 +38,6 @@ def test_init_exist_git():
def test_init_templates():
tmp = maketemp()
path = os.path.join(tmp, 'repo.git')
if os.path.exists(path):
shutil.rmtree(path)
templatedir = os.path.join(
os.path.dirname(__file__),
'mocktemplates',

View file

@ -2,7 +2,9 @@ from nose.tools import eq_ as eq
import errno
import os
import shutil
import stat
import sys
def mkdir(*a, **kw):
try:
@ -16,9 +18,21 @@ def mkdir(*a, **kw):
def maketemp():
tmp = os.path.join(os.path.dirname(__file__), 'tmp')
mkdir(tmp)
me = os.path.splitext(os.path.basename(__file__))[0]
tmp = os.path.join(tmp, me)
mkdir(tmp)
caller = sys._getframe(1)
name = '%s.%s' % (
sys._getframe(1).f_globals['__name__'],
caller.f_code.co_name,
)
tmp = os.path.join(tmp, name)
try:
shutil.rmtree(tmp)
except OSError, e:
if e.errno == errno.ENOENT:
pass
else:
raise
os.mkdir(tmp)
return tmp
def writeFile(path, content):