MCPcopy
hub / github.com/pyodide/pyodide / test_jsproxy_dir

Function test_jsproxy_dir

src/tests/test_jsproxy.py:13–68  ·  view source on GitHub ↗
(selenium)

Source from the content-addressed store, hash-verified

11
12@run_in_pyodide
13def test_jsproxy_dir(selenium):
14 from pyodide.code import run_js
15
16 run_js(
17 """
18 self.a = { x : 2, y : "9" };
19 self.b = function(){};
20 """
21 )
22
23 from js import a, b # type: ignore[attr-defined]
24
25 result = [dir(a), dir(b)]
26 jsproxy_items = {
27 "__bool__",
28 "__class__",
29 "__defineGetter__",
30 "__defineSetter__",
31 "__delattr__",
32 "constructor",
33 "toString",
34 "typeof",
35 "valueOf",
36 }
37 a_items = {"x", "y"}
38 callable_items = {"__call__", "new"}
39 set0 = set(result[0])
40 set1 = set(result[1])
41 assert set0.issuperset(jsproxy_items)
42 assert set0.isdisjoint(callable_items)
43 assert set0.issuperset(a_items)
44 assert set1.issuperset(jsproxy_items)
45 assert set1.issuperset(callable_items)
46 assert set1.isdisjoint(a_items)
47
48 run_js(
49 """
50 self.a = [0,1,2,3,4,5,6,7,8,9];
51 a[27] = 0;
52 a[":"] = 0;
53 a["/"] = 0;
54 a.abcd = 0;
55 a.α = 0;
56 """
57 )
58
59 from js import a # type: ignore[attr-defined]
60
61 d = dir(a)
62 assert "0" not in d
63 assert "9" not in d
64 assert "27" not in d
65 assert ":" in d
66 assert "/" in d
67 assert "abcd" in d
68 assert "α" in d
69
70

Callers

nothing calls this directly

Calls 2

run_jsFunction · 0.90
setFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…