Skip to content

Commit 7f12586

Browse files
committed
test web module exports
1 parent 3f26e07 commit 7f12586

File tree

5 files changed

+117
-15
lines changed

5 files changed

+117
-15
lines changed

docs/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"@material-ui/core",
1717
"victory",
1818
"semantic-ui-react",
19+
"jquery",
1920
]
2021
}
2122

idom/client/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ def open_modifiable_json(path: Path) -> Iterator[Any]:
1616
json.dump(data, f)
1717

1818

19-
_JS_MODULE_EXPORT_PATTERN = re.compile(r";export{(.*)};")
19+
_JS_MODULE_EXPORT_PATTERN = re.compile(r";export{(.*?)};")
20+
_JS_MODULE_EXPORT_NAME_PATTERN = re.compile(r";export (.*?) .*?;")
2021

2122

2223
def find_js_module_exports(path: Path) -> List[str]:
@@ -25,7 +26,9 @@ def find_js_module_exports(path: Path) -> List[str]:
2526
# we only know how to do this for javascript modules
2627
return []
2728
with path.open() as f:
28-
for match in _JS_MODULE_EXPORT_PATTERN.findall(f.read()):
29+
content = f.read()
30+
for match in _JS_MODULE_EXPORT_PATTERN.findall(content):
2931
for export in match.split(","):
3032
names.append(export.split(" as ", 1)[1].strip())
33+
names.extend(_JS_MODULE_EXPORT_NAME_PATTERN.findall(content))
3134
return names

idom/server/prefab.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from importlib import import_module
2-
from socket import socket
32
from typing import Any, Dict, Optional, Tuple, Type, TypeVar, cast
43

54
from idom.core.element import ElementConstructor
65
from idom.widgets.utils import multiview, hotswap, MultiViewMount, MountFunc
76

87
from .base import AbstractRenderServer
8+
from .utils import find_available_port
99

1010

1111
_S = TypeVar("_S", bound=AbstractRenderServer[Any, Any])
@@ -53,7 +53,7 @@ def run(
5353
if server_type is None: # pragma: no cover
5454
raise ValueError("No default server available.")
5555
if port is None: # pragma: no cover
56-
port = _find_available_port(host)
56+
port = find_available_port(host)
5757

5858
server = server_type(element, server_options)
5959

@@ -150,10 +150,3 @@ def hotswap_server(
150150
)
151151

152152
return mount, server
153-
154-
155-
def _find_available_port(host: str) -> int:
156-
"""Get a port that's available for the given host"""
157-
sock = socket()
158-
sock.bind((host, 0))
159-
return cast(int, sock.getsockname()[1])

idom/server/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from socket import socket
2+
from typing import cast
3+
4+
5+
def find_available_port(host: str) -> int:
6+
"""Get a port that's available for the given host"""
7+
sock = socket()
8+
sock.bind((host, 0))
9+
return cast(int, sock.getsockname()[1])

tests/test_client/test_manage.py

Lines changed: 100 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,114 @@
11
import pytest
22

3+
from idom.client.manage import web_module_url, web_module_exports, build, restore
34

4-
from idom.client.manage import web_module_url, build, restore
5+
from tests.general_utils import assert_same_items
56

67

78
@pytest.fixture(scope="module", autouse=True)
89
def _setup_build_for_tests():
9-
build([{"source_name": "tests", "js_dependencies": ["jquery"]}])
10+
build([{"source_name": "tests", "js_dependencies": ["victory@35.4.0"]}])
1011
try:
1112
yield
1213
finally:
1314
restore()
1415

1516

1617
def test_web_module_url():
17-
assert web_module_url("tests", "path/does/not/exist.js") is None
18-
assert web_module_url("tests", "jquery") == "../web_modules/jquery-tests-56e1841.js"
18+
assert web_module_url("tests", "does/not/exist") is None
19+
assert (
20+
web_module_url("tests", "victory") == "../web_modules/victory-tests-24fa38b.js"
21+
)
22+
23+
24+
def test_web_module_exports():
25+
assert web_module_exports("tests", "does/not/exist") == []
26+
assert_same_items(
27+
web_module_exports("tests", "victory"),
28+
[
29+
"Area",
30+
"Axis",
31+
"Background",
32+
"Bar",
33+
"Border",
34+
"Box",
35+
"BrushHelpers",
36+
"Candle",
37+
"Circle",
38+
"ClipPath",
39+
"Collection",
40+
"CursorHelpers",
41+
"Curve",
42+
"Data",
43+
"DefaultTransitions",
44+
"Domain",
45+
"ErrorBar",
46+
"Events",
47+
"Flyout",
48+
"Helpers",
49+
"LabelHelpers",
50+
"Line",
51+
"LineSegment",
52+
"Log",
53+
"Path",
54+
"Point",
55+
"Portal",
56+
"PropTypes",
57+
"RawZoomHelpers",
58+
"Rect",
59+
"Scale",
60+
"Selection",
61+
"SelectionHelpers",
62+
"Slice",
63+
"Style",
64+
"TSpan",
65+
"Text",
66+
"TextSize",
67+
"Transitions",
68+
"VictoryAnimation",
69+
"VictoryArea",
70+
"VictoryAxis",
71+
"VictoryBar",
72+
"VictoryBoxPlot",
73+
"VictoryBrushContainer",
74+
"VictoryBrushLine",
75+
"VictoryCandlestick",
76+
"VictoryChart",
77+
"VictoryClipContainer",
78+
"VictoryContainer",
79+
"VictoryCursorContainer",
80+
"VictoryErrorBar",
81+
"VictoryGroup",
82+
"VictoryHistogram",
83+
"VictoryLabel",
84+
"VictoryLegend",
85+
"VictoryLine",
86+
"VictoryPie",
87+
"VictoryPolarAxis",
88+
"VictoryPortal",
89+
"VictoryScatter",
90+
"VictorySelectionContainer",
91+
"VictorySharedEvents",
92+
"VictoryStack",
93+
"VictoryTheme",
94+
"VictoryTooltip",
95+
"VictoryTransition",
96+
"VictoryVoronoi",
97+
"VictoryVoronoiContainer",
98+
"VictoryZoomContainer",
99+
"Voronoi",
100+
"VoronoiHelpers",
101+
"Whisker",
102+
"Wrapper",
103+
"ZoomHelpers",
104+
"addEvents",
105+
"brushContainerMixin",
106+
"combineContainerMixins",
107+
"createContainer",
108+
"cursorContainerMixin",
109+
"makeCreateContainerFunction",
110+
"selectionContainerMixin",
111+
"voronoiContainerMixin",
112+
"zoomContainerMixin",
113+
],
114+
)

0 commit comments

Comments
 (0)