mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-21 19:25:35 -05:00
Fix Flaky test_execute_on_shift_enter (#1097)
* Wait for text to render in DOM before 'assert', to fix timing issue.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import dataclasses
|
||||
import math
|
||||
import os
|
||||
import pdb
|
||||
import re
|
||||
@@ -372,6 +373,31 @@ class PyScriptTest:
|
||||
|
||||
# ============== Helpers and utility functions ==============
|
||||
|
||||
MAX_TEST_TIME = 30 # Number of seconds allowed for checking a testing condition
|
||||
TEST_TIME_INCREMENT = 0.25 # 1/4 second, the length of each iteration
|
||||
TEST_ITERATIONS = math.ceil(
|
||||
MAX_TEST_TIME / TEST_TIME_INCREMENT
|
||||
) # 120 iters of 1/4 second
|
||||
|
||||
|
||||
def wait_for_render(page, selector, pattern):
|
||||
"""
|
||||
Assert that rendering inserts data into the page as expected: search the
|
||||
DOM from within the timing loop for a string that is not present in the
|
||||
initial markup but should appear by way of rendering
|
||||
"""
|
||||
re_sub_content = re.compile(pattern)
|
||||
py_rendered = False # Flag to be set to True when condition met
|
||||
|
||||
for _ in range(TEST_ITERATIONS):
|
||||
content = page.inner_html(selector)
|
||||
if re_sub_content.search(content):
|
||||
py_rendered = True
|
||||
break
|
||||
time.sleep(TEST_TIME_INCREMENT)
|
||||
|
||||
assert py_rendered # nosec
|
||||
|
||||
|
||||
class JsErrors(Exception):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user