Skip to content

Commit e38edc6

Browse files
authored
Merge pull request #264 from SciCatProject/setup-for-integration-testing
Setup for integration testing
2 parents 56fafdf + dc2d6d4 commit e38edc6

File tree

12 files changed

+122
-49
lines changed

12 files changed

+122
-49
lines changed

.github/workflows/ci.yml

+13-18
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
jobs:
1111
formatting:
1212
name: Formatting and static analysis
13-
runs-on: ubuntu-22.04
13+
runs-on: ubuntu-24.04
1414
steps:
1515
- uses: actions/checkout@v4
1616
- uses: actions/setup-python@v5
@@ -24,7 +24,7 @@ jobs:
2424
type-checking:
2525
name: Type checking
2626
needs: formatting
27-
runs-on: ubuntu-22.04
27+
runs-on: ubuntu-24.04
2828
steps:
2929
- uses: actions/checkout@v4
3030
- uses: actions/setup-python@v5
@@ -35,28 +35,23 @@ jobs:
3535
- run: tox -e mypy
3636

3737
tests:
38-
name: Tests ${{ matrix.os }} ${{ matrix.tox }}
38+
name: Tests
3939
needs: formatting
40-
runs-on: ${{ matrix.os }}
4140
strategy:
4241
matrix:
4342
include:
44-
- {python: '3.13', os: ubuntu-22.04, tox: py313-full}
45-
- {python: '3.12', os: ubuntu-22.04, tox: py312-full}
46-
- {python: '3.11', os: ubuntu-22.04, tox: py311-full}
47-
- {python: '3.10', os: ubuntu-22.04, tox: py310-full}
43+
- {python: '3.13', os: ubuntu-24.04, tox: py313-full}
44+
- {python: '3.12', os: ubuntu-24.04, tox: py312-full}
45+
- {python: '3.11', os: ubuntu-24.04, tox: py311-full}
46+
- {python: '3.10', os: ubuntu-24.04, tox: py310-full}
4847
- {python: '3.10', os: macos-14, tox: py310}
4948
- {python: '3.10', os: windows-2022, tox: py310}
50-
steps:
51-
- run: sudo apt install --yes docker-compose
52-
if: ${{ contains(matrix.os, 'ubuntu') }}
53-
- uses: actions/checkout@v4
54-
- uses: actions/setup-python@v5
55-
with:
56-
python-version: ${{ matrix.python }}
57-
- run: python -m pip install --upgrade pip
58-
- run: python -m pip install -r requirements/ci.txt
59-
- run: tox -e ${{ matrix.tox }}
49+
uses: ./.github/workflows/test.yml
50+
with:
51+
os-variant: ${{ matrix.os }}
52+
python-version: ${{ matrix.python }}
53+
tox-env: ${{ matrix.tox }}
54+
secrets: inherit
6055

6156
docs:
6257
needs: tests

.github/workflows/docs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ on:
1818
jobs:
1919
docs:
2020
name: Build documentation
21-
runs-on: ubuntu-22.04
21+
runs-on: ubuntu-24.04
2222
steps:
2323
- run: sudo apt install --yes pandoc
2424
- uses: actions/checkout@v4

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
jobs:
99
build_wheels:
1010
name: Wheels
11-
runs-on: ubuntu-22.04
11+
runs-on: ubuntu-24.04
1212

1313
steps:
1414
- uses: actions/checkout@v4
@@ -31,7 +31,7 @@ jobs:
3131
upload_packages:
3232
name: Deploy packages
3333
needs: [build_wheels]
34-
runs-on: ubuntu-22.04
34+
runs-on: ubuntu-24.04
3535
environment:
3636
name: release
3737
url: https://pypi.org/p/scitacean/

.github/workflows/test.yml

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: Test
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
os-variant:
7+
default: 'ubuntu-24.04'
8+
type: string
9+
description: 'Operating system'
10+
python-version:
11+
type: string
12+
description: 'Python interpreter version'
13+
tox-env:
14+
default: 'test'
15+
type: string
16+
description: 'Tox environment to run'
17+
checkout-ref:
18+
default: ''
19+
type: string
20+
description: 'Git ref to checkout'
21+
backend-version:
22+
default: ''
23+
type: string
24+
description: 'SciCat backend version, e.g., "v4.8.0"'
25+
workflow_call:
26+
inputs:
27+
os-variant:
28+
default: 'ubuntu-24.04'
29+
type: string
30+
python-version:
31+
type: string
32+
tox-env:
33+
default: 'test'
34+
type: string
35+
checkout-ref:
36+
default: ''
37+
type: string
38+
backend-version:
39+
default: ''
40+
type: string
41+
42+
jobs:
43+
tests:
44+
name: Tests ${{ inputs.os-variant }} ${{ inputs.tox-env }}
45+
runs-on: ${{ inputs.os-variant }}
46+
steps:
47+
- run: sudo apt install --yes docker-compose
48+
if: ${{ contains(inputs.os-variant, 'ubuntu') }}
49+
- uses: actions/checkout@v4
50+
with:
51+
ref: ${{ inputs.checkout-ref }}
52+
- uses: actions/setup-python@v5
53+
with:
54+
python-version: ${{ inputs.python-version }}
55+
- run: python -m pip install --upgrade pip
56+
- run: python -m pip install -r requirements/ci.txt
57+
- run: tox -e ${{ inputs.tox-env }}
58+
if: ${{ !inputs.backend-version }}
59+
- run: tox -e ${{ inputs.tox-env }} -- ${{ inputs.backend-version }}
60+
if: ${{ inputs.backend-version }}

docs/user-guide/testing.ipynb

+5-9
Original file line numberDiff line numberDiff line change
@@ -390,21 +390,19 @@
390390
"cell_type": "code",
391391
"execution_count": null,
392392
"id": "29",
393-
"metadata": {
394-
"tags": []
395-
},
393+
"metadata": {},
396394
"outputs": [],
397395
"source": [
398396
"import pytest\n",
399-
"from scitacean.testing.backend import add_pytest_option as add_backend_option\n",
397+
"from scitacean.testing.backend import add_pytest_options as add_backend_options\n",
400398
"\n",
401399
"\n",
402400
"pytest_plugins = (\n",
403401
" \"scitacean.testing.backend.fixtures\",\n",
404402
")\n",
405403
"\n",
406404
"def pytest_addoption(parser: pytest.Parser) -> None:\n",
407-
" add_backend_option(parser)"
405+
" add_backend_options(parser)"
408406
]
409407
},
410408
{
@@ -413,7 +411,7 @@
413411
"metadata": {},
414412
"source": [
415413
"The backend will only be launched when the corresponding command line option is given.\n",
416-
"By default, this is `--backend-tests` but it can be changed via the `option` argument of `add_pytest_option`.\n",
414+
"By default, this is `--backend-tests` but it can be changed via the `option` argument of `add_pytest_options`.\n",
417415
"\n",
418416
"### Use SciCat in tests\n",
419417
"\n",
@@ -424,9 +422,7 @@
424422
"cell_type": "code",
425423
"execution_count": null,
426424
"id": "31",
427-
"metadata": {
428-
"tags": []
429-
},
425+
"metadata": {},
430426
"outputs": [],
431427
"source": [
432428
"def test_something_with_scicat(require_scicat_backend):\n",

src/scitacean/testing/backend/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def test_manual_client(require_scicat_backend, scicat_access):
6161
.. autosummary::
6262
:toctree: ../functions
6363
64-
add_pytest_option
64+
add_pytest_options
6565
backend_enabled
6666
configure
6767
skip_if_not_backend
@@ -77,10 +77,10 @@ def test_manual_client(require_scicat_backend, scicat_access):
7777
stop_backend,
7878
wait_until_backend_is_live,
7979
)
80-
from ._pytest_helpers import add_pytest_option, backend_enabled, skip_if_not_backend
80+
from ._pytest_helpers import add_pytest_options, backend_enabled, skip_if_not_backend
8181

8282
__all__ = [
83-
"add_pytest_option",
83+
"add_pytest_options",
8484
"backend_enabled",
8585
"config",
8686
"configure",

src/scitacean/testing/backend/_backend.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def _docker_compose_template() -> dict[str, Any]:
3131

3232

3333
def _apply_config(
34-
template: dict[str, Any], account_config_path: Path
34+
template: dict[str, Any],
35+
account_config_path: Path,
36+
version: str | None,
3537
) -> dict[str, Any]:
3638
res = deepcopy(template)
3739
scicat = res["services"]["scicat"]
@@ -47,20 +49,29 @@ def _apply_config(
4749
f"{account_config_path}:/home/node/app/functionalAccounts.json",
4850
]
4951

52+
if version is not None:
53+
url = scicat["image"].split(":")[0]
54+
scicat["image"] = f"{url}:{version}"
55+
5056
return res
5157

5258

53-
def configure(target_path: _PathLike) -> None:
59+
def configure(target_path: _PathLike, *, version: str | None = None) -> None:
5460
"""Build a docker-compose file for the testing backend.
5561
5662
Parameters
5763
----------
5864
target_path:
5965
Generate a docker-compose file at this path.
66+
version:
67+
The backend version to use, e.g., ``"v4.8.0"``.
68+
If not provided, the latest version will be used that is known to be compatible.
6069
"""
6170
account_config_path = Path(target_path).parent / "functionalAccounts.json"
6271
config.dump_account_config(account_config_path)
63-
c = yaml.dump(_apply_config(_docker_compose_template(), account_config_path))
72+
c = yaml.dump(
73+
_apply_config(_docker_compose_template(), account_config_path, version)
74+
)
6475
if "PLACEHOLDER" in c:
6576
raise RuntimeError("Incorrect config")
6677

src/scitacean/testing/backend/_pytest_helpers.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
_COMMAND_LINE_OPTION: str | None = None
88

99

10-
def add_pytest_option(parser: pytest.Parser, option: str = "--backend-tests") -> None:
11-
"""Add a command-line option to pytest to toggle backend tests.
10+
def add_pytest_options(parser: pytest.Parser, option: str = "--backend-tests") -> None:
11+
"""Add command-line options to pytest to control backend tests.
1212
1313
Parameters
1414
----------
1515
parser:
1616
Pytest's command-line argument parser.
1717
option:
18-
Name of the command-line option.
18+
Name of the command-line option to toggle backend tests.
1919
"""
2020
parser.addoption(
2121
option,
@@ -26,6 +26,12 @@ def add_pytest_option(parser: pytest.Parser, option: str = "--backend-tests") ->
2626
global _COMMAND_LINE_OPTION
2727
_COMMAND_LINE_OPTION = option
2828

29+
parser.addoption(
30+
"--scitacean-backend-version",
31+
default=None,
32+
help="Specify a version for the SciCat backend",
33+
)
34+
2935

3036
def skip_if_not_backend(request: pytest.FixtureRequest) -> None:
3137
"""Mark the current test to be skipped if backend tests are disabled."""

src/scitacean/testing/backend/docker-compose-backend-template.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# before it can be used by docker compose.
44
#
55
# The images are based on the CI setup of the SciCat backend
6-
# and the latest stable package:
7-
# https://github.com/SciCatProject/scicat-backend-next/pkgs/container/backend-next/97880429?tag=stable
6+
# and a released package of the version configured in pyproject.toml:
7+
# https://github.com/SciCatProject/scicat-backend-next/pkgs/container/backend-next/versions
88
#
99
# See https://scicatproject.github.io/documentation/Development/v4.x/backend/configuration.html
1010
# for a list of all env variables.

src/scitacean/testing/backend/fixtures.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,12 @@ def scicat_backend(request, tmp_path_factory, scicat_access):
147147
):
148148
yield False
149149
else:
150+
version = request.config.getoption("--scitacean-backend-version")
150151
with _prepare_with_backend(
151-
scicat_access=scicat_access, target_dir=target_dir, counter=counter
152+
scicat_access=scicat_access,
153+
target_dir=target_dir,
154+
counter=counter,
155+
version=version,
152156
):
153157
yield True
154158

@@ -174,11 +178,12 @@ def _prepare_with_backend(
174178
scicat_access: SciCatAccess,
175179
counter: FileCounter | NullCounter,
176180
target_dir: Path,
181+
version: str | None,
177182
) -> Generator[None, None, None]:
178183
try:
179184
with counter.increment() as count:
180185
if count == 1:
181-
_backend_docker_up(target_dir)
186+
_backend_docker_up(target_dir, version)
182187
_seed_database(
183188
Client, scicat_access=scicat_access, target_dir=target_dir
184189
)
@@ -206,15 +211,15 @@ def _seed_database(
206211
seed.save_seed(target_dir)
207212

208213

209-
def _backend_docker_up(target_dir: Path) -> None:
214+
def _backend_docker_up(target_dir: Path, version: str | None) -> None:
210215
if _backend_is_running():
211216
raise RuntimeError("SciCat docker container is already running")
212217
docker_compose_file = target_dir / "docker-compose.yaml"
213218
log = logging.getLogger("scitacean.testing")
214219
log.info(
215220
"Starting docker container with SciCat backend from %s", docker_compose_file
216221
)
217-
configure(docker_compose_file)
222+
configure(docker_compose_file, version=version)
218223
docker.docker_compose_up(docker_compose_file)
219224
log.info("Waiting for SciCat docker to become accessible")
220225
wait_until_backend_is_live(max_time=60, n_tries=40)

tests/conftest.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import hypothesis
55
import pytest
66

7-
from scitacean.testing.backend import add_pytest_option as add_backend_option
7+
from scitacean.testing.backend import add_pytest_options as add_backend_options
88
from scitacean.testing.sftp import add_pytest_option as add_sftp_option
99

1010
pytest_plugins = (
@@ -26,5 +26,5 @@
2626

2727

2828
def pytest_addoption(parser: pytest.Parser) -> None:
29-
add_backend_option(parser)
29+
add_backend_options(parser)
3030
add_sftp_option(parser)

tox.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ isolated_build = true
55
[testenv]
66
deps = -r requirements/test.txt
77
commands =
8-
full: python -m pytest --backend-tests --sftp-tests
9-
!full: python -m pytest
8+
full: python -m pytest --backend-tests --sftp-tests {posargs}
9+
!full: python -m pytest {posargs}
1010

1111
[testenv:docs]
1212
description = invoke sphinx-build to build the HTML docs

0 commit comments

Comments
 (0)