remove PY_COMPLETE and the associated message of Python initialization complete (#1373)

* remove PY_COMPLETE

* fix test_multiple_async
This commit is contained in:
Madhur Tandon
2023-04-11 18:59:09 +05:30
committed by GitHub
parent c05195c045
commit f3db6a339c
14 changed files with 2 additions and 73 deletions

View File

@@ -67,9 +67,7 @@ export class PyTerminalPlugin extends Plugin {
// 3. everything which was written to stdout BEFORE this moment will
// NOT be shown on the py-terminal; in particular, pyodide
// startup messages will not be shown (but they will go to the
// console as usual). This is by design, else we would display
// e.g. "Python initialization complete" on every page, which we
// don't want.
// console as usual).
//
// 4. (in the future we might want to add an option to start the
// capture earlier, but I don't think it's important now).

View File

@@ -136,7 +136,6 @@ export class RemoteInterpreter extends Object {
await this.loadPackage('micropip');
}
logger.info('pyodide loaded and initialized');
this.pyscript_py._run_pyscript('print("Python initialization complete")');
}
/**

View File

@@ -46,10 +46,6 @@ class PyScriptTest:
creates an HTML page to run the specified snippet.
"""
# Pyodide always print()s this message upon initialization. Make it
# available to all tests so that it's easiert to check.
PY_COMPLETE = "Python initialization complete"
@pytest.fixture()
def init(self, request, tmpdir, logger, page):
"""

View File

@@ -14,7 +14,6 @@ class TestBasic(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-1] == "hello pyscript"
def test_python_exception(self):
@@ -26,7 +25,6 @@ class TestBasic(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
assert "hello pyscript" in self.console.log.lines
# check that we sent the traceback to the console
tb_lines = self.console.error.lines[-1].splitlines()
@@ -80,7 +78,6 @@ class TestBasic(PyScriptTest):
<py-script>js.console.log('four')</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-4:] == [
"one",
"two",
@@ -99,7 +96,6 @@ class TestBasic(PyScriptTest):
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-2:] == ["true false", "<div></div>"]
def test_packages(self):
@@ -118,7 +114,6 @@ class TestBasic(PyScriptTest):
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-3:] == [
"Loading asciitree", # printed by pyodide
"Loaded asciitree", # printed by pyodide
@@ -178,7 +173,6 @@ class TestBasic(PyScriptTest):
self.page.locator("button").click()
self.page.wait_for_selector("py-terminal")
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-1] == "hello world"
def test_py_script_src_attribute(self):
@@ -188,7 +182,6 @@ class TestBasic(PyScriptTest):
<py-script src="foo.py"></py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-1] == "hello from foo"
def test_py_script_src_not_found(self):
@@ -198,8 +191,6 @@ class TestBasic(PyScriptTest):
<py-script src="foo.py"></py-script>
"""
)
assert self.PY_COMPLETE in self.console.log.lines
assert "Failed to load resource" in self.console.error.lines[0]
error_msgs = str(exc.value)

View File

@@ -355,7 +355,6 @@ class TestOutput(PyScriptTest):
)
inner_text = self.page.inner_text("py-script")
assert inner_text == "this goes to the DOM"
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-2:] == [
"print from python",
"print from js",

View File

@@ -16,7 +16,6 @@ class TestElement(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-1] == "foo"
py_terminal = self.page.wait_for_selector("py-terminal")
@@ -34,7 +33,6 @@ class TestElement(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-1] == "bar"
py_terminal = self.page.wait_for_selector("py-terminal")
@@ -52,7 +50,6 @@ class TestElement(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-1] == "<b>bar</b>"
py_terminal = self.page.wait_for_selector("py-terminal")
@@ -71,8 +68,6 @@ class TestElement(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
div = self.page.wait_for_selector("#foo")
assert "World!" in div.inner_text()
@@ -89,8 +84,6 @@ class TestElement(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
parent_div = self.page.wait_for_selector("#foo")
assert "Hello!" in parent_div.inner_text()
@@ -109,8 +102,6 @@ class TestElement(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
div = self.page.locator("#foo")
assert div.inner_text() == ""
@@ -126,8 +117,6 @@ class TestElement(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
input = self.page.wait_for_selector("#foo")
assert input.input_value() == ""
@@ -145,8 +134,6 @@ class TestElement(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
select = self.page.wait_for_selector("#foo")
assert select.inner_text() == "Bar"
@@ -162,8 +149,6 @@ class TestElement(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
divs = self.page.locator("#foo")
assert divs.count() == 2
assert divs.first.inner_text() == "Hello!"
@@ -181,8 +166,6 @@ class TestElement(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
divs = self.page.locator("#foo")
assert divs.count() == 1
assert divs.inner_text() == "Hello!"
@@ -212,8 +195,6 @@ class TestElement(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
bond_divs = self.page.locator("#bond")
james_divs = self.page.locator("#james")
bond_2_divs = self.page.locator("#bond-2")
@@ -238,8 +219,6 @@ class TestElement(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
div = self.page.locator("#foo")
assert div.get_attribute("class") == "baz"
@@ -255,8 +234,6 @@ class TestElement(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
div = self.page.locator("#foo")
assert div.get_attribute("class") == ""
@@ -273,8 +250,6 @@ class TestElement(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
div = self.page.locator("#foo")
assert div.get_attribute("class") == "red"
@@ -291,7 +266,5 @@ class TestElement(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
div = self.page.locator("#foo")
assert div.get_attribute("class") == "red bold"

View File

@@ -20,13 +20,11 @@ class TestAsync(PyScriptTest):
def test_asyncio_ensure_future(self):
self.pyscript_run(self.coroutine_script.format(func="ensure_future"))
self.wait_for_console("third")
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-3:] == ["first", "second", "third"]
def test_asyncio_create_task(self):
self.pyscript_run(self.coroutine_script.format(func="create_task"))
self.wait_for_console("third")
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-3:] == ["first", "second", "third"]
def test_asyncio_gather(self):
@@ -79,8 +77,7 @@ class TestAsync(PyScriptTest):
"""
)
self.wait_for_console("b func done")
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[1:] == [
assert self.console.log.lines == [
"A 0",
"B 0",
"A 1",

View File

@@ -36,7 +36,6 @@ class TestImportmap(PyScriptTest):
)
assert self.console.log.lines == [
"hello from JS",
self.PY_COMPLETE,
"hello from Python",
]
@@ -59,7 +58,6 @@ class TestImportmap(PyScriptTest):
self.wait_for_pyscript()
assert self.console.log.lines == [
self.PY_COMPLETE,
"hello world",
]
# this warning is shown by pyscript, when *we* try to parse the import

View File

@@ -24,7 +24,6 @@ class TestInterpreterAccess(PyScriptTest):
console.log(`py_func() returns ${py_func_res}`);
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-2:] == [
"x is 1",
"py_func() returns 2",
@@ -42,7 +41,6 @@ class TestInterpreterAccess(PyScriptTest):
)
expected_message = "Interpreter Ran This"
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-1] == expected_message
py_terminal = self.page.wait_for_selector("py-terminal")
@@ -60,7 +58,6 @@ class TestInterpreterAccess(PyScriptTest):
)
expected_message = "Interpreter Ran This"
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-1] == expected_message
py_terminal = self.page.wait_for_selector("py-terminal")
@@ -88,7 +85,6 @@ class TestInterpreterAccess(PyScriptTest):
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-2:] == [
"x is 1",
"py_func() returns 2",

View File

@@ -270,7 +270,6 @@ class TestConfig(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-2:] == [
"hello from A",
"hello from B",
@@ -313,5 +312,4 @@ class TestConfig(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-1] == "hello from A"

View File

@@ -74,7 +74,6 @@ class TestPyRepl(PyScriptTest):
self.page.keyboard.press("Shift+Enter")
self.page.wait_for_selector("py-terminal")
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.log.lines[-1] == "hello world"
# Shift-enter should not add a newline to the editor
@@ -585,7 +584,6 @@ class TestPyRepl(PyScriptTest):
"""
)
successMsg = "[py-repl] loading code from ./loadReplSrc1.py to repl...success"
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.info.lines[-1] == successMsg
py_repl = self.page.locator("py-repl")
@@ -610,7 +608,6 @@ class TestPyRepl(PyScriptTest):
)
successMsg1 = "[py-repl] loading code from ./loadReplSrc2.py to repl...success"
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.info.lines[-1] == successMsg1
py_repl3 = self.page.locator("py-repl#py-repl3")
@@ -635,5 +632,4 @@ class TestPyRepl(PyScriptTest):
"failed with error 404 (Not Found). "
"Are your filename and path correct?"
)
assert self.console.log.lines[0] == self.PY_COMPLETE
assert self.console.error.lines[-1] == errorMsg

View File

@@ -9,9 +9,6 @@ class TestPyTerminal(PyScriptTest):
1. <py-terminal> should redirect stdout and stderr to the DOM
2. they also go to the console as usual
3. note that the console also contains PY_COMPLETE, which is a pyodide
initialization message, but py-terminal doesn't. This is by design
"""
self.pyscript_run(
"""

View File

@@ -36,7 +36,6 @@ class TestSplashscreen(PyScriptTest):
expect(div).to_be_hidden()
assert self.page.locator("py-locator").count() == 0
assert self.console.log.lines[0] == self.PY_COMPLETE
assert "hello pyscript" in self.console.log.lines
def test_autoclose_false(self):
@@ -55,7 +54,6 @@ class TestSplashscreen(PyScriptTest):
expect(div).to_be_visible()
expect(div).to_contain_text("Python startup...")
expect(div).to_contain_text("Startup complete")
assert self.console.log.lines[0] == self.PY_COMPLETE
assert "hello pyscript" in self.console.log.lines
def test_autoclose_loader_deprecated(self):
@@ -77,7 +75,6 @@ class TestSplashscreen(PyScriptTest):
expect(div).to_be_visible()
expect(div).to_contain_text("Python startup...")
expect(div).to_contain_text("Startup complete")
assert self.console.log.lines[0] == self.PY_COMPLETE
assert "hello pyscript" in self.console.log.lines
@pytest.mark.skip(reason="pys-onClick is broken, we should kill it, see #1213")

View File

@@ -30,7 +30,6 @@ class TestDocsSnippets(PyScriptTest):
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
btn = self.page.wait_for_selector("#get-time")
btn.click()
@@ -61,7 +60,6 @@ class TestDocsSnippets(PyScriptTest):
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
py_terminal = self.page.wait_for_selector("py-terminal")
# Just a small check to confirm that the response was received
assert "userId" in py_terminal.inner_text()
@@ -106,7 +104,6 @@ class TestDocsSnippets(PyScriptTest):
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
todo_input = self.page.locator("input")
submit_task_button = self.page.locator("button")
@@ -146,7 +143,6 @@ class TestDocsSnippets(PyScriptTest):
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
py_terminal = self.page.wait_for_selector("py-terminal")
assert "0.22.0a3" in py_terminal.inner_text()
self.assert_no_banners()
@@ -176,7 +172,6 @@ class TestDocsSnippets(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
btn_manual = self.page.wait_for_selector("#manual")
btn_display = self.page.wait_for_selector("#display")
btn_print = self.page.wait_for_selector("#print")
@@ -208,7 +203,6 @@ class TestDocsSnippets(PyScriptTest):
</py-script>
"""
)
assert self.console.log.lines[0] == self.PY_COMPLETE
py_terminal = self.page.wait_for_selector("py-terminal")
assert "0\n1\n2\n" in py_terminal.inner_text()