parent
12f9742a0a
commit
bb64862303
|
@ -35,4 +35,6 @@ nosetests.xml
|
||||||
.pydevproject
|
.pydevproject
|
||||||
|
|
||||||
# Pycharm
|
# Pycharm
|
||||||
/.idea
|
/.idea
|
||||||
|
|
||||||
|
.venv
|
||||||
|
|
|
@ -4,6 +4,9 @@ Development setup
|
||||||
Running nose tests with IPython is tricky, so there's a
|
Running nose tests with IPython is tricky, so there's a
|
||||||
run_tests.sh script for it.
|
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()`
|
To temporarily insert breakpoints for debugging: `from nose.tools import set_trace; set_trace()`
|
||||||
|
|
||||||
Tests have requirements not installed by setup.py:
|
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)
|
# Parse variables (words wrapped in {}) for %%sql magic (for %sql this is done automatically)
|
||||||
cell_variables = [
|
cell = self.shell.var_expand(cell)
|
||||||
fn for _, fn, _, _ in Formatter().parse(cell) if fn is not None
|
|
||||||
]
|
# cell_variables = [
|
||||||
cell_params = {}
|
# fn for _, fn, _, _ in Formatter().parse(cell) if fn is not None
|
||||||
for variable in cell_variables:
|
# ]
|
||||||
if variable in local_ns:
|
# cell_params = {}
|
||||||
cell_params[variable] = local_ns[variable]
|
# for variable in cell_variables:
|
||||||
else:
|
# if variable in local_ns:
|
||||||
raise NameError(variable)
|
# cell_params[variable] = local_ns[variable]
|
||||||
cell = cell.format(**cell_params)
|
# else:
|
||||||
|
# raise NameError(variable)
|
||||||
|
# cell = cell.format(**cell_params)
|
||||||
|
|
||||||
line = sql.parse.without_sql_comment(parser=self.execute.parser, line=line)
|
line = sql.parse.without_sql_comment(parser=self.execute.parser, line=line)
|
||||||
args = parse_argstring(self.execute, line)
|
args = parse_argstring(self.execute, line)
|
||||||
|
|
|
@ -370,3 +370,20 @@ def test_multiline_bracket_var_substitution(ip):
|
||||||
""",
|
""",
|
||||||
)
|
)
|
||||||
assert not result
|
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