Fix #1745 - Throw on multiple configs (#1885)

This MR shows errors and exit in these conditions:

  * multiple `<py-config>` or `<mpy-config>` found on the page
  * both `<py-config>` and `<script type="py" config="file.toml">` found on main
  * different `<script type="py" config="a.toml">`  and `<script type="py" config="b.toml">` configs found on main
This commit is contained in:
Andrea Giammarchi
2023-12-06 14:12:22 +01:00
committed by GitHub
parent 96e671b55f
commit b0377cc7ab
9 changed files with 163 additions and 22 deletions

View File

@@ -100,7 +100,31 @@ class TestConfig(PyScriptTest):
)
assert banner.inner_text() == expected
@pytest.mark.skip("NEXT: emit a warning in case of multiple py-config")
def test_ambiguous_py_config(self):
self.pyscript_run(
"""
<py-config>name = "first"</py-config>
<script type="py" config="second.toml"></script>
""",
wait_for_pyscript=False,
)
banner = self.page.wait_for_selector(".py-error")
expected = "(PY0409): Ambiguous py-config VS config attribute"
assert banner.text_content() == expected
def test_multiple_attributes_py_config(self):
self.pyscript_run(
"""
<script type="py" config="first.toml"></script>
<script type="py" config="second.toml"></script>
""",
wait_for_pyscript=False,
)
banner = self.page.wait_for_selector(".py-error")
expected = "(PY0409): Unable to use different configs on main"
assert banner.text_content() == expected
def test_multiple_py_config(self):
self.pyscript_run(
"""
@@ -117,13 +141,11 @@ class TestConfig(PyScriptTest):
#config = js.pyscript_get_config()
#js.console.log("config name:", config.name)
</script>
"""
)
banner = self.page.wait_for_selector(".py-warning")
expected = (
"Multiple <py-config> tags detected. Only the first "
"is going to be parsed, all the others will be ignored"
""",
wait_for_pyscript=False,
)
banner = self.page.wait_for_selector(".py-error")
expected = "(PY0409): Too many py-config"
assert banner.text_content() == expected
def test_paths(self):