-
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.
- Loading branch information
Showing
8 changed files
with
85 additions
and
1 deletion.
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,7 @@ | ||
"""Python Here Jupyter magic.""" | ||
from herethere.magic import load_ipython_extension | ||
|
||
from .magic_here import shortcuts # noqa | ||
|
||
|
||
__all__ = ("load_ipython_extension",) |
Empty file.
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,29 @@ | ||
"""%there magic Python code shortcuts.""" | ||
# pylint: disable=invalid-name | ||
|
||
import click | ||
from herethere.there.commands import there_code_shortcut | ||
|
||
KV_COMMAND_TEMPLATE = r""" | ||
from kivy.lang import Builder | ||
{unload_file} | ||
_pythonhere_new_root = Builder.load_string(r'''{code} ''', filename='_pythonhere') | ||
if _pythonhere_new_root: | ||
root.clear_widgets() | ||
root.add_widget(_pythonhere_new_root) | ||
del _pythonhere_new_root | ||
""" | ||
|
||
|
||
@there_code_shortcut | ||
@click.option( | ||
"-c", "--clear-style", is_flag=True, help="Unload previously applied rules." | ||
) | ||
def kv(code: str, clear_style: bool) -> str: | ||
"""Insert given rules into the Kivy Language Builder. | ||
:param code: KV language rules | ||
""" | ||
unload_file = "Builder.unload_file('_pythonhere')" if clear_style else "" | ||
code = code.replace("'''", '"""') | ||
return KV_COMMAND_TEMPLATE.format(code=code, unload_file=unload_file) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,10 @@ | |
"ifaddr", | ||
], | ||
extras_require={ | ||
"magic": [ | ||
"ipython", | ||
"ipywidgets", | ||
], | ||
"dev": [ | ||
"black", | ||
"codecov", | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pytest | ||
from herethere.there.commands import ContextObject | ||
|
||
from magic_here import shortcuts # noqa | ||
|
||
@pytest.mark.asyncio | ||
async def test_kv_command_runcode_called(call_there_group, mocker): | ||
runcode = mocker.patch.object(ContextObject, 'runcode', autospec=True) | ||
|
||
call_there_group(["kv"], "Label:") | ||
|
||
runcode.assert_called_once() | ||
ctx_obj = runcode.call_args[0][0] | ||
assert "Builder.load_string(r'''Label: '''" in ctx_obj.code | ||
|
||
@pytest.mark.asyncio | ||
async def test_kv_command_executed(capfd, app_instance, call_there_group): | ||
call_there_group(["kv"], "Label:\n text: '''Hello there'''") | ||
captured = capfd.readouterr() | ||
assert not captured.out and not captured.err | ||
assert app_instance.root.children[0].text == 'Hello there' |
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ envlist = py37,py38 | |
|
||
[testenv] | ||
extras = | ||
magic | ||
dev | ||
commands = | ||
./run_tests.sh | ||
|