parent
12f9742a0a
commit
bb64862303
|
@ -35,4 +35,6 @@ nosetests.xml
|
|||
.pydevproject
|
||||
|
||||
# Pycharm
|
||||
/.idea
|
||||
/.idea
|
||||
|
||||
.venv
|
||||
|
|
|
@ -4,6 +4,9 @@ Development setup
|
|||
Running nose tests with IPython is tricky, so there's a
|
||||
run_tests.sh script for it.
|
||||
|
||||
pip install -e .
|
||||
./run_tests.sh
|
||||
|
||||
To temporarily insert breakpoints for debugging: `from nose.tools import set_trace; set_trace()`
|
||||
|
||||
Tests have requirements not installed by setup.py:
|
||||
|
|
|
@ -147,16 +147,18 @@ class SqlMagic(Magics, Configurable):
|
|||
|
||||
"""
|
||||
# Parse variables (words wrapped in {}) for %%sql magic (for %sql this is done automatically)
|
||||
cell_variables = [
|
||||
fn for _, fn, _, _ in Formatter().parse(cell) if fn is not None
|
||||
]
|
||||
cell_params = {}
|
||||
for variable in cell_variables:
|
||||
if variable in local_ns:
|
||||
cell_params[variable] = local_ns[variable]
|
||||
else:
|
||||
raise NameError(variable)
|
||||
cell = cell.format(**cell_params)
|
||||
cell = self.shell.var_expand(cell)
|
||||
|
||||
# cell_variables = [
|
||||
# fn for _, fn, _, _ in Formatter().parse(cell) if fn is not None
|
||||
# ]
|
||||
# cell_params = {}
|
||||
# for variable in cell_variables:
|
||||
# if variable in local_ns:
|
||||
# cell_params[variable] = local_ns[variable]
|
||||
# else:
|
||||
# raise NameError(variable)
|
||||
# cell = cell.format(**cell_params)
|
||||
|
||||
line = sql.parse.without_sql_comment(parser=self.execute.parser, line=line)
|
||||
args = parse_argstring(self.execute, line)
|
||||
|
|
|
@ -370,3 +370,20 @@ def test_multiline_bracket_var_substitution(ip):
|
|||
""",
|
||||
)
|
||||
assert not result
|
||||
|
||||
def test_json_in_select(ip):
|
||||
# Variable expansion does not work within json, but
|
||||
# at least the two usages of curly braces do not collide
|
||||
ip.user_global_ns["person"] = "prince"
|
||||
result = ip.run_cell_magic(
|
||||
"sql",
|
||||
"",
|
||||
"""
|
||||
sqlite://
|
||||
SELECT
|
||||
'{"greeting": "Farewell sweet {person}"}'
|
||||
AS json
|
||||
""",
|
||||
)
|
||||
assert ('{"greeting": "Farewell sweet {person}"}',)
|
||||
|
||||
|
|
Loading…
Reference in New Issue