From 4e8281c749f89bb7fcb6088630f30ebf7e5f3f32 Mon Sep 17 00:00:00 2001 From: Madhur Tandon <20173739+madhur-tandon@users.noreply.github.com> Date: Tue, 24 Jan 2023 22:01:19 +0530 Subject: [PATCH] fix display multiple append with target (#1126) * fix display multiple append with target * flake8 ignore long lines * fix img render test --- pyscriptjs/src/python/pyscript.py | 2 +- .../tests/integration/test_02_display.py | 30 ++++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/pyscriptjs/src/python/pyscript.py b/pyscriptjs/src/python/pyscript.py index a9fcfda3..eb1fd890 100644 --- a/pyscriptjs/src/python/pyscript.py +++ b/pyscriptjs/src/python/pyscript.py @@ -250,7 +250,7 @@ class Element: child = js.document.createElement("div") self.element.appendChild(child) - if self.element.children: + if append and self.element.children: out_element = self.element.children[-1] else: out_element = self.element diff --git a/pyscriptjs/tests/integration/test_02_display.py b/pyscriptjs/tests/integration/test_02_display.py index ad7fbecb..05825a6d 100644 --- a/pyscriptjs/tests/integration/test_02_display.py +++ b/pyscriptjs/tests/integration/test_02_display.py @@ -219,6 +219,31 @@ class TestOutput(PyScriptTest): pattern = r'world' assert re.search(pattern, inner_html) + def test_display_multiple_append_false_with_target(self): + self.pyscript_run( + """ +
+ + class Circle: + r = 0 + def _repr_svg_(self): + return f'' # noqa: E501 + + circle = Circle() + + circle.r += 5 + display(circle, target="circle-div", append=False) + circle.r += 5 + display(circle, target="circle-div", append=False) + + """ + ) + innerhtml = self.page.locator("id=circle-div").inner_html() + assert ( + innerhtml + == '' # noqa: E501 + ) + def test_display_list_dict_tuple(self): self.pyscript_run( """ @@ -353,8 +378,5 @@ class TestOutput(PyScriptTest): """ ) - # TODO: This seems to be a py-script tag, should it? - rendered_img_src = self.page.locator("#py-internal-0 > img").get_attribute( - "src" - ) + rendered_img_src = self.page.locator("img").get_attribute("src") assert rendered_img_src == expected_img_src