Marimeireles fix/#1081 (#1155)

* Improves repl id output

* Fix tests for new REPL output ids

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add new REPL tests

* Pre commit linting

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove mistake

* Fixing tests that i didn't notice were broken?

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Mariana Meireles
2023-02-14 07:51:43 +01:00
committed by GitHub
parent 1f825edc28
commit b14a2bba5f
3 changed files with 58 additions and 8 deletions

View File

@@ -43,7 +43,7 @@ export function make_PyRepl(interpreter: Interpreter) {
this.shadow.appendChild(slot);
if (!this.hasAttribute('exec-id')) {
this.setAttribute('exec-id', '1');
this.setAttribute('exec-id', '0');
}
if (!this.hasAttribute('root')) {
this.setAttribute('root', this.id);
@@ -141,7 +141,7 @@ export function make_PyRepl(interpreter: Interpreter) {
makeOutDiv(): HTMLElement {
const outDiv = document.createElement('div');
outDiv.className = 'py-repl-output';
outDiv.id = this.id + '-' + this.getAttribute('exec-id');
outDiv.id = this.id + '-repl-output';
return outDiv;
}

View File

@@ -123,6 +123,7 @@ class TestPyRepl(PyScriptTest):
# clear the editor, write new code, execute
self._replace(py_repl, "display('another output')")
self.page.keyboard.press("Shift+Enter")
print
assert out_div.all_inner_texts()[1] == "another output"
def test_python_exception(self):
@@ -151,6 +152,26 @@ class TestPyRepl(PyScriptTest):
assert tb_lines[0] == "Traceback (most recent call last):"
assert tb_lines[-1] == "Exception: this is an error"
def test_multiple_repls(self):
"""
Multiple repls showing in the correct order in the page
"""
self.pyscript_run(
"""
<py-repl data-testid=="first"> display("first") </py-repl>
<py-repl data-testid=="second"> display("second") </py-repl>
"""
)
first_py_repl = self.page.get_by_text("first")
first_py_repl.click()
self.page.keyboard.press("Shift+Enter")
assert self.page.inner_text("#py-internal-0-repl-output") == "first"
second_py_repl = self.page.get_by_text("second")
second_py_repl.click()
self.page.keyboard.press("Shift+Enter")
assert self.page.inner_text("#py-internal-1-repl-output") == "second"
def test_python_exception_after_previous_output(self):
self.pyscript_run(
"""
@@ -247,17 +268,44 @@ class TestPyRepl(PyScriptTest):
# evaluate the py-repl, and wait for the newly generated one
self.page.keyboard.type("'hello'")
self.page.keyboard.press("Shift+Enter")
self.page.locator('py-repl[exec-id="2"]').wait_for()
self.page.locator('py-repl[exec-id="1"]').wait_for()
assert py_repls.count() == 2
assert outputs.count() == 2
#
# now we type something else: the new py-repl should have the focus
self.page.keyboard.type("'world'")
self.page.keyboard.press("Shift+Enter")
self.page.locator('py-repl[exec-id="3"]').wait_for()
self.page.locator('py-repl[exec-id="2"]').wait_for()
assert py_repls.count() == 3
assert outputs.count() == 3
#
# check that the code and the outputs are in order
out_texts = [el.inner_text() for el in self.iter_locator(outputs)]
assert out_texts == ["hello", "world", ""]
def test_multiple_repls_mixed_display_order(self):
"""
Displaying several outputs that don't obey the order in which the original
repl displays were created using the auto_generate attr
"""
self.pyscript_run(
"""
<py-repl auto-generate="true" data-testid=="first"> display("root first") </py-repl>
<py-repl auto-generate="true" data-testid=="second"> display("root second") </py-repl>
"""
)
second_py_repl = self.page.get_by_text("root second")
second_py_repl.click()
self.page.keyboard.press("Shift+Enter")
self.page.keyboard.type("display('second children')")
self.page.keyboard.press("Shift+Enter")
first_py_repl = self.page.get_by_text("root first")
first_py_repl.click()
self.page.keyboard.press("Shift+Enter")
self.page.keyboard.type("display('first children')")
self.page.keyboard.press("Shift+Enter")
assert self.page.inner_text("#py-internal-1-1-repl-output") == "second children"
assert self.page.inner_text("#py-internal-0-1-repl-output") == "first children"

View File

@@ -301,15 +301,17 @@ class TestExamples(PyScriptTest):
self.page.locator("py-repl").type("display('Hello, World!')")
self.page.locator("#runButton").click()
assert self.page.locator("#my-repl-1").text_content() == "Hello, World!"
assert (
self.page.locator("#my-repl-repl-output").text_content() == "Hello, World!"
)
# Confirm that using the second repl still works properly
self.page.locator("#my-repl-2").type("display(2*2)")
self.page.locator("#my-repl-1").type("display(2*2)")
self.page.keyboard.press("Shift+Enter")
# Make sure that the child of the second repl is attached properly
# before looking into the text_content
assert self.page.wait_for_selector("#my-repl-2-2", state="attached")
assert self.page.locator("#my-repl-2-2").text_content() == "4"
assert self.page.wait_for_selector("#my-repl-1-repl-output", state="attached")
assert self.page.locator("#my-repl-1-repl-output").text_content() == "4"
self.assert_no_banners()
self.check_tutor_generated_code(modules_to_check=["antigravity.py"])