From 6e3a1d3ac7098837cc311b0649ca2a2dcd0f3261 Mon Sep 17 00:00:00 2001 From: Sandro Date: Feb 21 2024 12:29:36 +0000 Subject: Patch out xnat4tests Unfortunately, we cannot ship xnat4tests due to its license. So, patch it out and run whatever tests remain. --- diff --git a/no_xnat4tests.patch b/no_xnat4tests.patch new file mode 100644 index 0000000..3892c1c --- /dev/null +++ b/no_xnat4tests.patch @@ -0,0 +1,72 @@ +diff --git a/conftest.py b/conftest.py +index ee7e614..eaf93ad 100644 +--- a/conftest.py ++++ b/conftest.py +@@ -25,9 +25,6 @@ import requests.cookies + import pytest + from pytest_mock import MockerFixture + +-from xnat4tests import start_xnat, stop_xnat, add_data, Config +-from xnat4tests.utils import set_loggers +- + import xnat + from xnat.session import XNATSession + from xnat.tests.mock import XnatpyRequestsMocker, CreatedObject +@@ -144,57 +141,3 @@ def xnatpy_connection(mocker: MockerFixture, + # Stop patch of threading + mocker.stop(threading_patch) + +- +-# Fixtures for xnat4tests, setup a config, use the pytest tmp_path_factory fixture for the tmpdir +-@pytest.fixture(scope="session") +-def xnat4tests_config(tmp_path_factory) -> Config: +- tmp_path = tmp_path_factory.mktemp('config') +- +- docker_host = os.environ.get('DOCKER_HOST') +- if docker_host: +- print(f'Docker host set in environment set to {docker_host}.') +- docker_host = urlparse(docker_host).netloc.split(':')[0] +- else: +- print('No docker host set in environment, using localhost as default.') +- docker_host = 'localhost' +- print(f'Determined docker hostname to be {docker_host}') +- +- set_loggers(loglevel='INFO') +- yield Config( +- xnat_root_dir=tmp_path, +- xnat_port=8080, +- docker_image="xnatpy_xnat4tests", +- docker_container="xnatpy_xnat4tests", +- docker_host=docker_host, +- build_args={ +- "xnat_version": "1.8.5", +- "xnat_cs_plugin_version": "3.2.0", +- }, +- connection_attempts=15, +- connection_attempt_sleep=10, +- ) +- +- +-# Create a context to ensure closure +-@contextlib.contextmanager +-def xnat4tests(config) -> str: +- start_xnat(config_name=config) +- try: +- add_data("dummydicom", config_name=config) +- yield config.xnat_uri +- finally: +- stop_xnat(config_name=config) +- +- +-# Fixtures for xnat4tests, start up a container and get the URI +-@pytest.fixture(scope="session") +-def xnat4tests_uri(xnat4tests_config) -> str: +- with xnat4tests(xnat4tests_config): +- yield xnat4tests_config.xnat_uri +- +- +-# Fixtures for xnat4tests, create an xnatpy connection +-@pytest.fixture(scope="session") +-def xnat4tests_connection(xnat4tests_uri) -> XNATSession: +- with xnat.connect(xnat4tests_uri, user='admin', password='admin') as connection: +- yield connection diff --git a/python-xnat.spec b/python-xnat.spec index ee13c74..08465a6 100644 --- a/python-xnat.spec +++ b/python-xnat.spec @@ -33,6 +33,10 @@ Source0: %forgesource %else Source0: https://gitlab.com/radiology/infrastructure/xnatpy/-/archive/%{version}/xnatpy-%{version}.tar.bz2 %endif +# xnat4tests is not available in Fedora. It's currently not possible to +# package it either, since it's licensed under CC0-1.0 +# https://github.com/Australian-Imaging-Service/xnat4tests/issues/17 +Patch: no_xnat4tests.patch BuildArch: noarch @@ -48,7 +52,6 @@ BuildRequires: help2man BuildRequires: python3-pytest BuildRequires: python3-pytest-mock BuildRequires: python3-requests-mock -BuildRequires: python3-xnat4tests %endif %description -n python3-xnat @@ -62,6 +65,9 @@ sed -i '1d' xnat/scripts/copy_project.py sed -i '1d' xnat/scripts/data_integrity_check.py sed -i '1d' xnat/scripts/import_experiment_dir.py +# Don't try to import docker (we are not using it) +sed -i '/import docker/d' xnat/tests/test_import.py + %generate_buildrequires %pyproject_buildrequires -r requirements.txt @@ -84,7 +90,10 @@ done %check %if %{with tests} -%{pytest} -v +# Docker tests are skipped automatically if docker is not available. +# To make it explicit of what is being skipped, I added it anyway. +# Funtional tests require xnat4tests. +%pytest -v -m 'not docker_test and not functional_test' %else # Import test currently fails # https://gitlab.com/radiology/infrastructure/xnatpy/-/issues/57