Files
pyscript/pyscriptjs/tests/integration/test_py_inputbox.py
Antonio Cuni f3157b377f Improve JS logging (#743)
This PR tries to improve and rationalize what we log. Key points:
- introduce `logger.ts`: each file/component is encouraged to use the logger instead of writing directly to `console.*`
    * the logger automatically prepend a prefix like `[py-config]`, `[py-env]` which make it easier to understand where a certain message is printed from
    * it provide a central place where to add more features in the future. E.g., I can imagine having a config setting to completely silence the logs (not implemented yet)
- use the new loggers everywhere
- write to `.info()` instead of `.log()`. The idea is to keep `console.log` free, so that for the users it's easier to tell apart their own messages and the pyscript ones
- generally improve what we log. This is an endless exercise, but I tried to print more things which are useful to understand what's going on and in which order the various things are executed, and remove prints which were clearly debugging leftovers
2022-09-06 15:18:41 +02:00

43 lines
1.6 KiB
Python

import time
import pytest
from .support import PyScriptTest
class TestPyInputBox(PyScriptTest):
@pytest.mark.xfail
def test_input_box_typing(self):
"""
This test fails in a similar fashion as the pybutton
test so it's xfailed for now.
[JS exception ] TypeError: Cannot use 'in' operator to search for 'runPythonAsync' in undefined
at http://127.0.0.1:8080/build/pyscript.js:305:38
at Object.subscribe (http://127.0.0.1:8080/build/pyscript.js:46:13)
at PyButton.runAfterRuntimeInitialized (http://127.0.0.1:8080/build/pyscript.js:304:27)
at PyButton.connectedCallback (http://127.0.0.1:8080/build/pyscript.js:26856:18)
at http://127.0.0.1:8080/build/pyscript.js:27075:20
at http://127.0.0.1:8080/build/pyscript.js:27093:3
""" # noqa: E501
self.pyscript_run(
"""
<py-inputbox label="my input">
import js
def on_keypress(evt):
if evt.key == "Enter":
js.console.log(evt.target.value)
</py-inputbox>
"""
)
assert self.console.log.lines == [self.PY_COMPLETE]
input = self.page.locator("input")
# We need to wait some time before we can type any text
# otherwise it won't be registered. This was the smallest
# amount that seems to work.
time.sleep(0.1)
input.type("Hello")
input.press("Enter")
assert self.console.log.lines == [self.PY_COMPLETE, "Hello"]