Skip to content

Commit 5a4ef0f

Browse files
Fix pytest.raises match regex ruff rule
1 parent 0212730 commit 5a4ef0f

12 files changed

Lines changed: 38 additions & 21 deletions

File tree

tilebox-datasets/tests/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def test_datapoint_not_found() -> None:
126126
s2_dataset = client.dataset("open_data.copernicus.sentinel2_msi")
127127
collection = s2_dataset.collection("S2A_S2MSI1C")
128128

129-
with pytest.raises(NotFoundError, match="No such datapoint.*"):
129+
with pytest.raises(NotFoundError, match=r"No such datapoint.*"):
130130
collection.find("0181f4ef-2040-101a-1423-d818e4d1895e") # is in another collection
131131

132132

tilebox-datasets/tests/test_timeseries.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,15 @@ def test_timeseries_dataset_collection_find_invalid_id() -> None:
186186
mocked.collection.find("invalid")
187187

188188
mocked.service.query_by_id.side_effect = ArgumentError
189-
with pytest.raises(ValueError, match="Invalid datapoint id.*"):
189+
with pytest.raises(ValueError, match=r"Invalid datapoint id.*"):
190190
mocked.collection.find(uuid4())
191191

192192

193193
def test_timeseries_dataset_collection_find_not_found() -> None:
194194
"""Test that .find() of a collection raises a NotFoundError if the datapoint is not found."""
195195
mocked = _mocked_collection()
196196
mocked.service.query_by_id.side_effect = NotFoundError
197-
with pytest.raises(NotFoundError, match="No such datapoint.*"):
197+
with pytest.raises(NotFoundError, match=r"No such datapoint.*"):
198198
mocked.collection.find("14eb91a2-a42f-421f-9397-1dab577f05a9")
199199

200200

tilebox-grpc/tests/aio/test_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ async def _mock_rpc() -> None:
3434
self.some_rpc = _mock_rpc
3535

3636
stub = with_pythonic_errors(Stub())
37-
with pytest.raises(exception_type, match=".*"):
37+
with pytest.raises(exception_type, match=r".*"):
3838
await stub.some_rpc()

tilebox-grpc/tests/test_channel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ def test_parse_channel_info_unix(url: str) -> None:
8888

8989

9090
def test_parse_channel_invalid() -> None:
91-
with pytest.raises(ValueError, match="Invalid"):
91+
with pytest.raises(ValueError, match=r"Invalid"):
9292
parse_channel_info("i'm not a url")
9393

9494

9595
def test_parse_channel_port_required_for_http() -> None:
96-
with pytest.raises(ValueError, match="Explicit port required"):
96+
with pytest.raises(ValueError, match=r"Explicit port required"):
9797
parse_channel_info("http://0.0.0.0")

tilebox-grpc/tests/test_error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ def _mock_rpc() -> None:
3838
self.some_rpc = _mock_rpc
3939

4040
stub = with_pythonic_errors(Stub())
41-
with pytest.raises(exception_type, match=".*"):
41+
with pytest.raises(exception_type, match=r".*"):
4242
stub.some_rpc()

tilebox-storage/tests/test_granule.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_granule_from_asf_datapoint(granule: ASFStorageGranule) -> None:
3636
def test_granule_from_asf_datapoints(granules: list[ASFStorageGranule]) -> None:
3737
datapoints = [_asf_granule_to_datapoint(granule) for granule in granules]
3838
dataset = xr.concat(datapoints, dim="time")
39-
with pytest.raises(ValueError, match=".*more than one granule.*"):
39+
with pytest.raises(ValueError, match=r".*more than one granule.*"):
4040
ASFStorageGranule.from_data(dataset)
4141

4242
for i in range(len(granules)): # converting a dataset with a time dimension of 1 should still work though
@@ -75,7 +75,7 @@ def test_granule_from_umbra_datapoint(granule: UmbraStorageGranule) -> None:
7575
def test_granule_from_umbra_datapoints(granules: list[UmbraStorageGranule]) -> None:
7676
datapoints = [_umbra_granule_to_datapoint(granule) for granule in granules]
7777
dataset = xr.concat(datapoints, dim="time")
78-
with pytest.raises(ValueError, match=".*more than one granule.*"):
78+
with pytest.raises(ValueError, match=r".*more than one granule.*"):
7979
UmbraStorageGranule.from_data(dataset)
8080

8181
for i in range(len(granules)): # converting a dataset with a time dimension of 1 should still work though
@@ -141,7 +141,7 @@ def test_granule_from_copernicus_datapoint(granule: CopernicusStorageGranule) ->
141141
def test_granule_from_copernicus_datapoints(granules: list[CopernicusStorageGranule]) -> None:
142142
datapoints = [_copernicus_granule_to_datapoint(granule) for granule in granules]
143143
dataset = xr.concat(datapoints, dim="time")
144-
with pytest.raises(ValueError, match=".*more than one granule.*"):
144+
with pytest.raises(ValueError, match=r".*more than one granule.*"):
145145
CopernicusStorageGranule.from_data(dataset)
146146

147147
for i in range(len(granules)): # converting a dataset with a time dimension of 1 should still work though
@@ -169,7 +169,7 @@ def test_granule_from_landsat_datapoint(granule: USGSLandsatStorageGranule) -> N
169169
def test_granule_from_landsat_datapoints(granules: list[USGSLandsatStorageGranule]) -> None:
170170
datapoints = [_landsat_granule_to_datapoint(granule) for granule in granules]
171171
dataset = xr.concat(datapoints, dim="time")
172-
with pytest.raises(ValueError, match=".*more than one granule.*"):
172+
with pytest.raises(ValueError, match=r".*more than one granule.*"):
173173
USGSLandsatStorageGranule.from_data(dataset)
174174

175175
for i in range(len(granules)): # converting a dataset with a time dimension of 1 should still work though

tilebox-storage/tests/test_providers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
import pytest
24
from httpx import AsyncClient, BasicAuth
35
from pytest_httpx import HTTPXMock
@@ -21,5 +23,5 @@ async def test_asf_login(httpx_mock: HTTPXMock) -> None:
2123
@pytest.mark.asyncio
2224
async def test_asf_login_invalid_auth(httpx_mock: HTTPXMock) -> None:
2325
httpx_mock.add_response(401)
24-
with pytest.raises(ValueError, match="Invalid username or password."):
26+
with pytest.raises(ValueError, match=re.escape("Invalid username or password.")):
2527
await _asf_login(("username", "password"))

tilebox-storage/tests/test_storage_client.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from datetime import timedelta
23
from pathlib import Path
34
from tempfile import TemporaryDirectory
@@ -37,14 +38,14 @@ async def test_client_login(httpx_mock: HTTPXMock) -> None:
3738
async def test_client_login_failed(httpx_mock: HTTPXMock) -> None:
3839
httpx_mock.add_response(401)
3940
client = _HttpClient(auth={"ASF": ("invalid-username", "password")})
40-
with pytest.raises(ValueError, match="Invalid username or password."):
41+
with pytest.raises(ValueError, match=re.escape("Invalid username or password.")):
4142
await client._client("ASF")
4243

4344

4445
@pytest.mark.asyncio
4546
async def test_client_missing_credentials() -> None:
4647
client = _HttpClient(auth={})
47-
with pytest.raises(ValueError, match="Missing credentials.*"):
48+
with pytest.raises(ValueError, match=r"Missing credentials.*"):
4849
await client._client("ASF")
4950

5051

@@ -102,7 +103,7 @@ async def test_download_verify_md5(httpx_mock: HTTPXMock, tmp_path: Path, granul
102103
httpx_mock.add_response(content=b"login-response")
103104
httpx_mock.add_response(stream=IteratorStream([b"my-granule"]))
104105
client = _HttpClient(auth={"ASF": ("username", "password")})
105-
with pytest.raises(ValueError, match=".*md5sum mismatch.*"):
106+
with pytest.raises(ValueError, match=r".*md5sum mismatch.*"):
106107
await client.download(granule, tmp_path, extract=False, show_progress=False)
107108

108109

tilebox-workflows/tests/automations/test_cron.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
from datetime import datetime, timezone
23

34
import pytest
@@ -24,7 +25,9 @@ def test_cron_task_serialization_protobuf() -> None:
2425

2526

2627
def test_cron_task_serialization_requires_trigger() -> None:
27-
with pytest.raises(ValueError, match="CronTask cannot be submitted without being triggered. Use task.once()."):
28+
with pytest.raises(
29+
ValueError, match=re.escape("CronTask cannot be submitted without being triggered. Use task.once().")
30+
):
2831
ExampleCronTask("test", 42)._serialize()
2932

3033

tilebox-workflows/tests/automations/test_storage_event.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import re
2+
13
import pytest
24
from hypothesis import given
35
from tests.proto.test_pb2 import SampleArgs
@@ -30,7 +32,7 @@ def test_storage_event_task_serialization_protobuf() -> None:
3032

3133
def test_storage_event_task_serialization_requires_trigger() -> None:
3234
with pytest.raises(
33-
ValueError, match="StorageEventTask cannot be submitted without being triggered. Use task.once()."
35+
ValueError, match=re.escape("StorageEventTask cannot be submitted without being triggered. Use task.once().")
3436
):
3537
ExampleStorageEventTask("test", 42)._serialize()
3638

0 commit comments

Comments
 (0)