Test refinement. (#2183)

* Test refinement.

* [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:
Nicholas Tollervey
2024-09-26 12:02:25 +01:00
committed by GitHub
parent 06138bbb48
commit f5d49ee52c
12 changed files with 91 additions and 57 deletions

View File

@@ -1,19 +1,20 @@
const qs = new URLSearchParams(location.search);
// src= to NOT have a config
const src = qs.has('src') ? qs.get('src') : './main.py';
// config= to NOT have a src
const config = qs.has('config') ? qs.get('config') : './settings.json';
const src = './main.py';
let config = './settings_mpy.json';
// terminal=0 to NOT have a terminal
const terminal = qs.has('terminal');
const terminal = qs.has('terminal') ? qs.get('terminal') : 1;
// worker=1 to have a worker
const worker = qs.has('worker');
const interpreter = qs.get('type') || 'mpy';
if (interpreter === 'py') {
config = "./settings_py.json";
}
const script = document.createElement('script');
script.type = qs.get('type') || 'mpy';
script.type = interpreter;
if (src) script.src = src;
if (config) script.setAttribute('config', config);
script.toggleAttribute('terminal', terminal);

View File

@@ -4,8 +4,8 @@
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pure Python PyScript tests</title>
<link rel="stylesheet" href="../../../dist/core.css">
<script type="module" src="../../../dist/core.js"></script>
<link rel="stylesheet" href="../../dist/core.css">
<script type="module" src="../../dist/core.js"></script>
</head>
<body>
<script src="./helper.js"></script>

View File

@@ -3,6 +3,6 @@ import json
import upytest
from pyscript import web
result = await upytest.run("./tests")
result = await upytest.run("./tests", random=True)
output = web.div(json.dumps(result), id="result")
web.page.append(output)

View File

@@ -1,6 +1,6 @@
{
"files": {
"https://raw.githubusercontent.com/ntoll/upytest/1.0.7/upytest.py": "",
"https://raw.githubusercontent.com/ntoll/upytest/1.0.8/upytest.py": "",
"./tests/test_config.py": "tests/test_config.py",
"./tests/test_current_target.py": "tests/test_current_target.py",
"./tests/test_display.py": "tests/test_display.py",

View File

@@ -0,0 +1,27 @@
{
"files": {
"https://raw.githubusercontent.com/ntoll/upytest/1.0.8/upytest.py": "",
"./tests/test_config.py": "tests/test_config.py",
"./tests/test_current_target.py": "tests/test_current_target.py",
"./tests/test_display.py": "tests/test_display.py",
"./tests/test_document.py": "tests/test_document.py",
"./tests/test_fetch.py": "tests/test_fetch.py",
"./tests/test_ffi.py": "tests/test_ffi.py",
"./tests/test_js_modules.py": "tests/test_js_modules.py",
"./tests/test_storage.py": "tests/test_storage.py",
"./tests/test_running_in_worker.py": "tests/test_running_in_worker.py",
"./tests/test_web.py": "tests/test_web.py",
"./tests/test_websocket.py": "tests/test_websocket.py",
"./tests/test_when.py": "tests/test_when.py",
"./tests/test_window.py": "tests/test_window.py"
},
"js_modules": {
"main": {
"./example_js_module.js": "greeting"
},
"worker": {
"./example_js_worker_module.js": "greeting_worker"
}
},
"packages": ["Pillow" ]
}

View File

@@ -3,6 +3,7 @@ Tests for the pyscript.config dictionary.
"""
from pyscript import config, document, fetch
from upytest import is_micropython
async def test_config_reads_expected_settings_correctly():
@@ -12,7 +13,8 @@ async def test_config_reads_expected_settings_correctly():
Just grab the raw JSON for the settings and compare it to the config
dictionary.
"""
url = document.location.href.rsplit("/", 1)[0] + "/settings.json"
settings = "/settings_mpy.json" if is_micropython else "/settings_py.json"
url = document.location.href.rsplit("/", 1)[0] + settings
raw_config = await fetch(url).json()
for key, value in raw_config.items():
assert config[key] == value, f"Expected {key} to be {value}, got {config[key]}"

View File

@@ -758,6 +758,10 @@ class TestElements:
}
self._create_el_and_basic_asserts("iframe", properties=properties)
@upytest.skip(
"Flakey on Pyodide in worker.",
skip_when=RUNNING_IN_WORKER and not upytest.is_micropython,
)
async def test_img(self):
"""
This test contains a bespoke version of the _create_el_and_basic_asserts
@@ -797,7 +801,7 @@ class TestElements:
if RUNNING_IN_WORKER:
# Needed to sync the DOM with the worker.
await asyncio.sleep(0.1)
await asyncio.sleep(0.5)
# Check the img element was created correctly and all its properties
# were set correctly.