skip to main content

@tonyfast s notebooks

site navigation
notebook summary
title
slicing and dicing accessibility violations with exception groups
description
exception groups are a new feature, motivated by async applications, to raise multiple unrelated exceptions. this is the ideal representation of bulk accessibility audits. capturing accessibility and inaccessibility in formal testing environments prevents regressions and organizes the entropy of bulk inaccessibilities.
cells
12 total
5 code
state
executed in order
kernel
Python [conda env:test-nbconvert-a11y]
language
python
name
conda-env-test-nbconvert-a11y-py
lines of code
37
outputs
2
table of contents
{"kernelspec": {"display_name": "Python [conda env:test-nbconvert-a11y]", "language": "python", "name": "conda-env-test-nbconvert-a11y-py"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.6"}, "widgets": {"application/vnd.jupyter.widget-state+json": {"state": {}, "version_major": 2, "version_minor": 0}}, "title": "slicing and dicing accessibility violations with exception groups", "description": "exception groups are a new feature, motivated by async applications, to raise multiple unrelated exceptions. this is the ideal representation of bulk accessibility audits.\ncapturing accessibility and inaccessibility in formal testing environments prevents regressions\nand organizes the entropy of bulk inaccessibilities."}
notebook toolbar
Activate
cell ordering
1

slicing and dicing accessibility violations with exception groups

exception groups are a new feature, motivated by async applications, to raise multiple unrelated exceptions. this is the ideal representation of bulk accessibility audits. capturing accessibility and inaccessibility in formal testing environments prevents regressions and organizes the entropy of bulk inaccessibilities.

2
    from nbconvert_a11y import pytest_axe
    assert pytest_axe.get_npm_directory("axe-core"), "axe isn't installed"
3

use the new async axe machinery to generate accessibility test results.

4
    async with pytest_axe.AsyncAxe(
        url="https://nbviewer.org/github/jupyterlab/jupyterlab-demo/blob/master/notebooks/Lorenz.ipynb"
    ) as axe:
            await axe.run()
5
    known_failures = axe.exc["serious-color-contrast-enhanced"], axe.exc["serious-color-contrast"], axe.exc["a fixed violation"]
6

we discover accessibility violations when we run axe. this audit is a snapshot in time. code changes and accessibility focused efforts may eliminate known accessibility violations. known inaccessibilities are expected_failures while remediated violations are contained in unexpected_passes .

7
    expected_failures, failures = axe.results.exception().split(known_failures)
    assert all((expected_failures, failures))
    print(
        "expected failures", expected_failures,
        "undocumented accessibility violations", failures, sep="\n"
    )
1 outputs.
expected failures
8 accessibility violations (2 sub-exceptions)
undocumented accessibility violations
8 accessibility violations (6 sub-exceptions)

8

unexpected_passes are interesting scenarios require maintenance to the accessibility tests to update and document improvements.

9
    (unexpected_passes := tuple(set(map(type, expected_failures.exceptions)).symmetric_difference(known_failures)))
1 outputs.
(nbconvert_a11y.pytest_axe.a fixed violation,)
10

these sets of exceptions and types provide different perspectives on the state of accessibility. i try to capture some of these ideas in the four states of knowing we can on a test:

11
i know it is i know it is not
i don't know it is i don't know it is not

these states map to different collections and sets of failures.

it is it is not
i know pass expected failure
i don't know unexpected pass failure
12

there is value in this multi dimensional testing system that verifies accessibility and admits to inaccessibilities. this approach will prove useful in retrofitting inaccessible systems.