Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 11b3db2

Browse files
committed
Add failing test for running %run -d twice
1 parent 67870ae commit 11b3db2

2 files changed

Lines changed: 30 additions & 14 deletions

File tree

IPython/core/tests/test_run.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,16 @@ def test_builtins_type(self):
207207
def test_run_profile( self ):
208208
"""Test that the option -p, which invokes the profiler, do not
209209
crash by invoking execfile"""
210-
get_ipython()
211210
self.run_tmpfile_p()
212211

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+
213220

214221
class TestMagicRunSimple(tt.TempFileMixin):
215222

IPython/testing/tools.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,8 @@
66
"""
77

88

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.
1911

2012
import os
2113
import re
@@ -25,6 +17,7 @@
2517
from contextlib import contextmanager
2618
from io import StringIO
2719
from subprocess import Popen, PIPE
20+
from unittest.mock import patch
2821

2922
try:
3023
# These tools are used by parts of the runtime, so we make the nose
@@ -45,9 +38,6 @@
4538
from . import decorators as dec
4639
from . import skipdoctest
4740

48-
#-----------------------------------------------------------------------------
49-
# Functions and classes
50-
#-----------------------------------------------------------------------------
5141

5242
# The docstring for full_path doctests differently on win32 (different path
5343
# separator) so just skip the doctest there. The example remains informative.
@@ -443,6 +433,25 @@ def make_tempfile(name):
443433
finally:
444434
os.unlink(name)
445435

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)
446455

447456
def help_output_test(subcommand=''):
448457
"""test that `ipython [subcommand] -h` works"""

0 commit comments

Comments
 (0)