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_install():
client.delete_web_modules(["jquery"], skip_missing=True)
client.install("jquery")
assert client.web_module_exists("jquery")
assert client.web_module_exists("/jquery") # works with a leading slash too
assert "jquery" in client.installed()
with assert_file_is_touched(client.web_module_path("jquery")):
client.install("jquery", force=True)
with pytest.raises(ValueError, match="already exists"):
# can't register a module with the same name
client.register_web_module("jquery", Path() / "some-module.js")
client.delete_web_modules("jquery")
assert not client.web_module_exists("jquery")
assert "jquery" not in client.installed()
def test_install_namespace_package():
client.install("@material-ui/core")
assert client.web_module_exists("@material-ui/core")
expected = "../web_modules/@material-ui/core.js"
assert client.web_module_url("@material-ui/core") == expected
def test_install_with_exports(capsys):
client.delete_web_modules(["preact", "preact/hooks"], skip_missing=True)
main("install", "preact", "--exports", "preact/hooks")
assert client.web_module_exists("preact/hooks")
main("installed")
captured = capsys.readouterr()
assert "- preact" in captured.out
assert "- preact/hooks" in captured.out
main("uninstall", "preact")
assert not client.web_module_exists("preact/hooks")
main("installed")
captured = capsys.readouterr()
assert "- preact" not in captured.out
assert "- preact/hooks" not in captured.out
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)
def test_custom_module(driver, display, victory):
my_chart = Module("my/chart", source=HERE / "my_chart.js")
assert client.web_module_exists("my/chart")
assert client.web_module_url("my/chart") == "../web_modules/my/chart.js"
display(my_chart.Import("Chart"))
driver.find_element_by_class_name("VictoryContainer")
my_chart.delete()
assert not client.web_module_exists("my/chart")
def test_install():
client.delete_web_modules(["jquery"], skip_missing=True)
client.install("jquery")
assert client.web_module_exists("jquery")
assert client.web_module_exists("/jquery") # works with a leading slash too
assert "jquery" in client.installed()
with assert_file_is_touched(client.web_module_path("jquery")):
client.install("jquery", force=True)
with pytest.raises(ValueError, match="already exists"):
# can't register a module with the same name
client.register_web_module("jquery", Path() / "some-module.js")
client.delete_web_modules("jquery")
assert not client.web_module_exists("jquery")
assert "jquery" not in client.installed()
def test_delete_module(victory):
victory.delete()
assert not client.web_module_exists("victory")
with pytest.raises(ValueError, match="does not exist"):
victory.delete()
def test_simple_install(capsys):
client.delete_web_modules("jquery", skip_missing=True)
main("install", "jquery")
assert client.web_module_exists("jquery")
main("installed")
captured = capsys.readouterr()
assert "- jquery" in captured.out
with assert_file_is_touched(client.web_module_path("jquery")):
main("install", "jquery", "--force")
assert client.web_module_exists("jquery")
main("uninstall", "jquery")
assert not client.web_module_exists("jquery")