Skip to content

Commit 7ed42c0

Browse files
committed
fix ambiguous raise matches
1 parent 760e3c9 commit 7ed42c0

File tree

6 files changed

+13
-14
lines changed

6 files changed

+13
-14
lines changed

asdf/_tests/_block/test_io.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def test_write_oversized_block():
169169
data = np.ones(30, dtype="uint8")
170170
raw_fd = io.BytesIO()
171171
fd = generic_io.get_file(raw_fd, mode="rw")
172-
with pytest.raises(RuntimeError, match="Block used size.*"):
172+
with pytest.raises(RuntimeError, match=r"Block used size.*"):
173173
bio.write_block(fd, data, allocated_size=0)
174174
assert fd.tell() == 0
175175

@@ -190,7 +190,7 @@ def test_fd_not_seekable():
190190

191191
np.testing.assert_array_equal(d, data)
192192

193-
with pytest.raises(ValueError, match="write_block received offset.*"):
193+
with pytest.raises(ValueError, match=r"write_block received offset.*"):
194194
bio.write_block(fd, data, offset=0)
195195

196196

@@ -223,14 +223,14 @@ def test_read_from_closed(tmp_path):
223223
bio.write_block(fd, data, stream=True)
224224
with generic_io.get_file(fn, mode="rw") as fd:
225225
_, _, _, callback = bio.read_block(fd, offset=0, lazy_load=True)
226-
with pytest.raises(OSError, match="ASDF file has already been closed. Can not get the data."):
226+
with pytest.raises(OSError, match=r"ASDF file has already been closed\. Can not get the data\."):
227227
callback()
228228

229229

230230
@pytest.mark.parametrize("data", [np.ones(10, dtype="f4"), np.ones((3, 3), dtype="uint8")])
231231
def test_invalid_data(data):
232232
fd = generic_io.get_file(io.BytesIO(), mode="rw")
233-
with pytest.raises(ValueError, match="Data must be of.*"):
233+
with pytest.raises(ValueError, match=r"Data must be of.*"):
234234
bio.write_block(fd, data, stream=True)
235235

236236

@@ -337,7 +337,7 @@ def test_read_block_index_no_header(tmp_path):
337337
generate_block_index_file(fn, values=values, offset=0)
338338
with generic_io.get_file(fn, "r") as fd:
339339
fd.seek(len(constants.INDEX_HEADER))
340-
with pytest.raises(BlockIndexError, match="Failed to read block index.*"):
340+
with pytest.raises(BlockIndexError, match=r"Failed to read block index.*"):
341341
assert bio.read_block_index(fd) == values
342342

343343

asdf/_tests/_block/test_options.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,27 +68,27 @@ def test_default_compression():
6868

6969
@pytest.mark.parametrize("invalid_storage", invalid_storage_types)
7070
def test_invalid_storage_type_init(invalid_storage):
71-
with pytest.raises(ValueError, match="array_storage must be one of.*"):
71+
with pytest.raises(ValueError, match=r"array_storage must be one of.*"):
7272
Options(invalid_storage)
7373

7474

7575
@pytest.mark.parametrize("invalid_storage", invalid_storage_types)
7676
def test_invalid_storage_attr(invalid_storage):
7777
o = Options("internal")
78-
with pytest.raises(ValueError, match="array_storage must be one of.*"):
78+
with pytest.raises(ValueError, match=r"array_storage must be one of.*"):
7979
o.storage_type = invalid_storage
8080

8181

8282
@pytest.mark.parametrize("invalid_compression", invalid_compression_types)
8383
def test_invalid_compression_attr(invalid_compression):
8484
o = Options("internal")
85-
with pytest.raises(ValueError, match="Invalid compression.*"):
85+
with pytest.raises(ValueError, match=r"Invalid compression.*"):
8686
o.compression = invalid_compression
8787

8888

8989
@pytest.mark.parametrize("invalid_compression", invalid_compression_types)
9090
def test_invalid_compression_init(invalid_compression):
91-
with pytest.raises(ValueError, match="Invalid compression.*"):
91+
with pytest.raises(ValueError, match=r"Invalid compression.*"):
9292
Options("internal", invalid_compression)
9393

9494

asdf/_tests/_block/test_reader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def test_invalid_block_index(tmp_path, invalid_block_index):
140140
with pytest.warns(AsdfBlockIndexWarning, match="Failed to read block index"):
141141
check(read_blocks(fd, lazy_load=True))
142142
else:
143-
with pytest.raises(ValueError, match="Header size.*"):
143+
with pytest.raises(ValueError, match=r"Header size.*"):
144144
check(read_blocks(fd, lazy_load=True))
145145

146146

@@ -190,7 +190,7 @@ def test_bad_checksum(validate_checksums):
190190

191191
with generic_io.get_file(buff, mode="r") as fd:
192192
if validate_checksums:
193-
with pytest.raises(ValueError, match=".* does not match given checksum"):
193+
with pytest.raises(ValueError, match=r".* does not match given checksum"):
194194
read_blocks(fd, lazy_load=False, validate_checksums=validate_checksums)[0].data
195195
else:
196196
read_blocks(fd, lazy_load=False, validate_checksums=validate_checksums)[0].data

asdf/_tests/_regtests/test_1539.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ def test_invalid_seek_and_read_from_closed_memoryio():
1717
b.seek(0)
1818
f = asdf.generic_io.get_file(b)
1919
f.close()
20-
with pytest.raises(IOError, match="I/O operation on closed file."):
20+
with pytest.raises(IOError, match=r"I/O operation on closed file\."):
2121
f.read_into_array(10)
2222
assert b.tell() == 0

asdf/_tests/test_extension.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,7 @@ class MailboxExtension:
10371037
assert "mailbox" not in sys.modules
10381038

10391039
# as the module hasn't been loaded, the converter shouldn't be found
1040-
with pytest.raises(KeyError, match="No support available for Python type 'mailbox.Mailbox'"):
1040+
with pytest.raises(KeyError, match=r"No support available for Python type 'mailbox\.Mailbox'"):
10411041
extension_manager.get_converter_for_type(typ)
10421042

10431043
# make sure inspecting the type didn't import the module

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ extend-ignore = [
188188
"S310", # URL open for permitted schemes
189189
"RUF005", # prefer concatenate over add for collections
190190
"RUF012", # mutable-class-default (typing related)
191-
"RUF043", # ambiguous raise
192191
]
193192

194193
[tool.ruff.lint.per-file-ignores]

0 commit comments

Comments
 (0)