| 1 |
"""These kinds of tests are less than ideal, but at least they run. |
| 2 |
|
| 3 |
This was an old test that was being run interactively in the top-level tests/ |
| 4 |
directory, which we are removing. For now putting this here ensures at least |
| 5 |
we do run the test, though ultimately this functionality should all be tested |
| 6 |
with better-isolated tests that don't rely on the global instance in iptest. |
| 7 |
""" |
| 8 |
|
| 9 |
from IPython.core.splitinput import LineInfo |
| 10 |
from IPython.core.prefilter import AutocallChecker |
| 11 |
|
| 12 |
|
| 13 |
def doctest_autocall(): |
| 14 |
""" |
| 15 |
In [1]: def f1(a,b,c): |
| 16 |
...: return a+b+c |
| 17 |
...: |
| 18 |
|
| 19 |
In [2]: def f2(a): |
| 20 |
...: return a + a |
| 21 |
...: |
| 22 |
|
| 23 |
In [3]: def r(x): |
| 24 |
...: return True |
| 25 |
...: |
| 26 |
|
| 27 |
In [4]: ;f2 a b c |
| 28 |
Out[4]: 'a b ca b c' |
| 29 |
|
| 30 |
In [5]: assert _ == "a b ca b c" |
| 31 |
|
| 32 |
In [6]: ,f1 a b c |
| 33 |
Out[6]: 'abc' |
| 34 |
|
| 35 |
In [7]: assert _ == 'abc' |
| 36 |
|
| 37 |
In [8]: print(_) |
| 38 |
abc |
| 39 |
|
| 40 |
In [9]: /f1 1,2,3 |
| 41 |
Out[9]: 6 |
| 42 |
|
| 43 |
In [10]: assert _ == 6 |
| 44 |
|
| 45 |
In [11]: /f2 4 |
| 46 |
Out[11]: 8 |
| 47 |
|
| 48 |
In [12]: assert _ == 8 |
| 49 |
|
| 50 |
In [12]: del f1, f2 |
| 51 |
|
| 52 |
In [13]: ,r a |
| 53 |
Out[13]: True |
| 54 |
|
| 55 |
In [14]: assert _ == True |
| 56 |
|
| 57 |
In [15]: r'a' |
| 58 |
Out[15]: 'a' |
| 59 |
|
| 60 |
In [16]: assert _ == 'a' |
| 61 |
""" |
| 62 |
|
| 63 |
|
| 64 |
def test_autocall_should_ignore_raw_strings(): |
| 65 |
line_info = LineInfo("r'a'") |
| 66 |
pm = ip.prefilter_manager |
| 67 |
ac = AutocallChecker(shell=pm.shell, prefilter_manager=pm, config=pm.config) |
| 68 |
assert ac.check(line_info) is None |