mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-22 19:53:00 -05:00
Add display impl, rm outputManage, print and console.log default to browser console (#749)
* Add display impl, remove outputManage, print and console.log defaults to terminal * Fixing tests * Lint * Erase unecessary code, add cuter CSS formating for errors, fix problems around REPL output * Add fix to repl2 and lint * lint * Allow for list of display, fix elif to else * Add better global option * test work * xfails * (antocuni, mariana): let's try to start again with TDD methodology: write the minimum test and code for a simple display() * (antocuni, mariana): this test works out of the box * WIP: this test is broken, mariana is going to fix it * add a failing test * Add ability to deal with targets * Add append arg and append tests * Add multiple values to display * Small adjustments to tests. I noticed I wasn;t running all at some point * add display test * Add console tests * Add async tests * Fix repl tests * Fixing merging issues * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Address antocuni's review * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fixing more tests * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * linting * Improve repl tests * Change my test so codespell is hapy with it * Test: change test_runtime_config to use json instead of toml to see if stops failing on CI * kill this file: it is a merge artifact since it was renamed into test_py_config.py on the main branch * Change test execution order and add async tests to async test file Co-authored-by: Antonio Cuni <anto.cuni@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
75
pyscriptjs/tests/integration/test_03_async.py
Normal file
75
pyscriptjs/tests/integration/test_03_async.py
Normal file
@@ -0,0 +1,75 @@
|
||||
import re
|
||||
|
||||
from .support import PyScriptTest
|
||||
|
||||
|
||||
class TestAsync(PyScriptTest):
|
||||
def test_multiple_async(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script>
|
||||
import js
|
||||
import asyncio
|
||||
for i in range(3):
|
||||
js.console.log('A', i)
|
||||
await asyncio.sleep(0.1)
|
||||
</py-script>
|
||||
|
||||
<py-script>
|
||||
import js
|
||||
import asyncio
|
||||
for i in range(3):
|
||||
js.console.log('B', i)
|
||||
await asyncio.sleep(0.1)
|
||||
js.console.log("async tadone")
|
||||
</py-script>
|
||||
"""
|
||||
)
|
||||
self.wait_for_console("async tadone")
|
||||
assert self.console.log.lines == [
|
||||
"Python initialization complete",
|
||||
"A 0",
|
||||
"B 0",
|
||||
"A 1",
|
||||
"B 1",
|
||||
"A 2",
|
||||
"B 2",
|
||||
"async tadone",
|
||||
]
|
||||
|
||||
def test_multiple_async_display(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script id="py1">
|
||||
def say_hello():
|
||||
display('hello')
|
||||
</py-script>
|
||||
<py-script id="py2">
|
||||
say_hello()
|
||||
</py-script>
|
||||
"""
|
||||
)
|
||||
inner_html = self.page.content()
|
||||
pattern = r'<div id="py2-2">hello</div>'
|
||||
assert re.search(pattern, inner_html)
|
||||
|
||||
def test_multiple_async_multiple_display(self):
|
||||
self.pyscript_run(
|
||||
"""
|
||||
<py-script id='pyA'>
|
||||
import asyncio
|
||||
for i in range(2):
|
||||
display('A')
|
||||
await asyncio.sleep(0)
|
||||
</py-script>
|
||||
|
||||
<py-script id='pyB'>
|
||||
import asyncio
|
||||
for i in range(2):
|
||||
display('B')
|
||||
await asyncio.sleep(0)
|
||||
</py-script>
|
||||
"""
|
||||
)
|
||||
inner_text = self.page.inner_text("html")
|
||||
assert "A\nB\nA\nB" in inner_text
|
||||
Reference in New Issue
Block a user