Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_reference_pre_installed_module(victory):
assert victory.url == idom.Module("victory").url
def test_module_cannot_have_source_and_install():
with pytest.raises(ValueError, match=r"Both .* were given."):
idom.Module("something", install="something", source=HERE / "something.js")
def test_module_from_url():
url = "https://code.jquery.com/jquery-3.5.0.js"
jquery = idom.Module(url)
assert jquery.url == url
with pytest.raises(ValueError, match="Module is not installed locally"):
jquery.name
with pytest.raises(ValueError, match="Module is not installed locally"):
jquery.delete()
def test_module_deletion():
# also test install
jquery = idom.Module("jquery", install="jquery@3.5.0")
assert idom.client.web_module_exists(jquery.name)
with idom.client.web_module_path(jquery.name).open() as f:
assert "jQuery JavaScript Library v3.5.0" in f.read()
jquery.delete()
assert not idom.client.web_module_exists(jquery.name)
import idom
semantic_ui = idom.Module("semantic-ui-react")
Button = semantic_ui.Import("Button")
semantic_ui_style = idom.html.link(
{
"rel": "stylesheet",
"href": "//cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css",
}
)
def pre_seperated(*args):
return idom.html.pre(
{"style": {"white-space": "pre-wrap"}}, "\n".join(map(str, args))
)
import idom
victory = idom.Module("victory")
VictoryBar = victory.Import("VictoryBar")
display(VictoryBar, {"style": {"parent": {"width": "500px"}}})
import json
from pathlib import Path
import idom
here = Path(__file__).parent
custom_chart_path = here / "custom_chart.js"
ClickableChart = idom.Module("chart", source=custom_chart_path).Import("ClickableChart")
data = [
{"x": 1, "y": 2},
{"x": 2, "y": 4},
{"x": 3, "y": 7},
{"x": 4, "y": 3},
{"x": 5, "y": 5},
]
@idom.element
async def EventLog(self, event=None):
return idom.html.div(
{"class": "highlight"}, idom.html.pre(json.dumps(event, indent=2))
)