mirror of
https://github.com/pyscript/pyscript.git
synced 2026-02-21 11:01:26 -05:00
Fix antigravity (#1017)
* Fix antigravity * Add test * [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:
@@ -1,5 +1,4 @@
|
||||
import random
|
||||
import sys
|
||||
|
||||
from js import DOMParser, document, setInterval
|
||||
from pyodide.ffi import create_proxy
|
||||
@@ -11,9 +10,10 @@ class Antigravity:
|
||||
url = "./antigravity.svg"
|
||||
|
||||
def __init__(self, target=None, interval=10, append=True, fly=False):
|
||||
target = target or sys.stdout._out
|
||||
self.target = (
|
||||
document.getElementById(target) if isinstance(target, str) else target
|
||||
document.getElementById(target)
|
||||
if isinstance(target, str)
|
||||
else document.body
|
||||
)
|
||||
doc = DOMParser.new().parseFromString(
|
||||
open_url(self.url).read(), "image/svg+xml"
|
||||
|
||||
@@ -98,6 +98,29 @@ class TestExamples(PyScriptTest):
|
||||
assert see_source_link.is_visible()
|
||||
self.assert_no_banners()
|
||||
|
||||
def test_antigravity(self):
|
||||
self.goto("examples/antigravity.html")
|
||||
self.wait_for_pyscript()
|
||||
assert self.page.title() == "Antigravity"
|
||||
|
||||
# confirm that svg added to page
|
||||
wait_for_render(self.page, "*", '<svg.*id="svg8".*>')
|
||||
|
||||
# Get svg layer of flying character
|
||||
char = self.page.wait_for_selector("#python")
|
||||
assert char is not None
|
||||
|
||||
# check that character moves in negative-y direction over time
|
||||
ycoord_pattern = r"translate\(-?\d*\.\d*,\s(?P<ycoord>-?[\d.]+)\)"
|
||||
starting_y_coord = float(
|
||||
re.match(ycoord_pattern, char.get_attribute("transform")).group("ycoord")
|
||||
)
|
||||
time.sleep(2)
|
||||
later_y_coord = float(
|
||||
re.match(ycoord_pattern, char.get_attribute("transform")).group("ycoord")
|
||||
)
|
||||
assert later_y_coord < starting_y_coord
|
||||
|
||||
def test_bokeh(self):
|
||||
# XXX improve this test
|
||||
self.goto("examples/bokeh.html")
|
||||
|
||||
Reference in New Issue
Block a user