Skip to content

Commit

Permalink
I’ve updated the project to test the Jinja macros against the fixture…
Browse files Browse the repository at this point in the history
…s generated as part of the GOV.UK Frontend package.

This removes the need to use and maintain the `govuk-frontend-diff` project.

I know in the `govuk-frontend-diff` project it’s set up to give quite a detailed diff if the generated HTML does not match and the way I’ve set it up, to compare strings, may not be quite what
you’re after. I’m happy for any ideas to improve this.
  • Loading branch information
tim-s-ccs committed Apr 17, 2024
1 parent 609740e commit 67a2ccd
Show file tree
Hide file tree
Showing 16 changed files with 280 additions and 52 deletions.
17 changes: 6 additions & 11 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
- name: Install Node dependencies
run: |
npm ci
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 safety
Expand All @@ -37,14 +40,6 @@ jobs:
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=120 --statistics
- name: Prepare to test
run: |
sudo apt-get install wait-for-it
curl -L https://github.com/matthew-shaw/govuk-frontend-diff/releases/download/v2.0.0/govuk-frontend-diff-linux --output govuk-frontend-diff
chmod +x govuk-frontend-diff
- name: Test with govuk-frontend-diff
- name: Test with pytest
run: |
(cd tests/utils && nohup python -m flask run --port 3000 &)
wait-for-it localhost:3000
./govuk-frontend-diff http://localhost:3000 --govuk-frontend-version=v5.1.0 --exclude page-template --ci
pytest
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,27 @@ The options available to each component macro can be found in the original [GOV.

## Running the tests

The tests are run in a GitHub actions pipeline but if you want to run them locally you will need to install [govuk-frontend-diff](https://github.com/matthew-shaw/govuk-frontend-diff).
The tests are run in a GitHub actions pipeline and you can run them locally with `pytest`.

There is a test server at `tests/utils/app.py` which you will need to run using the following command:
You will need to download the GOV.UK Frontend package via npm with:

```bash
(cd tests/utils && python -m flask run --port 3000)
npm i
```

You can then run the tests using `govuk-frontend-diff` as follows:
You can install the requirements for your chosen version of Python with:

```bash
./govuk-frontend-diff http://localhost:3000 --govuk-frontend-version=v4.8.0
pip install -r requirements-test-<YOUR_PYTHON_VERSION>.txt
```

This is all wrapped up in `./test.sh` for simplified running (Requires Docker).
You can then run the tests with:

```bash
pytest
```

The tests compare the HTML for each component fixture, which are within the GOV.UK Frontend package, with HTML generated by the Jinja macros.

## Versioning

Expand Down
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"private": true,
"name": "govuk-frontend-jinja",
"version": "0.0.0",
"author": "Matt Shaw",
"license": "MIT",
"devDependencies": {
"govuk-frontend": "^5.1.0"
}
}
18 changes: 17 additions & 1 deletion requirements-test-3.10.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --output-file=requirements-test-3.10.txt requirements-test.in
Expand All @@ -8,10 +8,16 @@ blinker==1.7.0
# via flask
click==8.1.7
# via flask
exceptiongroup==1.2.0
# via pytest
flake8==7.0.0
# via -r requirements-test.in
flask==3.0.2
# via -r requirements-test.in
importlib-metadata==7.1.0
# via flask
iniconfig==2.0.0
# via pytest
itsdangerous==2.1.2
# via flask
jinja2==3.1.3
Expand All @@ -22,9 +28,19 @@ markupsafe==2.1.5
# werkzeug
mccabe==0.7.0
# via flake8
packaging==24.0
# via pytest
pluggy==1.4.0
# via pytest
pycodestyle==2.11.1
# via flake8
pyflakes==3.2.0
# via flake8
pytest==8.1.1
# via -r requirements-test.in
tomli==2.0.1
# via pytest
werkzeug==3.0.1
# via flask
zipp==3.18.1
# via importlib-metadata
18 changes: 17 additions & 1 deletion requirements-test-3.11.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --output-file=requirements-test-3.11.txt requirements-test.in
Expand All @@ -8,10 +8,16 @@ blinker==1.7.0
# via flask
click==8.1.7
# via flask
exceptiongroup==1.2.0
# via pytest
flake8==7.0.0
# via -r requirements-test.in
flask==3.0.2
# via -r requirements-test.in
importlib-metadata==7.1.0
# via flask
iniconfig==2.0.0
# via pytest
itsdangerous==2.1.2
# via flask
jinja2==3.1.3
Expand All @@ -22,9 +28,19 @@ markupsafe==2.1.5
# werkzeug
mccabe==0.7.0
# via flake8
packaging==24.0
# via pytest
pluggy==1.4.0
# via pytest
pycodestyle==2.11.1
# via flake8
pyflakes==3.2.0
# via flake8
pytest==8.1.1
# via -r requirements-test.in
tomli==2.0.1
# via pytest
werkzeug==3.0.1
# via flask
zipp==3.18.1
# via importlib-metadata
18 changes: 17 additions & 1 deletion requirements-test-3.12.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.12
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --output-file=requirements-test-3.12.txt requirements-test.in
Expand All @@ -8,10 +8,16 @@ blinker==1.7.0
# via flask
click==8.1.7
# via flask
exceptiongroup==1.2.0
# via pytest
flake8==7.0.0
# via -r requirements-test.in
flask==3.0.2
# via -r requirements-test.in
importlib-metadata==7.1.0
# via flask
iniconfig==2.0.0
# via pytest
itsdangerous==2.1.2
# via flask
jinja2==3.1.3
Expand All @@ -22,9 +28,19 @@ markupsafe==2.1.5
# werkzeug
mccabe==0.7.0
# via flake8
packaging==24.0
# via pytest
pluggy==1.4.0
# via pytest
pycodestyle==2.11.1
# via flake8
pyflakes==3.2.0
# via flake8
pytest==8.1.1
# via -r requirements-test.in
tomli==2.0.1
# via pytest
werkzeug==3.0.1
# via flask
zipp==3.18.1
# via importlib-metadata
14 changes: 13 additions & 1 deletion requirements-test-3.8.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.8
# This file is autogenerated by pip-compile with Python 3.9
# by the following command:
#
# pip-compile --output-file=requirements-test-3.8.txt requirements-test.in
Expand All @@ -8,12 +8,16 @@ blinker==1.7.0
# via flask
click==8.1.7
# via flask
exceptiongroup==1.2.0
# via pytest
flake8==7.0.0
# via -r requirements-test.in
flask==3.0.2
# via -r requirements-test.in
importlib-metadata==7.0.1
# via flask
iniconfig==2.0.0
# via pytest
itsdangerous==2.1.2
# via flask
jinja2==3.1.3
Expand All @@ -24,10 +28,18 @@ markupsafe==2.1.5
# werkzeug
mccabe==0.7.0
# via flake8
packaging==24.0
# via pytest
pluggy==1.4.0
# via pytest
pycodestyle==2.11.1
# via flake8
pyflakes==3.2.0
# via flake8
pytest==8.1.1
# via -r requirements-test.in
tomli==2.0.1
# via pytest
werkzeug==3.0.1
# via flask
zipp==3.17.0
Expand Down
12 changes: 12 additions & 0 deletions requirements-test-3.9.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ blinker==1.7.0
# via flask
click==8.1.7
# via flask
exceptiongroup==1.2.0
# via pytest
flake8==7.0.0
# via -r requirements-test.in
flask==3.0.2
# via -r requirements-test.in
importlib-metadata==7.0.1
# via flask
iniconfig==2.0.0
# via pytest
itsdangerous==2.1.2
# via flask
jinja2==3.1.3
Expand All @@ -24,10 +28,18 @@ markupsafe==2.1.5
# werkzeug
mccabe==0.7.0
# via flake8
packaging==24.0
# via pytest
pluggy==1.4.0
# via pytest
pycodestyle==2.11.1
# via flake8
pyflakes==3.2.0
# via flake8
pytest==8.1.1
# via -r requirements-test.in
tomli==2.0.1
# via pytest
werkzeug==3.0.1
# via flask
zipp==3.17.0
Expand Down
1 change: 1 addition & 0 deletions requirements-test.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
flake8
flask
pytest
6 changes: 0 additions & 6 deletions test.sh

This file was deleted.

9 changes: 9 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest

from utils.app import app


@pytest.fixture
def client():
with app.test_client() as client:
yield client
Loading

0 comments on commit 67a2ccd

Please sign in to comment.