提交 b6316e83 authored 作者: Virgile Andreani's avatar Virgile Andreani 提交者: Virgile Andreani

Apply rule RUF043

上级 e27a43a0
......@@ -45,7 +45,7 @@ class TestOpFromGraph(unittest_tools.InferShapeTester):
def test_valid_input(self):
x, y, z = matrices("xyz")
with pytest.raises(ValueError, match="Expected at least.*"):
with pytest.raises(ValueError, match=r"Expected at least.*"):
OpFromGraph([x], [x])()
with pytest.raises(ValueError, match=r"Expected 1 input\(s\)"):
......
......@@ -264,7 +264,7 @@ class TestComputeTestValue:
fn=fx, outputs_info=pt.ones_like(A.T), non_sequences=A, n_steps=k
)
with pytest.raises(ValueError, match="^could not broadcast input"):
with pytest.raises(ValueError, match=r"^could not broadcast input"):
pytensor.scan(
fn=fx, outputs_info=pt.ones_like(A.T), non_sequences=A, n_steps=k
)
......
......@@ -62,8 +62,8 @@ class TestFunctionGraph:
with pytest.raises(
ValueError,
match=(
"One of the provided inputs is the output of an already existing node. "
"If that is okay, either discard that input's owner or use graph.clone."
"One of the provided inputs is the output of an already existing node\\. "
"If that is okay, either discard that input's owner or use graph\\.clone\\."
),
):
var3 = op1(var1)
......@@ -208,7 +208,7 @@ class TestFunctionGraph:
assert var5 in fg.variables
assert var5.owner in fg.apply_nodes
with pytest.raises(TypeError, match="Computation graph contains.*"):
with pytest.raises(TypeError, match=r"Computation graph contains.*"):
from pytensor.graph.null_type import NullType
fg.import_var(NullType()(), "testing")
......@@ -265,7 +265,7 @@ class TestFunctionGraph:
assert var6.tag.test_value.shape != var4.tag.test_value.shape
with pytest.raises(AssertionError, match="The replacement.*"):
with pytest.raises(AssertionError, match=r"The replacement.*"):
fg.replace(var4, var6)
def test_replace(self):
......@@ -342,12 +342,12 @@ class TestFunctionGraph:
var5 = op3(var4, var2, var2)
fg = FunctionGraph([var1, var2], [var3, var5], clone=False)
with pytest.raises(Exception, match="The following nodes are .*"):
with pytest.raises(Exception, match=r"The following nodes are .*"):
fg.apply_nodes.remove(var5.owner)
fg.check_integrity()
with pytest.raises(Exception, match="Inconsistent clients.*"):
with pytest.raises(Exception, match=r"Inconsistent clients.*"):
fg.apply_nodes.add(var5.owner)
fg.remove_client(var2, (var5.owner, 1))
......@@ -355,14 +355,14 @@ class TestFunctionGraph:
fg.add_client(var2, (var5.owner, 1))
with pytest.raises(Exception, match="The following variables are.*"):
with pytest.raises(Exception, match=r"The following variables are.*"):
fg.variables.remove(var4)
fg.check_integrity()
fg.variables.add(var4)
with pytest.raises(Exception, match="Undeclared input.*"):
with pytest.raises(Exception, match=r"Undeclared input.*"):
var6 = MyVariable2("var6")
fg.clients[var6] = [(var5.owner, 3)]
fg.variables.add(var6)
......@@ -376,26 +376,26 @@ class TestFunctionGraph:
# TODO: What if the index value is greater than 1? It will throw an
# `IndexError`, but that doesn't sound like anything we'd want.
out_node = Output(idx=1).make_node(var4)
with pytest.raises(Exception, match="Inconsistent clients list.*"):
with pytest.raises(Exception, match=r"Inconsistent clients list.*"):
fg.add_client(var4, (out_node, 0))
fg.check_integrity()
fg.remove_client(var4, (out_node, 0))
with pytest.raises(TypeError, match="The first entry of.*"):
with pytest.raises(TypeError, match=r"The first entry of.*"):
fg.add_client(var4, (None, 0))
var7 = op1(var4)
with pytest.raises(Exception, match="Client not in FunctionGraph.*"):
with pytest.raises(Exception, match=r"Client not in FunctionGraph.*"):
fg.add_client(var4, (var7.owner, 0))
fg.check_integrity()
fg.remove_client(var4, (var7.owner, 0))
with pytest.raises(Exception, match="Inconsistent clients list.*"):
with pytest.raises(Exception, match=r"Inconsistent clients list.*"):
fg.add_client(var4, (var3.owner, 0))
fg.check_integrity()
......
......@@ -662,7 +662,7 @@ def test_unaligned_RandomVariable(rv_op, dist_args, base_size, cdf_name, params_
(10, 4),
pytest.raises(
ValueError,
match="Vectorized input 0 has an incompatible shape in axis 1.",
match="Vectorized input 0 has an incompatible shape in axis 1\\.",
),
),
],
......
......@@ -108,7 +108,7 @@ def test_softmax(axis, dtype):
if dtype == "int64":
with pytest.raises(
NotImplementedError,
match="Pytorch Softmax is not currently implemented for non-float types.",
match="Pytorch Softmax is not currently implemented for non-float types\\.",
):
compare_pytorch_and_py([x], [out], [test_input])
else:
......@@ -125,7 +125,7 @@ def test_logsoftmax(axis, dtype):
if dtype == "int64":
with pytest.raises(
NotImplementedError,
match="Pytorch LogSoftmax is not currently implemented for non-float types.",
match="Pytorch LogSoftmax is not currently implemented for non-float types\\.",
):
compare_pytorch_and_py([x], [out], [test_input])
else:
......
......@@ -24,9 +24,9 @@ def test_pytorch_CumOp(axis, dtype):
# Create the output variable
if isinstance(axis, tuple):
with pytest.raises(TypeError, match="axis must be an integer or None."):
with pytest.raises(TypeError, match="axis must be an integer or None\\."):
out = pt.cumsum(a, axis=axis)
with pytest.raises(TypeError, match="axis must be an integer or None."):
with pytest.raises(TypeError, match="axis must be an integer or None\\."):
out = pt.cumprod(a, axis=axis)
else:
out = pt.cumsum(a, axis=axis)
......
......@@ -421,7 +421,7 @@ def test_VMLinker_exception():
z = BadOp()(a)
with pytest.raises(Exception, match=".*Apply node that caused the error.*"):
with pytest.raises(Exception, match=r".*Apply node that caused the error.*"):
function([a], z, mode=Mode(optimizer=None, linker=linker))
......@@ -433,7 +433,7 @@ def test_VM_exception():
a = scalar()
fg = FunctionGraph(outputs=[SomeOp()(a)])
with pytest.raises(ValueError, match="`nodes` and `thunks`.*"):
with pytest.raises(ValueError, match=r"`nodes` and `thunks`.*"):
SomeVM(fg, fg.apply_nodes, [], [])
......@@ -453,7 +453,7 @@ def test_Loop_exception():
thunks = [node.op.make_thunk(node, storage_map, compute_map, []) for node in nodes]
with pytest.raises(ValueError, match="`nodes`, `thunks` and `post_thunk_clear`.*"):
with pytest.raises(ValueError, match=r"`nodes`, `thunks` and `post_thunk_clear`.*"):
Loop(
fg,
fg.apply_nodes,
......
......@@ -79,5 +79,5 @@ def test_SparseTensorType_filter():
x_res = z.type.filter(x.astype("float32"), allow_downcast=True)
assert x_res.dtype == "float64"
with pytest.raises(TypeError, match=".*dtype but got.*"):
with pytest.raises(TypeError, match=r".*dtype but got.*"):
w.type.filter(x)
......@@ -32,7 +32,7 @@ def test_RandomVariable_basics(strict_test_value_flags):
assert str_res == 'normal_rv{"(),()->()"}'
# `ndims_params` should be a `Sequence` type
with pytest.raises(TypeError, match="^Parameter ndims_params*"):
with pytest.raises(TypeError, match=r"^Parameter ndims_params*"):
RandomVariable(
"normal",
0,
......@@ -42,7 +42,7 @@ def test_RandomVariable_basics(strict_test_value_flags):
)
# `size` should be a `Sequence` type
with pytest.raises(TypeError, match="^Parameter size*"):
with pytest.raises(TypeError, match=r"^Parameter size*"):
RandomVariable(
"normal",
0,
......
......@@ -284,7 +284,7 @@ class TestSharedRandomStream:
def test_supp_shape_from_ref_param_shape():
with pytest.raises(ValueError, match="^ndim_supp*"):
with pytest.raises(ValueError, match=r"^ndim_supp*"):
supp_shape_from_ref_param_shape(
ndim_supp=0,
dist_params=(np.array([1, 2]), 0),
......@@ -306,7 +306,7 @@ def test_supp_shape_from_ref_param_shape():
)
assert res == (2,)
with pytest.raises(ValueError, match="^Reference parameter*"):
with pytest.raises(ValueError, match=r"^Reference parameter*"):
supp_shape_from_ref_param_shape(
ndim_supp=1,
dist_params=(np.array(1),),
......
......@@ -298,7 +298,7 @@ class TestLocalCanonicalizeAlloc:
# Error raised by SpecifyShape that is introduced due to static shape inference
with pytest.raises(
AssertionError,
match="SpecifyShape: dim 0 of input has shape 3, expected 6.",
match="SpecifyShape: dim 0 of input has shape 3, expected 6\\.",
):
f()
else:
......
......@@ -589,7 +589,7 @@ class TestAsTensorVariable:
def test_ndim_incompatible(self):
x = TensorType(config.floatX, shape=(1, None))("x")
with pytest.raises(ValueError, match="^Tensor of type.*"):
with pytest.raises(ValueError, match=r"^Tensor of type.*"):
as_tensor_variable(x, ndim=0)
def test_bool(self):
......@@ -898,7 +898,7 @@ class TestAlloc:
def test_infer_static_shape():
with pytest.raises(TypeError, match="^Shapes must be scalar integers.*"):
with pytest.raises(TypeError, match=r"^Shapes must be scalar integers.*"):
infer_static_shape([constant(1.0)])
with (
......@@ -907,7 +907,7 @@ def test_infer_static_shape():
):
infer_static_shape([dscalar("x")])
with pytest.raises(ValueError, match=".*could not be cast to have 0 dimensions"):
with pytest.raises(ValueError, match=r".*could not be cast to have 0 dimensions"):
infer_static_shape((as_tensor_variable([[1, 2]]),))
constant_size = constant([1])
......@@ -1269,7 +1269,7 @@ def test_get_vector_length():
as_tensor_variable([1, 2], ndim=1),
as_tensor_variable([3, 4], ndim=1),
)
with pytest.raises(ValueError, match="^Length of .*"):
with pytest.raises(ValueError, match=r"^Length of .*"):
get_vector_length(z)
# Test `MakeVector`s
......@@ -1329,13 +1329,13 @@ class TestJoinAndSplit:
return variables
def test_input_validation(self):
with pytest.raises(TypeError, match=".*integer.*"):
with pytest.raises(TypeError, match=r".*integer.*"):
Split(2)(matrix(), dscalar(), [1, 1])
with pytest.raises(TypeError, match=".*integer.*"):
with pytest.raises(TypeError, match=r".*integer.*"):
Split(2)(matrix(), ivector(), [1, 1])
with pytest.raises(TypeError, match=".*integer.*"):
with pytest.raises(TypeError, match=r".*integer.*"):
join(dscalar(), matrix(), matrix())
def test_join_scalar(self):
......@@ -3131,7 +3131,7 @@ def test_default():
assert f(None, 2) == 2
assert f(1, None) == 1
with pytest.raises(TypeError, match=".*compatible types.*"):
with pytest.raises(TypeError, match=r".*compatible types.*"):
default(x, vector())
......@@ -3622,7 +3622,7 @@ class TestDiag:
@pytest.mark.parametrize("inp", (scalar, tensor3))
def test_diag_invalid_input_ndim(self, inp):
x = inp()
with pytest.raises(ValueError, match="Input must be 1- or 2-d."):
with pytest.raises(ValueError, match="Input must be 1- or 2-d\\."):
diag(x)
......
......@@ -1374,7 +1374,7 @@ def test_concat_with_broadcast():
with pytest.raises(
TypeError,
match="Only tensors with the same number of dimensions can be concatenated.",
match="Only tensors with the same number of dimensions can be concatenated\\.",
):
a = pt.tensor("a", shape=(1, 3, 5))
b = pt.tensor("b", shape=(3, 5))
......
......@@ -1462,7 +1462,7 @@ class TestMinMax:
def test_MaxAndArgmax_deprecated():
with pytest.raises(
AttributeError,
match="The class `MaxandArgmax` has been deprecated. Call `Max` and `Argmax` seperately as an alternative.",
match="The class `MaxandArgmax` has been deprecated\\. Call `Max` and `Argmax` seperately as an alternative\\.",
):
pytensor.tensor.math.MaxAndArgmax
......
......@@ -495,14 +495,14 @@ class TestSpecifyShape(utt.InferShapeTester):
f = pytensor.function([x, shape], y, mode=Mode("py"))
assert f([1], (1,)) == [1]
with pytest.raises(AssertionError, match="SpecifyShape:.*"):
with pytest.raises(AssertionError, match=r"SpecifyShape:.*"):
assert f([1], (2,)) == [1]
x = matrix()
y = specify_shape(x, (None, 2))
f = pytensor.function([x], y, mode=Mode("py"))
assert f(np.zeros((3, 2), dtype=config.floatX)).shape == (3, 2)
with pytest.raises(AssertionError, match="SpecifyShape:.*"):
with pytest.raises(AssertionError, match=r"SpecifyShape:.*"):
assert f(np.zeros((3, 3), dtype=config.floatX))
def test_bad_shape(self):
......@@ -516,7 +516,7 @@ class TestSpecifyShape(utt.InferShapeTester):
assert np.array_equal(f(xval), xval)
xval = np.random.random(3).astype(config.floatX)
with pytest.raises(AssertionError, match="SpecifyShape:.*"):
with pytest.raises(AssertionError, match=r"SpecifyShape:.*"):
f(xval)
assert isinstance(
......@@ -540,14 +540,14 @@ class TestSpecifyShape(utt.InferShapeTester):
for shape_ in [(4, 3), (2, 8)]:
xval = np.random.random(shape_).astype(config.floatX)
with pytest.raises(AssertionError, match="SpecifyShape:.*"):
with pytest.raises(AssertionError, match=r"SpecifyShape:.*"):
f(xval)
s = iscalar("s")
f = pytensor.function([x, s], specify_shape(x, None, s), mode=self.mode)
x_val = np.zeros((3, 2), dtype=config.floatX)
assert f(x_val, 2).shape == (3, 2)
with pytest.raises(AssertionError, match="SpecifyShape:.*"):
with pytest.raises(AssertionError, match=r"SpecifyShape:.*"):
f(xval, 3)
def test_infer_shape(self):
......
......@@ -240,7 +240,7 @@ class TestSolveBase:
def test_solve_raises_on_invalid_assume_a():
with pytest.raises(ValueError, match="Invalid assume_a: test. It must be one of"):
with pytest.raises(ValueError, match="Invalid assume_a: test\\. It must be one of"):
Solve(assume_a="test", b_ndim=2)
......
......@@ -1364,12 +1364,12 @@ class TestSubtensor(utt.OptimizationTestMixin):
f(np.ones((20, 5))) # Fine
with pytest.raises(
ValueError,
match="Runtime broadcasting not allowed. AdvancedIncSubtensor1 was asked",
match="Runtime broadcasting not allowed\\. AdvancedIncSubtensor1 was asked",
):
f(np.ones((1, 5)))
with pytest.raises(
ValueError,
match="Runtime broadcasting not allowed. AdvancedIncSubtensor1 was asked",
match="Runtime broadcasting not allowed\\. AdvancedIncSubtensor1 was asked",
):
f(np.ones((20, 1)))
......@@ -2903,7 +2903,7 @@ def test_get_vector_length():
assert get_vector_length(lvector()[1:1]) == 0
assert get_vector_length(lvector()[-1:-1:3]) == 0
with pytest.raises(ValueError, match="^Length of .*"):
with pytest.raises(ValueError, match=r"^Length of .*"):
get_vector_length(x[lscalar() :])
......
......@@ -115,7 +115,7 @@ def test_filter_variable():
with pytest.raises(TypeError):
test_type.filter(np.empty((0, 1), dtype=config.floatX))
with pytest.raises(TypeError, match=".*not aligned.*"):
with pytest.raises(TypeError, match=r".*not aligned.*"):
test_val = np.empty((1, 2), dtype=config.floatX)
test_val.flags.aligned = False
test_type.filter(test_val)
......
......@@ -150,7 +150,9 @@ class TestConfigTypes:
cp._apply("cuda123")
with pytest.raises(ValueError, match="It was removed from PyTensor"):
cp._apply("gpu123")
with pytest.raises(ValueError, match='Valid options start with one of "cpu".'):
with pytest.raises(
ValueError, match='Valid options start with one of "cpu"\\.'
):
cp._apply("notadevice")
assert str(cp) == "unnamed (cpu)"
......@@ -247,7 +249,7 @@ def test_config_pickling():
)
with pytest.raises(
AttributeError,
match="Can't (pickle|get) local object 'test_config_pickling.<locals>.<lambda>'",
match=r"Can't (pickle|get) local object 'test_config_pickling\.<locals>\.<lambda>'",
):
pickle.dump(root, io.BytesIO())
......
......@@ -335,9 +335,9 @@ class TestIfelse(utt.OptimizationTestMixin):
z = matrix("csr", dtype=self.dtype, name="z")
cond = iscalar("cond")
with pytest.raises(TypeError, match=".*do not match."):
with pytest.raises(TypeError, match=r".*do not match."):
ifelse(cond, x, y)
with pytest.raises(TypeError, match=".*do not match."):
with pytest.raises(TypeError, match=r".*do not match."):
ifelse(cond, y, x)
with pytest.raises(TypeError):
ifelse(cond, x, z)
......
......@@ -411,7 +411,7 @@ def test_adv_index_update(mode, idx_dtype):
else:
with pytest.raises(
IndexError,
match="Boolean indexer should be unlabeled or on the same dimension to the indexed array.",
match="Boolean indexer should be unlabeled or on the same dimension to the indexed array\\.",
):
getattr(x[idx.rename(a="b"), :3], mode)(y)
vectorized_update = x
......
......@@ -349,11 +349,11 @@ def test_squeeze_errors():
# Non-existent dimension
x1 = xtensor("x1", dims=("city", "country"), shape=(3, 1))
with pytest.raises(ValueError, match="Dimension .* not found"):
with pytest.raises(ValueError, match=r"Dimension .* not found"):
x1.squeeze("time")
# Dimension size > 1
with pytest.raises(ValueError, match="has static size .* not 1"):
with pytest.raises(ValueError, match=r"has static size .* not 1"):
x1.squeeze("city")
# Symbolic shape: dim is not 1 at runtime → should raise
......@@ -579,7 +579,7 @@ class TestBroadcast:
y = xtensor("y", dims=("c", "d"), shape=(5, 6))
z = xtensor("z", dims=("b", "d"), shape=(4, 7))
with pytest.raises(ValueError, match="Dimension .* has conflicting shapes"):
with pytest.raises(ValueError, match=r"Dimension .* has conflicting shapes"):
broadcast(x, y, z)
def test_broadcast_no_input(self):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论