mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-20 02:37:41 -05:00
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
35 lines
1.4 KiB
Python
35 lines
1.4 KiB
Python
import pytest
|
|
|
|
from .support import PyScriptTest
|
|
|
|
|
|
class TestPyButton(PyScriptTest):
|
|
@pytest.mark.xfail
|
|
def test_on_click(self):
|
|
"""
|
|
currently this test fails for a bad reason which is unrelated to
|
|
py-button. During the page loading, the following JS exception occur,
|
|
in base.ts:BaseEvalElement.evaluate
|
|
|
|
[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-button label="my button">
|
|
import js
|
|
def on_click(evt):
|
|
js.console.log('clicked!')
|
|
</py-button>
|
|
"""
|
|
)
|
|
assert self.console.log.lines == [self.PY_COMPLETE]
|
|
self.page.locator("text=my button").click()
|
|
self.page.locator("text=my button").click()
|
|
assert self.console.log.lines == [self.PY_COMPLETE, "clicked!", "clicked!"]
|