forked from ipython/ipython
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ipython#2232 from takluyver/i1456
Reapply monkeypatch to inspect.findsource()
- Loading branch information
Showing
3 changed files
with
69 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Tests for IPython.core.ultratb | ||
""" | ||
|
||
import os.path | ||
import unittest | ||
|
||
from IPython.testing import tools as tt | ||
from IPython.utils.syspathcontext import prepended_to_syspath | ||
from IPython.utils.tempdir import TemporaryDirectory | ||
|
||
ip = get_ipython() | ||
|
||
file_1 = """1 | ||
2 | ||
3 | ||
def f(): | ||
1/0 | ||
""" | ||
|
||
file_2 = """def f(): | ||
1/0 | ||
""" | ||
|
||
class ChangedPyFileTest(unittest.TestCase): | ||
def test_changing_py_file(self): | ||
"""Traceback produced if the line where the error occurred is missing? | ||
https://github.com/ipython/ipython/issues/1456 | ||
""" | ||
with TemporaryDirectory() as td: | ||
fname = os.path.join(td, "foo.py") | ||
with open(fname, "w") as f: | ||
f.write(file_1) | ||
|
||
with prepended_to_syspath(td): | ||
ip.run_cell("import foo") | ||
|
||
with tt.AssertPrints("ZeroDivisionError"): | ||
ip.run_cell("foo.f()") | ||
|
||
# Make the file shorter, so the line of the error is missing. | ||
with open(fname, "w") as f: | ||
f.write(file_2) | ||
|
||
# For some reason, this was failing on the *second* call after | ||
# changing the file, so we call f() twice. | ||
with tt.AssertNotPrints("Internal Python error", channel='stderr'): | ||
with tt.AssertPrints("ZeroDivisionError"): | ||
ip.run_cell("foo.f()") | ||
with tt.AssertPrints("ZeroDivisionError"): | ||
ip.run_cell("foo.f()") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters