Skip to content
File

Blob: src/workerd/server/tests/python/hello/worker.py

python32 lines
1import js
2from js import console, globalThis
3 
4from pyodide import __version__
5from pyodide.ffi import JsException
6 
7if __version__ == "0.26.0a2":
8 assert js == globalThis
9else:
10 # js should be patched at top level in order to allow snapshotting.
11 assert js != globalThis
12 
13# Calling fetch at top level should give a good error message despite patching.
14try:
15 js.fetch("example.com")
16except JsException as e:
17 print(e)
18 assert "Disallowed operation called within global scope" in str(e)
19else:
20 assert False # noqa: B011
21 
22 
23def test():
24 # js should be correctly restored when restoring snapshot
25 assert js == globalThis
26 
27 # This just tests that nothing raises when we run this. It isn't great though
28 # because we don't test whether we printed anything.
29 # TODO: update this to test that something happened
30 print("Does this work?")
31 console.log("Does this work?") # both should print the same output