##// END OF EJS Templates
Simplify implementation of TemporaryWorkingDirectory....
Thomas Kluyver -
Show More
@@ -109,7 +109,7 b' class TestsBase(unittest.TestCase):'
109
109
110 #Copy the files if requested.
110 #Copy the files if requested.
111 if copy_filenames is not None:
111 if copy_filenames is not None:
112 self.copy_files_to(copy_filenames)
112 self.copy_files_to(copy_filenames, dest=temp_dir.name)
113
113
114 #Return directory handler
114 #Return directory handler
115 return temp_dir
115 return temp_dir
@@ -131,21 +131,15 b' class TemporaryWorkingDirectory(TemporaryDirectory):'
131 Automatically reverts to previous cwd upon cleanup.
131 Automatically reverts to previous cwd upon cleanup.
132 Usage example:
132 Usage example:
133
133
134 with TemporaryWorakingDirectory() as tmpdir:
134 with TemporaryWorkingDirectory() as tmpdir:
135 ...
135 ...
136 """
136 """
137
137 def __enter__(self):
138 def __init__(self, **kw):
139 super(TemporaryWorkingDirectory, self).__init__(**kw)
140
141 #Change cwd to new temp dir. Remember old cwd.
142 self.old_wd = _os.getcwd()
138 self.old_wd = _os.getcwd()
143 _os.chdir(self.name)
139 _os.chdir(self.name)
140 return super(TemporaryWorkingDirectory, self).__enter__()
144
141
145
142 def __exit__(self, exc, value, tb):
146 def cleanup(self, _warn=False):
147 #Revert to old cwd.
148 _os.chdir(self.old_wd)
143 _os.chdir(self.old_wd)
144 return super(TemporaryWorkingDirectory, self).__exit__(exc, value, tb)
149
145
150 #Cleanup
151 super(TemporaryWorkingDirectory, self).cleanup(_warn=_warn)
General Comments 0
You need to be logged in to leave comments. Login now