##// END OF EJS Templates
moved TemporaryWorkingDir into utils.tempdir
Paul Ivanov -
Show More
@@ -18,7 +18,7 b' import glob'
18 import shutil
18 import shutil
19
19
20 import IPython
20 import IPython
21 from IPython.utils.tempdir import TemporaryDirectory
21 from IPython.utils.tempdir import TemporaryWorkingDirectory
22 from IPython.utils.process import get_output_error_code
22 from IPython.utils.process import get_output_error_code
23 from IPython.testing.tools import get_ipython_cmd
23 from IPython.testing.tools import get_ipython_cmd
24
24
@@ -29,38 +29,6 b' ipy_cmd = get_ipython_cmd(as_string=True) + " "'
29 # Classes and functions
29 # Classes and functions
30 #-----------------------------------------------------------------------------
30 #-----------------------------------------------------------------------------
31
31
32 class TemporaryWorkingDirectory(TemporaryDirectory):
33 """
34 Creates a temporary directory and sets the cwd to that directory.
35 Automatically reverts to previous cwd upon cleanup.
36 Usage example:
37
38 with TemporaryWorakingDirectory() as tmpdir:
39 ...
40 """
41
42 def __init__(self, **kw):
43 """
44 Constructor
45 """
46 super(TemporaryWorkingDirectory, self).__init__(**kw)
47
48 #Change cwd to new temp dir. Remember old cwd.
49 self.old_wd = os.getcwd()
50 os.chdir(self.name)
51
52
53 def cleanup(self):
54 """
55 Destructor
56 """
57
58 #Revert to old cwd.
59 os.chdir(self.old_wd)
60
61 #Cleanup
62 super(TemporaryWorkingDirectory, self).cleanup()
63
64
32
65 class TestsBase(object):
33 class TestsBase(object):
66 """Base tests class. Contains usefull fuzzy comparison and nbconvert
34 """Base tests class. Contains usefull fuzzy comparison and nbconvert
@@ -104,3 +104,29 b' class NamedFileInTemporaryDirectory(object):'
104
104
105 def __exit__(self, type, value, traceback):
105 def __exit__(self, type, value, traceback):
106 self.cleanup()
106 self.cleanup()
107
108
109 class TemporaryWorkingDirectory(TemporaryDirectory):
110 """
111 Creates a temporary directory and sets the cwd to that directory.
112 Automatically reverts to previous cwd upon cleanup.
113 Usage example:
114
115 with TemporaryWorakingDirectory() as tmpdir:
116 ...
117 """
118
119 def __init__(self, **kw):
120 super(TemporaryWorkingDirectory, self).__init__(**kw)
121
122 #Change cwd to new temp dir. Remember old cwd.
123 self.old_wd = _os.getcwd()
124 _os.chdir(self.name)
125
126
127 def cleanup(self):
128 #Revert to old cwd.
129 _os.chdir(self.old_wd)
130
131 #Cleanup
132 super(TemporaryWorkingDirectory, self).cleanup()
General Comments 0
You need to be logged in to leave comments. Login now