##// END OF EJS Templates
Use TemporaryWorkingDirectory context manager in some tests
Thomas Kluyver -
Show More
@@ -15,7 +15,7 b' import nose.tools as nt'
15 from IPython.config.loader import Config
15 from IPython.config.loader import Config
16 from IPython.core import completer
16 from IPython.core import completer
17 from IPython.external.decorators import knownfailureif
17 from IPython.external.decorators import knownfailureif
18 from IPython.utils.tempdir import TemporaryDirectory
18 from IPython.utils.tempdir import TemporaryDirectory, TemporaryWorkingDirectory
19 from IPython.utils.generics import complete_object
19 from IPython.utils.generics import complete_object
20 from IPython.utils import py3compat
20 from IPython.utils import py3compat
21 from IPython.utils.py3compat import string_types, unicode_type
21 from IPython.utils.py3compat import string_types, unicode_type
@@ -189,28 +189,22 b' def test_abspath_file_completions():'
189
189
190 def test_local_file_completions():
190 def test_local_file_completions():
191 ip = get_ipython()
191 ip = get_ipython()
192 cwd = py3compat.getcwd()
192 with TemporaryWorkingDirectory():
193 try:
193 prefix = './foo'
194 with TemporaryDirectory() as tmpdir:
194 suffixes = ['1', '2']
195 os.chdir(tmpdir)
195 names = [prefix+s for s in suffixes]
196 prefix = './foo'
196 for n in names:
197 suffixes = ['1', '2']
197 open(n, 'w').close()
198 names = [prefix+s for s in suffixes]
198
199 for n in names:
199 # Check simple completion
200 open(n, 'w').close()
200 c = ip.complete(prefix)[1]
201
201 nt.assert_equal(c, names)
202 # Check simple completion
202
203 c = ip.complete(prefix)[1]
203 # Now check with a function call
204 nt.assert_equal(c, names)
204 cmd = 'a = f("%s' % prefix
205
205 c = ip.complete(prefix, cmd)[1]
206 # Now check with a function call
206 comp = [prefix+s for s in suffixes]
207 cmd = 'a = f("%s' % prefix
207 nt.assert_equal(c, comp)
208 c = ip.complete(prefix, cmd)[1]
209 comp = [prefix+s for s in suffixes]
210 nt.assert_equal(c, comp)
211 finally:
212 # prevent failures from making chdir stick
213 os.chdir(cwd)
214
208
215
209
216 def test_greedy_completions():
210 def test_greedy_completions():
@@ -8,7 +8,7 b' import os'
8 from IPython.testing import tools as tt, decorators as dec
8 from IPython.testing import tools as tt, decorators as dec
9 from IPython.core.prompts import PromptManager, LazyEvaluate
9 from IPython.core.prompts import PromptManager, LazyEvaluate
10 from IPython.testing.globalipapp import get_ipython
10 from IPython.testing.globalipapp import get_ipython
11 from IPython.utils.tempdir import TemporaryDirectory
11 from IPython.utils.tempdir import TemporaryWorkingDirectory
12 from IPython.utils import py3compat
12 from IPython.utils import py3compat
13 from IPython.utils.py3compat import unicode_type
13 from IPython.utils.py3compat import unicode_type
14
14
@@ -67,13 +67,10 b' class PromptTests(unittest.TestCase):'
67
67
68 @dec.onlyif_unicode_paths
68 @dec.onlyif_unicode_paths
69 def test_render_unicode_cwd(self):
69 def test_render_unicode_cwd(self):
70 save = py3compat.getcwd()
70 with TemporaryWorkingDirectory(u'ünicødé'):
71 with TemporaryDirectory(u'ünicødé') as td:
72 os.chdir(td)
73 self.pm.in_template = r'\w [\#]'
71 self.pm.in_template = r'\w [\#]'
74 p = self.pm.render('in', color=False)
72 p = self.pm.render('in', color=False)
75 self.assertEqual(p, u"%s [%i]" % (py3compat.getcwd(), ip.execution_count))
73 self.assertEqual(p, u"%s [%i]" % (py3compat.getcwd(), ip.execution_count))
76 os.chdir(save)
77
74
78 def test_lazy_eval_unicode(self):
75 def test_lazy_eval_unicode(self):
79 u = u'ünicødé'
76 u = u'ünicødé'
General Comments 0
You need to be logged in to leave comments. Login now