mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -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
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
import re
|
|
|
|
from .support import PyScriptTest
|
|
|
|
|
|
class TestBasic(PyScriptTest):
|
|
def test_pyscript_hello(self):
|
|
self.pyscript_run(
|
|
"""
|
|
<py-script>
|
|
print('hello pyscript')
|
|
</py-script>
|
|
"""
|
|
)
|
|
# this is a very ugly way of checking the content of the DOM. If we
|
|
# find ourselves to write a lot of code in this style, we will
|
|
# probably want to write a nicer API for it.
|
|
inner_html = self.page.locator("py-script").inner_html()
|
|
pattern = r'<div id="py-.*">hello pyscript</div>'
|
|
assert re.search(pattern, inner_html)
|
|
|
|
def test_execution_in_order(self):
|
|
"""
|
|
Check that they py-script tags are executed in the same order they are
|
|
defined
|
|
"""
|
|
self.pyscript_run(
|
|
"""
|
|
<py-script>import js; js.console.log('one')</py-script>
|
|
<py-script>js.console.log('two')</py-script>
|
|
<py-script>js.console.log('three')</py-script>
|
|
<py-script>js.console.log('four')</py-script>
|
|
"""
|
|
)
|
|
assert self.console.log.lines == [
|
|
self.PY_COMPLETE,
|
|
"one",
|
|
"two",
|
|
"three",
|
|
"four",
|
|
]
|
|
|
|
def test_escaping_of_angle_brackets(self):
|
|
"""
|
|
Check that py-script tags escape angle brackets
|
|
"""
|
|
self.pyscript_run(
|
|
"""
|
|
<py-script>import js; js.console.log(1<2, 1>2)</py-script>
|
|
<py-script>js.console.log("<div></div>")</py-script>
|
|
"""
|
|
)
|
|
assert self.console.log.lines == [self.PY_COMPLETE, "true false", "<div></div>"]
|