From 05c554c47e2882978e941730fee8c887f1bcf587 2014-02-19 18:18:49 From: Thomas Kluyver Date: 2014-02-19 18:18:49 Subject: [PATCH] Simplify implementation of TemporaryWorkingDirectory. Closes gh-5160 --- diff --git a/IPython/nbconvert/tests/base.py b/IPython/nbconvert/tests/base.py index 23f9123..5cd58a4 100644 --- a/IPython/nbconvert/tests/base.py +++ b/IPython/nbconvert/tests/base.py @@ -109,7 +109,7 @@ class TestsBase(unittest.TestCase): #Copy the files if requested. if copy_filenames is not None: - self.copy_files_to(copy_filenames) + self.copy_files_to(copy_filenames, dest=temp_dir.name) #Return directory handler return temp_dir diff --git a/IPython/utils/tempdir.py b/IPython/utils/tempdir.py index 0f27889..951abd6 100644 --- a/IPython/utils/tempdir.py +++ b/IPython/utils/tempdir.py @@ -131,21 +131,15 @@ class TemporaryWorkingDirectory(TemporaryDirectory): Automatically reverts to previous cwd upon cleanup. Usage example: - with TemporaryWorakingDirectory() as tmpdir: + with TemporaryWorkingDirectory() as tmpdir: ... """ - - def __init__(self, **kw): - super(TemporaryWorkingDirectory, self).__init__(**kw) - - #Change cwd to new temp dir. Remember old cwd. + def __enter__(self): self.old_wd = _os.getcwd() _os.chdir(self.name) + return super(TemporaryWorkingDirectory, self).__enter__() - - def cleanup(self, _warn=False): - #Revert to old cwd. + def __exit__(self, exc, value, tb): _os.chdir(self.old_wd) + return super(TemporaryWorkingDirectory, self).__exit__(exc, value, tb) - #Cleanup - super(TemporaryWorkingDirectory, self).cleanup(_warn=_warn)