This commit is contained in:
Fabio Pliger
2024-05-08 14:26:05 -05:00
parent 0c2dec3240
commit d348d9aaf6

View File

@@ -25,12 +25,14 @@ DEFAULT_ELEMENT_ATTRIBUTES = {
"virtualkeyboardpolicy": "manual", "virtualkeyboardpolicy": "manual",
} }
INTERPRETERS = ['py', 'mpy'] INTERPRETERS = ["py", "mpy"]
@pytest.fixture(params=INTERPRETERS) @pytest.fixture(params=INTERPRETERS)
def interpreter(request): def interpreter(request):
return request.param return request.param
class TestElements(PyScriptTest): class TestElements(PyScriptTest):
"""Test all elements in the pyweb.ui.elements module. """Test all elements in the pyweb.ui.elements module.
@@ -42,17 +44,19 @@ class TestElements(PyScriptTest):
on each the supported properties and checks if the element was created correctly on each the supported properties and checks if the element was created correctly
and all it's properties were set correctly. and all it's properties were set correctly.
""" """
def _create_el_and_basic_asserts( def _create_el_and_basic_asserts(
self, self,
el_type, el_type,
el_text=None, el_text=None,
interpreter='py', interpreter="py",
properties=None, properties=None,
expected_errors=None, expected_errors=None,
additional_selector_rules=None, additional_selector_rules=None,
): ):
"""Create an element with all its properties set, by running <script type=<interpreter> ... > """Create an element with all its properties set, by running <script type=<interpreter> ... >
, and check if the element was created correctly and all its properties were set correctly.""" , and check if the element was created correctly and all its properties were set correctly.
"""
expected_errors = expected_errors or [] expected_errors = expected_errors or []
if not properties: if not properties:
properties = {} properties = {}
@@ -125,7 +129,9 @@ class TestElements(PyScriptTest):
assert abbr.text_content() == "click me" assert abbr.text_content() == "click me"
def test_abbr(self, interpreter): def test_abbr(self, interpreter):
abbr = self._create_el_and_basic_asserts("abbr", "some text", interpreter=interpreter) abbr = self._create_el_and_basic_asserts(
"abbr", "some text", interpreter=interpreter
)
assert abbr.text_content() == "some text" assert abbr.text_content() == "some text"
def test_address(self, interpreter): def test_address(self, interpreter):
@@ -141,7 +147,9 @@ class TestElements(PyScriptTest):
"alt": "HTTP", "alt": "HTTP",
} }
# TODO: Check why click times out # TODO: Check why click times out
self._create_el_and_basic_asserts("area", interpreter=interpreter, properties=properties) self._create_el_and_basic_asserts(
"area", interpreter=interpreter, properties=properties
)
def test_article(self, interpreter): def test_article(self, interpreter):
self._create_el_and_basic_asserts("article", "some text", interpreter) self._create_el_and_basic_asserts("article", "some text", interpreter)
@@ -173,7 +181,9 @@ class TestElements(PyScriptTest):
assert button.inner_html() == "click me" assert button.inner_html() == "click me"
def test_element_button_attributes(self, interpreter): def test_element_button_attributes(self, interpreter):
button = self._create_el_and_basic_asserts("button", "click me", interpreter, None) button = self._create_el_and_basic_asserts(
"button", "click me", interpreter, None
)
assert button.inner_html() == "click me" assert button.inner_html() == "click me"
def test_canvas(self, interpreter): def test_canvas(self, interpreter):
@@ -276,7 +286,9 @@ class TestElements(PyScriptTest):
"autocomplete": "on", "autocomplete": "on",
"rel": "external", "rel": "external",
} }
self._create_el_and_basic_asserts("form", "some text", interpreter, properties=properties) self._create_el_and_basic_asserts(
"form", "some text", interpreter, properties=properties
)
def test_h1(self, interpreter): def test_h1(self, interpreter):
self._create_el_and_basic_asserts("h1", "some text", interpreter) self._create_el_and_basic_asserts("h1", "some text", interpreter)
@@ -316,7 +328,8 @@ class TestElements(PyScriptTest):
"height": "200", "height": "200",
} }
self._create_el_and_basic_asserts( self._create_el_and_basic_asserts(
"iframe", interpreter, "iframe",
interpreter,
properties=properties, properties=properties,
expected_errors=[ expected_errors=[
"Failed to load resource: the server responded with a status of 404 (File not found)" "Failed to load resource: the server responded with a status of 404 (File not found)"
@@ -351,7 +364,9 @@ class TestElements(PyScriptTest):
"required": True, "required": True,
"size": 20, "size": 20,
} }
self._create_el_and_basic_asserts("input_", interpreter=interpreter, properties=properties) self._create_el_and_basic_asserts(
"input_", interpreter=interpreter, properties=properties
)
def test_ins(self, interpreter): def test_ins(self, interpreter):
self._create_el_and_basic_asserts( self._create_el_and_basic_asserts(
@@ -409,7 +424,9 @@ class TestElements(PyScriptTest):
"high": 80, "high": 80,
"optimum": 50, "optimum": 50,
} }
self._create_el_and_basic_asserts("meter", "some text", interpreter, properties=properties) self._create_el_and_basic_asserts(
"meter", "some text", interpreter, properties=properties
)
def test_nav(self, interpreter): def test_nav(self, interpreter):
self._create_el_and_basic_asserts("nav", "some text", interpreter) self._create_el_and_basic_asserts("nav", "some text", interpreter)