##// END OF EJS Templates
validate ESC_PAREN ('/') is followed by a callable name and not empty (#12690)...
validate ESC_PAREN ('/') is followed by a callable name and not empty (#12690) When running a single python expression with just a slash - `/`, a tuple is returned. ```python In [1]: / Out[1]: () ``` This weird case happens because when a line starts with `/` the `inputtransformer` transforms it into a call of the first word after the `/` as the callable name and rest tokens after as arguments. This PR fixes that issue by validating that at least a callable name is given and it's not empty, if not a `SyntaxError` will be raised. ```python In [1]: / File "<ipython-input-1-8f27084b6294>", line 1 / ^ SyntaxError: invalid syntax In [2]: ``` Validated that tests are passing.

File last commit:

r28819:8fb51573
r28936:b65cf89c merge
Show More
test_splitinput.py
41 lines | 1.2 KiB | text/x-python | PythonLexer
/ IPython / core / tests / test_splitinput.py
Thomas Kluyver
Update split_user_input unicode test.
r4769 # coding: utf-8
Thomas Kluyver
Remove unused imports from IPython.core
r11124
from IPython.core.splitinput import split_user_input, LineInfo
M Bussonnier
Fix autocall runs on getitem....
r28819
import pytest
Thomas Kluyver
Reuse common code for inputsplitter and prefilter.
r4746
tests = [
Samuel Gaist
[core][tests][splitinput] Remove nose
r26909 ("x=1", ("", "", "x", "=1")),
("?", ("", "?", "", "")),
("??", ("", "??", "", "")),
(" ?", (" ", "?", "", "")),
(" ??", (" ", "??", "", "")),
("??x", ("", "??", "x", "")),
("?x=1", ("", "?", "x", "=1")),
("!ls", ("", "!", "ls", "")),
(" !ls", (" ", "!", "ls", "")),
("!!ls", ("", "!!", "ls", "")),
(" !!ls", (" ", "!!", "ls", "")),
(",ls", ("", ",", "ls", "")),
(";ls", ("", ";", "ls", "")),
(" ;ls", (" ", ";", "ls", "")),
("f.g(x)", ("", "", "f.g", "(x)")),
M Bussonnier
Fix autocall runs on getitem....
r28819 ("f.g (x)", ("", "", "f.g", " (x)")),
Samuel Gaist
[core][tests][splitinput] Remove nose
r26909 ("?%hist1", ("", "?", "%hist1", "")),
("?%%hist2", ("", "?", "%%hist2", "")),
("??%hist3", ("", "??", "%hist3", "")),
("??%%hist4", ("", "??", "%%hist4", "")),
("?x*", ("", "?", "x*", "")),
M Bussonnier
Fix autocall runs on getitem....
r28819 ("Pérez Fernando", ("", "", "Pérez", " Fernando")),
Samuel Gaist
[core][tests][splitinput] Remove nose
r26909 ]
Thomas Kluyver
Reuse common code for inputsplitter and prefilter.
r4746
M Bussonnier
Fix autocall runs on getitem....
r28819 @pytest.mark.parametrize("input, output", tests)
def test_split_user_input(input, output):
assert split_user_input(input) == output
Thomas Kluyver
Remove unused imports from IPython.core
r11124
Matthias Bussonnier
MAINT: run black on files that ends up in a single line change....
r27747
Thomas Kluyver
Remove unused imports from IPython.core
r11124 def test_LineInfo():
"""Simple test for LineInfo construction and str()"""
Samuel Gaist
[core][tests][splitinput] Remove nose
r26909 linfo = LineInfo(" %cd /home")
assert str(linfo) == "LineInfo [ |%|cd|/home]"