Skip to content

Commit 547c9a5

Browse files
committed
fix tests
1 parent 8f82227 commit 547c9a5

File tree

6 files changed

+56
-37
lines changed

6 files changed

+56
-37
lines changed

docs/source/exts/widget_example.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,6 @@ def run(self):
3737
self.state_machine,
3838
).run()
3939

40-
example_tab = TabbedDirective(
41-
"WidgetExample",
42-
["Live Example"],
43-
{},
44-
StringList(
45-
[
46-
"",
47-
f" .. interactive-widget:: {example_name}",
48-
"",
49-
]
50-
),
51-
self.lineno - 1,
52-
self.content_offset,
53-
"",
54-
self.state,
55-
self.state_machine,
56-
).run()
57-
5840
if (examples / f"{example_name}.js").exists():
5941
js_code_tab = TabbedDirective(
6042
"WidgetExample",
@@ -77,7 +59,25 @@ def run(self):
7759
else:
7860
js_code_tab = []
7961

80-
return py_code_tab + example_tab + js_code_tab
62+
example_tab = TabbedDirective(
63+
"WidgetExample",
64+
["Live Example"],
65+
{},
66+
StringList(
67+
[
68+
"",
69+
f" .. interactive-widget:: {example_name}",
70+
"",
71+
]
72+
),
73+
self.lineno - 1,
74+
self.content_offset,
75+
"",
76+
self.state,
77+
self.state_machine,
78+
).run()
79+
80+
return py_code_tab + js_code_tab + example_tab
8181

8282

8383
def setup(app: Sphinx) -> None:

idom/client/manage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def register_web_module(name: str, source: Union[str, Path]) -> str:
4343
if web_module_exists(name):
4444
raise ValueError(f"Web module {name} already exists")
4545
if not source_path.is_file():
46-
raise ValueError(f"Web modules source {source} does not exist or is not a file")
46+
raise ValueError(f"Web module source {source} does not exist or is not a file")
4747
STATIC_SHIMS[f"web_modules/{name}.js"] = source_path
4848
return web_module_url(name)
4949

@@ -140,6 +140,7 @@ class Cache:
140140
__slots__ = "_file", "package_list", "export_list"
141141

142142
def __init__(self, path: Path) -> None:
143+
path.mkdir(parents=True, exist_ok=True)
143144
self._file = path / ".idom-cache.json"
144145
if not self._file.exists():
145146
self.package_list: List[str] = []

tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import pyalect.builtins.pytest # noqa
1717

1818
import idom
19+
from idom.client.manage import restore as restore_client
1920
from idom.core import ElementConstructor, AbstractElement
2021
from idom.server import hotswap_server, AbstractRenderServer, find_available_port
2122
from idom.server.sanic import PerClientStateServer
@@ -274,8 +275,8 @@ def fresh_client(pytestconfig: Config) -> Iterator[None]:
274275
after testing and may effect usage of IDOM beyond the scope of the tests.
275276
"""
276277
if not pytestconfig.option.dirty_client:
277-
idom.client.restore()
278+
restore_client()
278279
yield
279-
idom.client.restore()
280+
restore_client()
280281
else:
281282
yield
File renamed without changes.

tests/test_client/test_module.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44
import idom
5-
from idom.client.manage import install, delete_web_modules
5+
from idom.client.manage import install, delete_web_modules, installed
66
from idom import Module, client
77

88

@@ -11,7 +11,7 @@
1111

1212
@pytest.fixture
1313
def victory():
14-
if "victory" not in client.installed():
14+
if "victory" not in installed():
1515
install(["victory"], [])
1616
return Module("victory")
1717

@@ -44,15 +44,15 @@ def test_reference_pre_installed_module(victory):
4444
def test_custom_module(driver, display, victory):
4545
my_chart = Module("my/chart", source_file=HERE / "my-chart.js")
4646

47-
assert client.web_module_exists("my/chart")
48-
assert client.web_module_url("my/chart") == "../web_modules/my/chart.js"
47+
assert client.current.web_module_exists("my/chart")
48+
assert client.current.web_module_url("my/chart") == "../web_modules/my/chart.js"
4949

5050
display(my_chart.Import("Chart"))
5151

5252
driver.find_element_by_class_name("VictoryContainer")
5353

5454
delete_web_modules("my/chart")
55-
assert not client.web_module_exists("my/chart")
55+
assert not client.current.web_module_exists("my/chart")
5656

5757

5858
def test_module_from_url():
@@ -63,4 +63,22 @@ def test_module_from_url():
6363

6464

6565
def test_module_uses_current_client_implementation():
66-
assert False
66+
class MmockClientImplementation:
67+
exists_return = True
68+
69+
def register_web_module(self, name, source):
70+
self.saved_module = (name, source)
71+
72+
def web_module_exists(self, name):
73+
return name == "fake-name"
74+
75+
def web_module_url(self, name):
76+
return f"./mock/url/to/module-{name}.js"
77+
78+
client.current = MmockClientImplementation()
79+
80+
assert Module("fake-name").url == "./mock/url/to/module-fake-name.js"
81+
82+
Module("some-other-name", source_file="fake/path/to/module.js")
83+
84+
assert client.current.saved_module == ("some-other-name", "fake/path/to/module.js")

tests/test_main.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,38 @@
22

33
from idom.__main__ import main
44
from idom import client
5+
from idom.client.manage import delete_web_modules, installed
56

67
from tests.general_utils import assert_same_items
78

89

910
@pytest.mark.slow
1011
def test_simple_install(capsys):
11-
client.delete_web_modules("jquery", skip_missing=True)
12+
delete_web_modules("jquery", skip_missing=True)
1213

1314
main("install", "jquery")
14-
assert client.web_module_exists("jquery")
15+
assert client.current.web_module_exists("jquery")
1516
main("installed")
1617
captured = capsys.readouterr()
1718
assert "- jquery" in captured.out
1819

1920
main("uninstall", "jquery")
20-
assert not client.web_module_exists("jquery")
21+
assert not client.current.web_module_exists("jquery")
2122

2223

2324
@pytest.mark.slow
2425
def test_install_with_exports(capsys):
25-
client.delete_web_modules(["preact", "preact/hooks"], skip_missing=True)
26+
delete_web_modules(["preact", "preact/hooks"], skip_missing=True)
2627

2728
main("install", "preact", "--exports", "preact/hooks")
28-
assert client.web_module_exists("preact/hooks")
29+
assert client.current.web_module_exists("preact/hooks")
2930
main("installed")
3031
captured = capsys.readouterr()
3132
assert "- preact" in captured.out
3233
assert "- preact/hooks" in captured.out
3334

3435
main("uninstall", "preact")
35-
assert not client.web_module_exists("preact/hooks")
36+
assert not client.current.web_module_exists("preact/hooks")
3637
main("installed")
3738
captured = capsys.readouterr()
3839
assert "- preact" not in captured.out
@@ -42,9 +43,7 @@ def test_install_with_exports(capsys):
4243
@pytest.mark.slow
4344
def test_restore(capsys):
4445
main("restore")
45-
assert_same_items(
46-
client.installed(), ["fast-json-patch", "htm", "react", "react-dom"]
47-
)
46+
assert_same_items(installed(), ["fast-json-patch", "htm", "react", "react-dom"])
4847

4948

5049
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)