Show More
@@ -207,9 +207,16 class TestMagicRunPass(tt.TempFileMixin): | |||
|
207 | 207 | def test_run_profile( self ): |
|
208 | 208 | """Test that the option -p, which invokes the profiler, do not |
|
209 | 209 | crash by invoking execfile""" |
|
210 | get_ipython() | |
|
211 | 210 | self.run_tmpfile_p() |
|
212 | 211 | |
|
212 | def test_run_debug_twice(self): | |
|
213 | # https://github.com/ipython/ipython/issues/10028 | |
|
214 | _ip = get_ipython() | |
|
215 | with tt.fake_input(['c']): | |
|
216 | _ip.magic('run -d %s' % self.fname) | |
|
217 | with tt.fake_input(['c']): | |
|
218 | _ip.magic('run -d %s' % self.fname) | |
|
219 | ||
|
213 | 220 | |
|
214 | 221 | class TestMagicRunSimple(tt.TempFileMixin): |
|
215 | 222 |
@@ -6,16 +6,8 Authors | |||
|
6 | 6 | """ |
|
7 | 7 | |
|
8 | 8 | |
|
9 | #----------------------------------------------------------------------------- | |
|
10 | # Copyright (C) 2009 The IPython Development Team | |
|
11 | # | |
|
12 | # Distributed under the terms of the BSD License. The full license is in | |
|
13 | # the file COPYING, distributed as part of this software. | |
|
14 | #----------------------------------------------------------------------------- | |
|
15 | ||
|
16 | #----------------------------------------------------------------------------- | |
|
17 | # Imports | |
|
18 | #----------------------------------------------------------------------------- | |
|
9 | # Copyright (c) IPython Development Team. | |
|
10 | # Distributed under the terms of the Modified BSD License. | |
|
19 | 11 | |
|
20 | 12 | import os |
|
21 | 13 | import re |
@@ -25,6 +17,7 import tempfile | |||
|
25 | 17 | from contextlib import contextmanager |
|
26 | 18 | from io import StringIO |
|
27 | 19 | from subprocess import Popen, PIPE |
|
20 | from unittest.mock import patch | |
|
28 | 21 | |
|
29 | 22 | try: |
|
30 | 23 | # These tools are used by parts of the runtime, so we make the nose |
@@ -45,9 +38,6 from IPython.utils.encoding import DEFAULT_ENCODING | |||
|
45 | 38 | from . import decorators as dec |
|
46 | 39 | from . import skipdoctest |
|
47 | 40 | |
|
48 | #----------------------------------------------------------------------------- | |
|
49 | # Functions and classes | |
|
50 | #----------------------------------------------------------------------------- | |
|
51 | 41 | |
|
52 | 42 | # The docstring for full_path doctests differently on win32 (different path |
|
53 | 43 | # separator) so just skip the doctest there. The example remains informative. |
@@ -443,6 +433,25 def make_tempfile(name): | |||
|
443 | 433 | finally: |
|
444 | 434 | os.unlink(name) |
|
445 | 435 | |
|
436 | def fake_input(inputs): | |
|
437 | """Temporarily replace the input() function to return the given values | |
|
438 | ||
|
439 | Use as a context manager: | |
|
440 | ||
|
441 | with fake_input(['result1', 'result2']): | |
|
442 | ... | |
|
443 | ||
|
444 | Values are returned in order. If input() is called again after the last value | |
|
445 | was used, EOFError is raised. | |
|
446 | """ | |
|
447 | it = iter(inputs) | |
|
448 | def mock_input(prompt=''): | |
|
449 | try: | |
|
450 | return next(it) | |
|
451 | except StopIteration: | |
|
452 | raise EOFError('No more inputs given') | |
|
453 | ||
|
454 | return patch('builtins.input', mock_input) | |
|
446 | 455 | |
|
447 | 456 | def help_output_test(subcommand=''): |
|
448 | 457 | """test that `ipython [subcommand] -h` works""" |
General Comments 0
You need to be logged in to leave comments.
Login now