import re from .support import PyScriptTest class TestBasic(PyScriptTest): def test_pyscript_hello(self): self.pyscript_run( """ print('hello pyscript') """ ) # 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'
hello pyscript
' 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 """ # NOTE: this test relies on the fact that pyscript does not write # anything to console.info. If we start writing to info in the future, # we will probably need to tweak this test. self.pyscript_run( """ import js; js.console.info('one') js.console.info('two') js.console.info('three') js.console.info('four') """ ) assert self.console.info.lines == ["one", "two", "three", "four"] def test_escaping_of_angle_brackets(self): """ Check that py-script tags escape angle brackets """ # NOTE: this test relies on the fact that pyscript does not write # anything to console.info. If we start writing to info in the future, # we will probably need to tweak this test. self.pyscript_run( """ import js; js.console.info(1<2, 1>2) js.console.info("
")
""" ) assert self.console.info.lines == ["true false", "
"]