MCPcopy
hub / github.com/pyodide/pyodide / test_pyproxy_class

Function test_pyproxy_class

src/tests/test_pyproxy.py:9–83  ·  view source on GitHub ↗
(selenium)

Source from the content-addressed store, hash-verified

7
8@run_in_pyodide
9def test_pyproxy_class(selenium):
10 from pyodide.code import run_js
11
12 class Foo:
13 bar = 42
14
15 def get_value(self, value):
16 return value * 64
17
18 f = Foo()
19
20 run_js(
21 """
22 (f) => {
23 assert(() => f.type === "Foo");
24 let f_get_value = f.get_value
25 assert(() => f_get_value(2) === 128);
26 f_get_value.destroy();
27 assert(() => f.bar === 42);
28 assert(() => 'bar' in f);
29 f.baz = 32;
30 assert(() => f.baz === 32);
31 }
32 """
33 )(f)
34 assert hasattr(f, "baz")
35 f_props = run_js(
36 """
37 (f) => {
38 let f_props = Object.getOwnPropertyNames(f);
39 delete f.baz;
40 return f_props;
41 }
42 """
43 )(f)
44 assert not hasattr(f, "baz")
45 run_js(
46 """
47 (f) => {
48 assert(() => f.toString().startsWith("<Foo"));
49 }
50 """
51 )(f)
52
53 assert {
54 "__class__",
55 "__delattr__",
56 "__dict__",
57 "__dir__",
58 "__doc__",
59 "__eq__",
60 "__format__",
61 "__ge__",
62 "__getattribute__",
63 "__gt__",
64 "__hash__",
65 "__init__",
66 "__init_subclass__",

Callers

nothing calls this directly

Calls 3

run_jsFunction · 0.90
FooClass · 0.85
setFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…