Skip to content

Commit 971437f

Browse files
LGA-3267: Add Ruff Format to the pipeline (#25)
1 parent b09547b commit 971437f

File tree

11 files changed

+33
-23
lines changed

11 files changed

+33
-23
lines changed

.github/workflows/static-analysis.yml

+8-3
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ jobs:
3434
name: Ruff
3535
runs-on: ubuntu-latest
3636
steps:
37-
- uses: actions/checkout@v4
38-
- uses: chartboost/ruff-action@v1
37+
- name: Checkout
38+
uses: actions/checkout@v4
39+
- name: Lint
40+
uses: chartboost/ruff-action@v1
3941
with:
4042
args: check --output-format=github
41-
src: './src'
43+
- name: Format
44+
uses: chartboost/ruff-action@v1
45+
with:
46+
args: format --check
4247

4348
sonarcloud:
4449
name: Sonar cloud

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ repos:
1313
files: requirements-(base|production).in
1414
args: [requirements/source/requirements-production.in, "--output-file", requirements/generated/requirements-production.txt]
1515
- repo: https://github.com/astral-sh/ruff-pre-commit
16-
rev: v0.5.4
16+
rev: v0.6.2
1717
hooks:
1818
- id: ruff
1919
args: [ --fix ]

app/__init__.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ def create_app(config_class=Config):
133133
)
134134
# Concat all headscripts seperately so they can be loaded into the DOM head.
135135
headscripts = Bundle(
136-
"src/js/headscripts/*.js",
137-
filters="jsmin",
138-
output="dist/js/headscripts.min.js"
136+
"src/js/headscripts/*.js", filters="jsmin", output="dist/js/headscripts.min.js"
139137
)
140138
if "css" not in assets:
141139
assets.register("css", css)

app/main/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
bp = Blueprint("main", __name__, template_folder="../templates/main")
44

55
from app.main import routes # noqa: E402,F401
6-
from app.main import filters
6+
from app.main import filters # noqa: E402,F401

app/main/filters.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
@bp.app_template_filter("dict")
66
def str_to_dict(s):
7-
""" Uses the JSON module to parse a string into a dict.
7+
"""Uses the JSON module to parse a string into a dict.
88
This can be invoked in Jinja templates using:
99
{{ '{"spam": "eggs"}' | dict }}
1010
@@ -16,7 +16,7 @@ def str_to_dict(s):
1616

1717
@bp.app_template_filter("get_item")
1818
def get_item_from_dict(d, s):
19-
""" Gets an item from a dict safely returning None if it is not present
19+
"""Gets an item from a dict safely returning None if it is not present
2020
This can be invoked in Jinja templates using:
2121
{{ '{"spam": "eggs"}' | dict | get_item("spam") }}
2222

app/main/gtm.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,7 @@ def detect_gtm_anon_id():
3333
def remember_gtm_anon_id(response):
3434
session["gtm_anon_id"] = str(uuid.uuid4())
3535
expiration_date = datetime.now(UTC) + timedelta(days=30)
36-
response.set_cookie("gtm_anon_id", session.get("gtm_anon_id"), expires=expiration_date)
36+
response.set_cookie(
37+
"gtm_anon_id", session.get("gtm_anon_id"), expires=expiration_date
38+
)
3739
return response

requirements/generated/requirements-development.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ requests==2.32.3
124124
# pytest-base-url
125125
rich==13.7.1
126126
# via flask-limiter
127-
ruff==0.5.4
127+
ruff==0.6.2
128128
# via -r requirements/source/requirements-development.in
129129
sentry-sdk[flask]==2.10.0
130130
# via -r requirements/source/requirements-base.in

tests/functional_tests/conftest.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
from app import create_app
44
from flask import url_for
55

6+
67
class TestConfig(Config):
78
TESTING = True
89
DEBUG = True
910
SERVER_NAME = "localhost"
1011
RATELIMIT_ENABLED = False
1112
SECRET_KEY = "TEST_KEY"
1213

14+
1315
@pytest.fixture(scope="session")
1416
def app():
1517
app = create_app(TestConfig)
@@ -28,4 +30,4 @@ def runner(app):
2830

2931
@pytest.fixture(scope="function", autouse=True)
3032
def startup(app, page):
31-
page.goto(url_for('main.index', _external=True))
33+
page.goto(url_for("main.index", _external=True))

tests/functional_tests/test_accessibility.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88

99
ACCESSIBILITY_STANDARDS = ["wcag2a", "wcag2aa"]
1010

11+
1112
def check_accessibility(page: Page):
12-
'''
13+
"""
1314
Inserts axe core python into a page at the yield step
1415
to run accessibility based testing. Axe will run on
1516
the page defined in the function.
16-
'''
17+
"""
1718
if page.title() != "localhost":
1819
directory = "tests/functional_tests/accessibility_output"
1920
if not os.path.exists(directory):
@@ -24,16 +25,16 @@ def check_accessibility(page: Page):
2425

2526
wcag_violations = []
2627

27-
for violation in results['violations']:
28+
for violation in results["violations"]:
2829
if set(violation["tags"]) & set(ACCESSIBILITY_STANDARDS):
2930
wcag_violations.append(violation)
30-
31+
3132
if len(wcag_violations) == 0:
3233
assert "No WCAG accessibility issues found"
3334
else:
3435
# Cleans the URL to remove any invalid characters and replace with _
3536
invalid_filename_chars = r'[\/:*?"<>|]'
36-
sanitized_title = re.sub(invalid_filename_chars, '_', page.title())
37+
sanitized_title = re.sub(invalid_filename_chars, "_", page.title())
3738

3839
max_title_len = 30
3940
file_name = f"axe_results_{sanitized_title[:max_title_len]}.json"
@@ -44,17 +45,18 @@ def check_accessibility(page: Page):
4445

4546
@pytest.mark.usefixtures("live_server")
4647
def test_all_page_accessibility(app, page: Page):
47-
ignored_routes = ['static', '/']
48+
ignored_routes = ["static", "/"]
4849
routes = app.view_functions
4950
for route in routes:
5051
if route not in ignored_routes:
5152
full_url = url_for(route, _external=True)
5253
page.goto(full_url)
5354
check_accessibility(page)
5455

56+
5557
def test_accessibility_folder():
56-
path = 'tests/functional_tests/accessibility_output'
58+
path = "tests/functional_tests/accessibility_output"
5759
if not any(os.scandir(path)):
5860
assert True
5961
else:
60-
assert not 'WCAG accessibility issues found'
62+
assert not "WCAG accessibility issues found"
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from playwright.sync_api import Page
22
import pytest
33

4+
45
@pytest.mark.usefixtures("live_server")
56
def test_base_accessibility(page: Page):
6-
pass
7+
pass

tests/unit_tests/test_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
def test_coverage():
22
# Test Pytest coverage
33
assert 1 + 1 == 2
4-
pass
4+
pass

0 commit comments

Comments
 (0)