mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
Use <script type="py"> instead of <py-script> in most tests (#1723)
This is mostly a global search&replace, to replace <py-script> with <script type="py">. The vast majority of tests just works, some needed some tweak.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import pytest
|
||||
from .support import PyScriptTest, filter_inner_text
|
||||
|
||||
|
||||
@@ -5,7 +6,7 @@ class TestAsync(PyScriptTest):
|
||||
# ensure_future() and create_task() should behave similarly;
|
||||
# we'll use the same source code to test both
|
||||
coroutine_script = """
|
||||
<py-script>
|
||||
<script type="py">
|
||||
import js
|
||||
import asyncio
|
||||
js.console.log("first")
|
||||
@@ -14,7 +15,7 @@ class TestAsync(PyScriptTest):
|
||||
js.console.log("third")
|
||||
asyncio.{func}(main())
|
||||
js.console.log("second")
|
||||
</py-script>
|
||||
</script>
|
||||
"""
|
||||
|
||||
def test_asyncio_ensure_future(self):
|
||||
@@ -30,7 +31,7 @@ class TestAsync(PyScriptTest):
|
||||
def test_asyncio_gather(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script id="pys">
|
||||
<script type="py" id="pys">
|
||||
import asyncio
|
||||
import js
|
||||
from pyodide.ffi import to_js
|
||||
@@ -45,7 +46,7 @@ class TestAsync(PyScriptTest):
|
||||
js.console.log("DONE")
|
||||
|
||||
asyncio.ensure_future(get_results())
|
||||
</py-script>
|
||||
</script>
|
||||
"""
|
||||
)
|
||||
self.wait_for_console("DONE")
|
||||
@@ -54,7 +55,7 @@ class TestAsync(PyScriptTest):
|
||||
def test_multiple_async(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script>
|
||||
<script type="py">
|
||||
import js
|
||||
import asyncio
|
||||
async def a_func():
|
||||
@@ -62,9 +63,9 @@ class TestAsync(PyScriptTest):
|
||||
js.console.log('A', i)
|
||||
await asyncio.sleep(0.1)
|
||||
asyncio.ensure_future(a_func())
|
||||
</py-script>
|
||||
</script>
|
||||
|
||||
<py-script>
|
||||
<script type="py">
|
||||
import js
|
||||
import asyncio
|
||||
async def b_func():
|
||||
@@ -73,7 +74,7 @@ class TestAsync(PyScriptTest):
|
||||
await asyncio.sleep(0.1)
|
||||
js.console.log('b func done')
|
||||
asyncio.ensure_future(b_func())
|
||||
</py-script>
|
||||
</script>
|
||||
"""
|
||||
)
|
||||
self.wait_for_console("b func done")
|
||||
@@ -90,7 +91,7 @@ class TestAsync(PyScriptTest):
|
||||
def test_multiple_async_multiple_display_targeted(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script id='pyA'>
|
||||
<script type="py" id="pyA">
|
||||
from pyscript import display
|
||||
import js
|
||||
import asyncio
|
||||
@@ -98,11 +99,13 @@ class TestAsync(PyScriptTest):
|
||||
async def a_func():
|
||||
for i in range(2):
|
||||
display(f'A{i}', target='pyA', append=True)
|
||||
js.console.log("A", i)
|
||||
await asyncio.sleep(0.1)
|
||||
asyncio.ensure_future(a_func())
|
||||
|
||||
</py-script>
|
||||
<py-script id='pyB'>
|
||||
</script>
|
||||
|
||||
<script type="py" id="pyB">
|
||||
from pyscript import display
|
||||
import js
|
||||
import asyncio
|
||||
@@ -110,11 +113,12 @@ class TestAsync(PyScriptTest):
|
||||
async def a_func():
|
||||
for i in range(2):
|
||||
display(f'B{i}', target='pyB', append=True)
|
||||
js.console.log("B", i)
|
||||
await asyncio.sleep(0.1)
|
||||
js.console.log("B DONE")
|
||||
|
||||
asyncio.ensure_future(a_func())
|
||||
</py-script>
|
||||
</script>
|
||||
"""
|
||||
)
|
||||
self.wait_for_console("B DONE")
|
||||
@@ -124,7 +128,7 @@ class TestAsync(PyScriptTest):
|
||||
def test_async_display_untargeted(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script>
|
||||
<script type="py">
|
||||
from pyscript import display
|
||||
import asyncio
|
||||
import js
|
||||
@@ -135,16 +139,16 @@ class TestAsync(PyScriptTest):
|
||||
js.console.log("DONE")
|
||||
|
||||
asyncio.ensure_future(a_func())
|
||||
</py-script>
|
||||
</script>
|
||||
"""
|
||||
)
|
||||
self.wait_for_console("DONE")
|
||||
assert self.page.locator("py-script").inner_text() == "A"
|
||||
assert self.page.locator("script-py").inner_text() == "A"
|
||||
|
||||
def test_sync_and_async_order(self):
|
||||
"""
|
||||
The order of execution is defined as follows:
|
||||
1. first, we execute all the py-script tag in order
|
||||
1. first, we execute all the script tags in order
|
||||
2. then, we start all the tasks which were scheduled with create_task
|
||||
|
||||
Note that tasks are started *AFTER* all py-script tags have been
|
||||
@@ -152,12 +156,12 @@ class TestAsync(PyScriptTest):
|
||||
executed after e.g. js.console.log("6").
|
||||
"""
|
||||
src = """
|
||||
<py-script>
|
||||
<script type="py">
|
||||
import js
|
||||
js.console.log("1")
|
||||
</py-script>
|
||||
</script>
|
||||
|
||||
<py-script>
|
||||
<script type="py">
|
||||
import asyncio
|
||||
import js
|
||||
|
||||
@@ -169,14 +173,14 @@ class TestAsync(PyScriptTest):
|
||||
js.console.log("2")
|
||||
asyncio.create_task(mytask1())
|
||||
js.console.log("3")
|
||||
</py-script>
|
||||
</script>
|
||||
|
||||
<py-script>
|
||||
<script type="py">
|
||||
import js
|
||||
js.console.log("4")
|
||||
</py-script>
|
||||
</script>
|
||||
|
||||
<py-script>
|
||||
<script type="py">
|
||||
import asyncio
|
||||
import js
|
||||
|
||||
@@ -189,7 +193,7 @@ class TestAsync(PyScriptTest):
|
||||
js.console.log("5")
|
||||
asyncio.create_task(mytask2())
|
||||
js.console.log("6")
|
||||
</py-script>
|
||||
</script>
|
||||
"""
|
||||
self.pyscript_run(src, wait_for_pyscript=False)
|
||||
self.wait_for_console("DONE")
|
||||
|
||||
Reference in New Issue
Block a user