Skip to content

Commit 57c5887

Browse files
committed
Fix tabs, add ruff and black
1 parent 652ac9f commit 57c5887

File tree

14 files changed

+108
-59
lines changed

14 files changed

+108
-59
lines changed

.github/workflows/python.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Python checks
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build:
11+
name: Test with Python ${{ matrix.python_version }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
python_version: ["3.9", "3.10", "3.11"]
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Set up Python 3
20+
uses: actions/setup-python@v3
21+
with:
22+
python-version: ${{ matrix.python_version }}
23+
- name: Install dependencies
24+
run: |
25+
python -m pip install --upgrade pip
26+
pip install poetry
27+
poetry install
28+
- name: Lint with ruff
29+
run: ruff .
30+
- name: Check formatting with black
31+
run: black . --check --verbose
32+
- name: Run unit tests
33+
run: |
34+
poetry run pytest

CONTRIBUTING.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ Install [poetry](https://python-poetry.org/).
66

77
Install the project dependencies:
88

9-
```
9+
```sh
1010
poetry install
1111
```
1212

1313
Run the tests:
1414

15-
```
15+
```sh
1616
poetry run pytest
1717
```
1818

@@ -21,32 +21,32 @@ poetry run pytest
2121

2222
Set credentials for PyPi:
2323

24-
```
24+
```sh
2525
poetry config pypi-token.pypi <token>
2626
```
2727

2828
Build the wheels:
2929

30-
```
30+
```sh
3131
poetry build
3232
```
3333

3434
Publish to PyPi:
3535

36-
```
36+
```sh
3737
poetry publish
3838
```
3939

4040
## Documentation
4141

4242
Build locally:
4343

44-
```
44+
```sh
4545
mkdocs serve
4646
```
4747

4848
Deploy to GitHub Pages:
4949

50-
```
50+
```sh
5151
mkdocs gh-deploy
5252
```

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,8 @@ For more examples see [documentation](https://pamelafox.github.io/axe-playwright
4242

4343
## Contributing
4444

45-
See [guide on contributing](CONTRIBUTING.md).
45+
See [guide on contributing](CONTRIBUTING.md).
46+
47+
## Acknowledgments
48+
49+
This project is based on [axe-core-python](https://github.com/ruslan-rv-ua/axe-core-python) by @ruslan-rv-ua and also takes inspiration from [axe-selenium-python](https://pypi.org/project/axe-selenium-python/) for output formats.

axe_playwright_python/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.1.0'
1+
__version__ = "0.1.0"

axe_playwright_python/base.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
import json
2+
import os
13
from abc import ABC, abstractmethod
24
from pathlib import Path
3-
import os
4-
import json
55
from string import Template
66

7-
87
AXE_FILE_NAME = "axe.min.js"
98
AXE_FILE_PATH = Path(__file__).parent / AXE_FILE_NAME
109

@@ -56,8 +55,7 @@ def from_file(cls, axe_min_js_path: str | Path) -> "AxeBase":
5655
return cls(axe_script=axe_script)
5756

5857

59-
class AxeResults():
60-
58+
class AxeResults:
6159
def __init__(self, response: dict):
6260
self.response = response
6361

@@ -66,7 +64,7 @@ def violations_count(self) -> int:
6664
"""
6765
Number of violations found.
6866
"""
69-
return len(self.response['violations'])
67+
return len(self.response["violations"])
7068

7169
def generate_snapshot(self):
7270
"""
@@ -75,22 +73,22 @@ def generate_snapshot(self):
7573
<violation-id> (impact) : <number-of-nodes>
7674
"""
7775
snapshot_lines = []
78-
for v in self.response['violations']:
76+
for v in self.response["violations"]:
7977
snapshot_lines.append(f"{v['id']} ({v['impact']}) : {len(v['nodes'])}")
80-
return '\n'.join(snapshot_lines)
78+
return "\n".join(snapshot_lines)
8179

8280
def __violation_report(self, violation: dict, template: Template) -> str:
8381
nodes_str = ""
8482
for num, node in enumerate(violation["nodes"], start=1):
85-
targets = ', '.join(node["target"])
83+
targets = ", ".join(node["target"])
8684
nodes_str += f"\n\n\t{num})\tTarget: {targets}"
87-
snippet = node.get('html').replace('\n', '')
85+
snippet = node.get("html").replace("\n", "")
8886
nodes_str += f"\n\t\tSnippet: {snippet}"
8987
nodes_str += "\n\t\tMessages:"
9088
for item in node.get("all", []) + node.get("any", []) + node.get("none", []):
9189
nodes_str += "\n\t\t* " + item["message"]
9290
return template.substitute(violation, elements=nodes_str)
93-
91+
9492
def generate_report(self, violation_id: str | None = None) -> str:
9593
"""
9694
Return readable report of accessibility violations found.
@@ -109,9 +107,10 @@ def generate_report(self, violation_id: str | None = None) -> str:
109107
continue
110108
report_str += self.__violation_report(violation, template)
111109
return report_str
112-
113-
def save_to_file(self, file_path: str | Path | None = None,
114-
violations_only: bool = False) -> None:
110+
111+
def save_to_file(
112+
self, file_path: str | Path | None = None, violations_only: bool = False
113+
) -> None:
115114
"""Save results to file.
116115
@param results: Results from Axe analysis
117116
@param file_path: File path for saving results file
@@ -126,5 +125,3 @@ def save_to_file(self, file_path: str | Path | None = None,
126125
cwd = Path.cwd()
127126
file_path = cwd / "results.json"
128127
Path(file_path).write_text(json.dumps(response, indent=4))
129-
130-

axe_playwright_python/sync_playwright.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def run(
1919
options (dict | None, optional): options.
2020
Defaults to {"resultTypes": ["violations"]}.
2121
22-
For more information on `context` and `options`,
22+
For more information on `context` and `options`,
2323
view the [axe-core documentation]().
2424
2525
Returns:
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Rule Violated:
22
$id - $description
3-
URL: $helpUrl
4-
Impact Level: $impact
5-
Tags: $tags
6-
Elements Affected:
7-
$elements
3+
URL: $helpUrl
4+
Impact Level: $impact
5+
Tags: $tags
6+
Elements Affected:
7+
$elements

examples/usage.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from playwright.sync_api import sync_playwright
21
from axe_core_python.sync_playwright import Axe
2+
from playwright.sync_api import sync_playwright
33

44
axe = Axe()
55

@@ -8,4 +8,4 @@
88
page = browser.new_page()
99
page.goto("https://www.google.com")
1010
results = axe.run(page)
11-
browser.close()
11+
browser.close()

pyproject.toml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "axe-playwright-python"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
description = "Automated web accessibility testing using axe-core engine and Playwright."
55
authors = ["Pamela Fox <[email protected]>"]
66
readme = "README.md"
@@ -12,15 +12,17 @@ classifiers = [
1212
"Development Status :: 5 - Production/Stable",
1313
"Programming Language :: Python",
1414
"Programming Language :: Python :: 3",
15+
"Programming Language :: Python :: 3.9",
1516
"Programming Language :: Python :: 3.10",
17+
"Programming Language :: Python :: 3.11",
1618
"Topic :: Adaptive Technologies",
1719
"Topic :: Software Development",
1820
"Topic :: Software Development :: Quality Assurance",
1921
"Topic :: Software Development :: Testing",
2022
]
2123

2224
[tool.poetry.dependencies]
23-
python = "^3.10"
25+
python = "^3.9"
2426
playwright = "^1.36.0"
2527

2628
[tool.poetry.dev-dependencies]
@@ -35,3 +37,14 @@ flake8 = "^6.0.0"
3537
[build-system]
3638
requires = ["poetry-core>=1.0.0"]
3739
build-backend = "poetry.core.masonry.api"
40+
41+
[tool.ruff]
42+
line-length = 100
43+
target-version = "py39"
44+
select = ["E", "F", "I", "UP"]
45+
ignore = ["D203"]
46+
show-source = true
47+
48+
[tool.black]
49+
line-length = 100
50+
target-version = ["py39"]

tests/test_axe_async_playwright.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import pytest
44
import pytest_asyncio
5-
from axe_playwright_python.async_playwright import Axe
65
from playwright.async_api import async_playwright
76

7+
from axe_playwright_python.async_playwright import Axe
8+
89
TEST_FILE = "test_page.html"
910
TEST_FILE_PATH = Path(__file__).parent.absolute() / TEST_FILE
1011

0 commit comments

Comments
 (0)