Skip to content

Commit f53fe61

Browse files
committed
refactor: Replace requests_mock calls with responses
1 parent 953ec68 commit f53fe61

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

tests/modules/create.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import os
22

33
import pytest
4-
import requests_mock
4+
import responses
55

66
import nf_core.modules
77
from tests.utils import mock_api_calls
88

99

1010
def test_modules_create_succeed(self):
1111
"""Succeed at creating the TrimGalore! module"""
12-
with requests_mock.Mocker() as mock:
13-
mock_api_calls(mock, "trim-galore", "0.6.7")
12+
with responses.RequestsMock() as rsps:
13+
mock_api_calls(rsps, "trim-galore", "0.6.7")
1414
module_create = nf_core.modules.ModuleCreate(
1515
self.pipeline_dir, "trimgalore", "@author", "process_single", True, True, conda_name="trim-galore"
1616
)
@@ -20,8 +20,8 @@ def test_modules_create_succeed(self):
2020

2121
def test_modules_create_fail_exists(self):
2222
"""Fail at creating the same module twice"""
23-
with requests_mock.Mocker() as mock:
24-
mock_api_calls(mock, "trim-galore", "0.6.7")
23+
with responses.RequestsMock() as rsps:
24+
mock_api_calls(rsps, "trim-galore", "0.6.7")
2525
module_create = nf_core.modules.ModuleCreate(
2626
self.pipeline_dir, "trimgalore", "@author", "process_single", False, False, conda_name="trim-galore"
2727
)
@@ -33,8 +33,8 @@ def test_modules_create_fail_exists(self):
3333

3434
def test_modules_create_nfcore_modules(self):
3535
"""Create a module in nf-core/modules clone"""
36-
with requests_mock.Mocker() as mock:
37-
mock_api_calls(mock, "fastqc", "0.11.9")
36+
with responses.RequestsMock() as rsps:
37+
mock_api_calls(rsps, "fastqc", "0.11.9")
3838
module_create = nf_core.modules.ModuleCreate(
3939
self.nfcore_modules, "fastqc", "@author", "process_low", False, False
4040
)
@@ -45,8 +45,8 @@ def test_modules_create_nfcore_modules(self):
4545

4646
def test_modules_create_nfcore_modules_subtool(self):
4747
"""Create a tool/subtool module in a nf-core/modules clone"""
48-
with requests_mock.Mocker() as mock:
49-
mock_api_calls(mock, "star", "2.8.10a")
48+
with responses.RequestsMock() as rsps:
49+
mock_api_calls(rsps, "star", "2.8.10a")
5050
module_create = nf_core.modules.ModuleCreate(
5151
self.nfcore_modules, "star/index", "@author", "process_medium", False, False
5252
)

tests/test_modules.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import tempfile
77
import unittest
88

9-
import requests_mock
9+
import responses
1010

1111
import nf_core.create
1212
import nf_core.modules
@@ -35,8 +35,8 @@ def create_modules_repo_dummy(tmp_dir):
3535
fh.writelines(["repository_type: modules", "\n", "org_path: nf-core", "\n"])
3636

3737
# mock biocontainers and anaconda response
38-
with requests_mock.Mocker() as mock:
39-
mock_api_calls(mock, "bpipe", "0.9.11--hdfd78af_0")
38+
with responses.RequestsMock() as rsps:
39+
mock_api_calls(rsps, "bpipe", "0.9.11--hdfd78af_0")
4040
# bpipe is a valid package on bioconda that is very unlikely to ever be added to nf-core/modules
4141
module_create = nf_core.modules.ModuleCreate(root_dir, "bpipe/test", "@author", "process_single", False, False)
4242
module_create.create()

tests/test_subworkflows.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import tempfile
77
import unittest
88

9-
import requests_mock
9+
import responses
1010

1111
import nf_core.create
1212
import nf_core.modules
@@ -30,7 +30,8 @@ def create_modules_repo_dummy(tmp_dir):
3030
with open(os.path.join(root_dir, ".nf-core.yml"), "w") as fh:
3131
fh.writelines(["repository_type: modules", "\n", "org_path: nf-core", "\n"])
3232

33-
with requests_mock.Mocker() as mock:
33+
# FIXME This mock isn't used
34+
with responses.RequestsMock() as rsps:
3435
subworkflow_create = nf_core.subworkflows.SubworkflowCreate(root_dir, "test_subworkflow", "@author", True)
3536
subworkflow_create.create()
3637

tests/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from contextlib import contextmanager
99
from pathlib import Path
1010

11+
import responses
12+
1113
OLD_TRIMGALORE_SHA = "06348dffce2a732fc9e656bdc5c64c3e02d302cb"
1214
OLD_TRIMGALORE_BRANCH = "mimic-old-trimgalore"
1315
GITLAB_URL = "https://gitlab.com/nf-core/modules-test.git"
@@ -68,14 +70,13 @@ def set_wd(path: Path):
6870
os.chdir(start_wd)
6971

7072

71-
def mock_api_calls(mock, module, version):
73+
def mock_api_calls(rsps: responses.RequestsMock, module, version):
7274
"""Mock biocontainers and anaconda api calls for module"""
7375
biocontainers_api_url = (
7476
f"https://api.biocontainers.pro/ga4gh/trs/v2/tools/{module}/versions/{module}-{version.split('--')[0]}"
7577
)
7678
anaconda_api_url = f"https://api.anaconda.org/package/bioconda/{module}"
7779
anaconda_mock = {
78-
"status_code": 200,
7980
"latest_version": version.split("--")[0],
8081
"summary": "",
8182
"doc_url": "",
@@ -84,7 +85,6 @@ def mock_api_calls(mock, module, version):
8485
"license": "",
8586
}
8687
biocontainers_mock = {
87-
"status_code": 200,
8888
"images": [
8989
{
9090
"image_type": "Singularity",
@@ -98,5 +98,5 @@ def mock_api_calls(mock, module, version):
9898
},
9999
],
100100
}
101-
mock.register_uri("GET", anaconda_api_url, json=anaconda_mock)
102-
mock.register_uri("GET", biocontainers_api_url, json=biocontainers_mock)
101+
rsps.get(anaconda_api_url, json=anaconda_mock, status=200)
102+
rsps.get(biocontainers_api_url, json=biocontainers_mock, status=200)

0 commit comments

Comments
 (0)