mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
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:
committed by
GitHub
parent
06138bbb48
commit
f5d49ee52c
8
pyscript.core/package-lock.json
generated
8
pyscript.core/package-lock.json
generated
@@ -12,7 +12,7 @@
|
||||
"@ungap/with-resolvers": "^0.1.0",
|
||||
"@webreflection/idb-map": "^0.3.1",
|
||||
"basic-devtools": "^0.1.6",
|
||||
"polyscript": "^0.15.7",
|
||||
"polyscript": "^0.15.8",
|
||||
"sabayon": "^0.5.2",
|
||||
"sticky-module": "^0.1.1",
|
||||
"to-json-callback": "^0.1.1",
|
||||
@@ -2679,9 +2679,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/polyscript": {
|
||||
"version": "0.15.7",
|
||||
"resolved": "https://registry.npmjs.org/polyscript/-/polyscript-0.15.7.tgz",
|
||||
"integrity": "sha512-2rqB6PW7rE4mZLnSRcCoDpX5/onb9OiTQfXqUi8f7Mt//hxphj6ekBFm2GQ9co3mua0wa3OjYeDXqfHqLE+VMQ==",
|
||||
"version": "0.15.8",
|
||||
"resolved": "https://registry.npmjs.org/polyscript/-/polyscript-0.15.8.tgz",
|
||||
"integrity": "sha512-iBHcFPI2tXM7bw1gNpKZxQ+FIDzhoh/kBbwZtDnikpL6vLk45Tokj4RxaYR83UM6F7OhqoGi+60fer4LG34dCw==",
|
||||
"license": "APACHE-2.0",
|
||||
"dependencies": {
|
||||
"@ungap/structured-clone": "^1.2.0",
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
"build:3rd-party": "node rollup/3rd-party.cjs",
|
||||
"build:tests-index": "node rollup/build_test_index.cjs",
|
||||
"clean:3rd-party": "rm src/3rd-party/*.js && rm src/3rd-party/*.css",
|
||||
"test:integration": "static-handler --coi . 2>/dev/null & SH_PID=$!; EXIT_CODE=0; playwright test --fully-parallel tests/integration.spec.js || EXIT_CODE=$?; kill $SH_PID 2>/dev/null; exit $EXIT_CODE",
|
||||
"test:integration": "static-handler --coi . 2>/dev/null & SH_PID=$!; EXIT_CODE=0; playwright test --fully-parallel tests/js_tests.spec.js tests/py_tests.spec.js || EXIT_CODE=$?; kill $SH_PID 2>/dev/null; exit $EXIT_CODE",
|
||||
"test:ws": "bun tests/ws/index.js & playwright test tests/ws.spec.js",
|
||||
"dev": "node dev.cjs",
|
||||
"release": "npm run build && npm run zip",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -1,41 +1,5 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test('Python unit tests - MicroPython on MAIN thread', async ({ page }) => {
|
||||
await page.goto('http://localhost:8080/tests/python/index.html');
|
||||
test.setTimeout(120*1000); // Increase timeout for this test.
|
||||
const result = page.locator("#result"); // Payload for results will be here.
|
||||
await result.waitFor(); // wait for the result.
|
||||
const data = JSON.parse(await result.textContent()); // get the result data.
|
||||
await expect(data.fails).toMatchObject([]); // ensure no test failed.
|
||||
});
|
||||
|
||||
test('Python unit tests - Pyodide on MAIN thread', async ({ page }) => {
|
||||
await page.goto('http://localhost:8080/tests/python/index.html?type=py');
|
||||
test.setTimeout(120*1000); // Increase timeout for this test.
|
||||
const result = page.locator("#result"); // Payload for results will be here.
|
||||
await result.waitFor(); // wait for the result.
|
||||
const data = JSON.parse(await result.textContent()); // get the result data.
|
||||
await expect(data.fails).toMatchObject([]); // ensure no test failed.
|
||||
});
|
||||
|
||||
test('Python unit tests - MicroPython on WORKER', async ({ page }) => {
|
||||
await page.goto('http://localhost:8080/tests/python/index.html?worker');
|
||||
test.setTimeout(120*1000); // Increase timeout for this test.
|
||||
const result = page.locator("#result"); // Payload for results will be here.
|
||||
await result.waitFor(); // wait for the result.
|
||||
const data = JSON.parse(await result.textContent()); // get the result data.
|
||||
await expect(data.fails).toMatchObject([]); // ensure no test failed.
|
||||
});
|
||||
|
||||
test('Python unit tests - Pyodide on WORKER', async ({ page }) => {
|
||||
await page.goto('http://localhost:8080/tests/python/index.html?type=py&worker');
|
||||
test.setTimeout(120*1000); // Increase timeout for this test.
|
||||
const result = page.locator("#result"); // Payload for results will be here.
|
||||
await result.waitFor(); // wait for the result.
|
||||
const data = JSON.parse(await result.textContent()); // get the result data.
|
||||
await expect(data.fails).toMatchObject([]); // ensure no test failed.
|
||||
});
|
||||
|
||||
test('MicroPython display', async ({ page }) => {
|
||||
await page.goto('http://localhost:8080/tests/javascript/mpy.html');
|
||||
await page.waitForSelector('html.done.worker');
|
||||
@@ -130,7 +94,6 @@ test('MicroPython + JS Storage', async ({ page }) => {
|
||||
});
|
||||
|
||||
test('MicroPython + workers', async ({ page }) => {
|
||||
test.setTimeout(120*1000); // Increase timeout for this test.
|
||||
await page.goto('http://localhost:8080/tests/javascript/workers/index.html');
|
||||
await page.waitForSelector('html.mpy.py');
|
||||
});
|
||||
37
pyscript.core/tests/py_tests.spec.js
Normal file
37
pyscript.core/tests/py_tests.spec.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
test('Python unit tests - MicroPython on MAIN thread', async ({ page }) => {
|
||||
await page.goto('http://localhost:8080/tests/python/index.html');
|
||||
test.setTimeout(120*1000); // Increase timeout for this test.
|
||||
const result = page.locator("#result"); // Payload for results will be here.
|
||||
await result.waitFor(); // wait for the result.
|
||||
const data = JSON.parse(await result.textContent()); // get the result data.
|
||||
await expect(data.fails).toMatchObject([]); // ensure no test failed.
|
||||
});
|
||||
|
||||
test('Python unit tests - Pyodide on MAIN thread', async ({ page }) => {
|
||||
await page.goto('http://localhost:8080/tests/python/index.html?type=py');
|
||||
test.setTimeout(120*1000); // Increase timeout for this test.
|
||||
const result = page.locator("#result"); // Payload for results will be here.
|
||||
await result.waitFor(); // wait for the result.
|
||||
const data = JSON.parse(await result.textContent()); // get the result data.
|
||||
await expect(data.fails).toMatchObject([]); // ensure no test failed.
|
||||
});
|
||||
|
||||
test('Python unit tests - MicroPython on WORKER', async ({ page }) => {
|
||||
await page.goto('http://localhost:8080/tests/python/index.html?worker');
|
||||
test.setTimeout(120*1000); // Increase timeout for this test.
|
||||
const result = page.locator("#result"); // Payload for results will be here.
|
||||
await result.waitFor(); // wait for the result.
|
||||
const data = JSON.parse(await result.textContent()); // get the result data.
|
||||
await expect(data.fails).toMatchObject([]); // ensure no test failed.
|
||||
});
|
||||
|
||||
test('Python unit tests - Pyodide on WORKER', async ({ page }) => {
|
||||
await page.goto('http://localhost:8080/tests/python/index.html?type=py&worker');
|
||||
test.setTimeout(120*1000); // Increase timeout for this test.
|
||||
const result = page.locator("#result"); // Payload for results will be here.
|
||||
await result.waitFor(); // wait for the result.
|
||||
const data = JSON.parse(await result.textContent()); // get the result data.
|
||||
await expect(data.fails).toMatchObject([]); // ensure no test failed.
|
||||
});
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
27
pyscript.core/tests/python/settings_py.json
Normal file
27
pyscript.core/tests/python/settings_py.json
Normal 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" ]
|
||||
}
|
||||
@@ -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]}"
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user