File: test_expose.py

package info (click to toggle)
python-pywebview 3.3.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid
  • size: 29,536 kB
  • sloc: python: 5,703; javascript: 888; cs: 130; sh: 55; makefile: 3
file content (58 lines) | stat: -rw-r--r-- 1,329 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
from concurrent.futures.thread import ThreadPoolExecutor
import webview
from .util import run_test, assert_js


def test_expose_single():
    window = webview.create_window('JSBridge test', html='<html><body>TEST</body></html>')
    window.expose(get_int)
    run_test(webview, window, expose_single)


def test_expose_multiple():
    window = webview.create_window('JSBridge test', html='<html><body>TEST</body></html>')
    window.expose(get_int, get_float)
    run_test(webview, window, expose_multiple)


def test_expose_runtime():
    window = webview.create_window('JSBridge test', html='<html><body>TEST</body></html>')
    run_test(webview, window, expose_runtime)


def test_override():
    api = Api()
    window = webview.create_window('JSBridge test', js_api=api)
    window.expose(get_int)
    run_test(webview, window, expose_override)


def get_int():
    return 420


def get_float():
    return 420.420


class Api:
    def get_int(self):
        return 421


def expose_single(window):
    assert_js(window, 'get_int', 420)


def expose_multiple(window):
    assert_js(window, 'get_int', 420)
    assert_js(window, 'get_float', 420.420)


def expose_runtime(window):
    window.expose(get_int, get_float)
    assert_js(window, 'get_int', 420)


def expose_override(window):
    assert_js(window, 'get_int', 420)