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