Skip to content

Commit

Permalink
make (test) temporary file creation more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
d-maurer committed Oct 7, 2020
1 parent 7b5db2c commit d5816ed
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/OFS/tests/testObjectManager.py
Expand Up @@ -614,7 +614,6 @@ def test_export_import(self):
from transaction import commit
try:
tf = None # temporary file required for export/import
tdir_created = False
# export/import needs the object manager in ZODB
s = DemoStorage()
db = DB(s)
Expand All @@ -628,18 +627,15 @@ def test_export_import(self):
top._setObject(tmp.getId(), tmp)
commit()
exported = top.manage_exportObject("f", True)
if tempfile.tempdir is None: # pragma: no cover
tempfile.mktemp() # initialize `tempdir`
tdir = join(tempfile.tempdir, "import")
if not exists(tdir): # pragma: no cover
tdir_created = True
mkdir(tdir)
tdir = tempfile.mkdtemp()
idir = join(tdir, "import")
mkdir(idir)
tf = tempfile.NamedTemporaryFile(
dir=tdir, delete=False)
dir=idir, delete=False)
tf.write(exported)
tf.close()
unused, tname = split(tf.name)
tmp._getImportPaths = _CallResult((tempfile.tempdir,))
tmp._getImportPaths = _CallResult((tdir,))
tmp.manage_importObject(tname, set_owner=False,
suppress_events=True)
imp_f = tmp["f"] # exception if import unsuccessful
Expand All @@ -648,7 +644,7 @@ def test_export_import(self):
finally:
if tf is not None: # pragma: no cover
unlink(tf.name)
if tdir_created: # pragma: no cover
rmdir(idir)
rmdir(tdir)
c.close()
db.close()
Expand Down

0 comments on commit d5816ed

Please sign in to comment.