File
Blob: src/workerd/server/tests/python/hello/worker.py
| 1 | import js |
| 2 | from js import console, globalThis |
| 3 | |
| 4 | from pyodide import __version__ |
| 5 | from pyodide.ffi import JsException |
| 6 | |
| 7 | if __version__ == "0.26.0a2": |
| 8 | assert js == globalThis |
| 9 | else: |
| 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. |
| 14 | try: |
| 15 | js.fetch("example.com") |
| 16 | except JsException as e: |
| 17 | print(e) |
| 18 | assert "Disallowed operation called within global scope" in str(e) |
| 19 | else: |
| 20 | assert False # noqa: B011 |
| 21 | |
| 22 | |
| 23 | def 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 |