Files
Nicholas Tollervey a02ff691d2 pyscript API/docstring refactor with comprehensive tests (#2414)
* Revise display module. TODO: more comprehensive tests. Especially around mimebundles.

* Markdown corrections in example code in display.py docstrings.

* Minor adjustments and a much more comprehensive test-suite for the display module.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Updated docstring in __init__.py.

* Remove unused imports and black-ify the source.

* Refactor, docs and tests for the Event class in events.py.

* Refactored, simplified and documented @when decorator.

* Extensive test suite for @when decorator.

* Documentation and minor refactoring of the fetch.py module. TODO: Check tests.

* Refactored and more comprehensive tests for the fetch module.

* Add/clarify Event related interactions. Thanks @Neon22 for the suggestion.

* Refactor, document ffi.py module.

* More complete passing tests for ffi.py.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add docstrings to flatted.py. Since this is actually an external(ish) module, tests for it should be in the external repository from which this code is derived.

* Minor docstring cleanup in ffi.py.

* Added docstrings and clarifications to fs.py.

* Add very limited test suite for fs.py.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Rename magic_js.py to context.py, add comprehensive docstrings, and rename certain internal things for readability and comprehension.

* Fix dict check in ffi.py.

* Rename test_js_modules to test_context.

* Fix test configuration aftert rename.

* Docs and refactor of media.py.

* Comprehensive tests for media.py.

* Refactor and docstrings for storage.py

* Appease the ruff gods.

* Further storage.py changes and a more complete test suite for storage.

* Refactor and docstrings for the util.py module. Fixed a problem with is_awaitable not handling async bound methods.

* More comprehensive test suite for util.py. Updated to latest upytest.

* A major refactoring, documenting and simplification of the web.py module substantially reducing it in size and complexity with only a few minor (edge) behavioural changes.

Softly breaking changes include:

- An element's classes are just a set.
- An element's styles are just a dict.
- Explicitly use `update_all` with ElementCollections (simpler and greater flexibility).
- Extract a child element by id with `my_container["#an-id"]`

* Updates and additions for a more comprehensive test suite for the web.py module. All code paths are exercised and checked.

* Black tidy-ups in test suite.

* Refactor and documentation for websocket.py module.

* Tests for websocket.py. Disabled due to playwright flakiness, but they all pass in a local browser.

* Refactor and documentation of workers.py module.

* Added tests for workers.py module. Updated related test suite to account for the new named worker in the test HTML.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Refactor away remaining "is not None" not caught before.

* Remove check-docstring-first because it interferes with the auto-generated documentation (where triple quoted strings are used to document module attributes).

* Careful Markdown changes so the docstrings render properly in the PyScript docs.

* Typo correction.

* More typo corrections and clarifications.

* Add clarification about SVG handling to _render_image docstring.

* Add DOM event options to the @when decorator (with new tests to exercise this functionality).

* Fixes default value for options if no options passed into @when.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2025-12-11 17:19:24 +00:00
..

PyScript Test Suite

There are three aspects to our test suite. These are reflected in the layout of the test directory:

  1. python - contains the Python based test suite to exercise Python code within PyScript. These tests are run four differeng ways to ensure all combination of MicroPython/Pyodide and main thread/worker contexts are checked.
  2. javascript - contains JavaScript tests to exercise PyScript itself, in the browser.
  3. manual - contains tests to run manually in a browser, due to the complex nature of the tests.

We use Playwright to automate the running of the Python and JavaScript test suites. We use uPyTest as a test framework for the Python test suite. uPyTest is a "PyTest inspired" framework for running tests in the browser on both MicroPython and Pyodide.

The automated (Playwright) tests are specified in the integration.spec.js file in this directory.

All automatic tests live in either the python or javascript folders. All the tests in these folder are run by CI or locally run by make test in the root of this project. Alternatively, run npm run test:integration in the PyScript source directory.

Similarly, some tests can only be run manually (due to their nature or underlying complexity). These are in the manual directory and are in the form of separate directories (each containing an index.html) or individual *.html files to which you point your browser. Each separate test may exercise JavaScript or Python code (or both), and the context for each separate test is kept carefully isolated.

Some rules of thumb:

  • We don't test upstream projects: we assume they have their own test suites, and if we find bugs, we file an issue upstream with an example of how to recreate the problem.
  • We don't test browser functionality, we just have to trust that browsers work as advertised. Once again, if we find an issue, we report upstream.
  • All test cases should include commentary describing the intent and context of the test.
  • Tests in Python use uPyTest (see the README for documentation), an "inspired by PyTest" test framework that works with both MicroPython and Pyodide in the browser. This means that all Python tests should work with both interpreters.
  • Tests in JavaScript... (Andrea to explain). ;-)