diff --git a/test/legacy_test/test_matmul_op.py b/test/legacy_test/test_matmul_op.py index aec83676e39328..bf2d8d0ee95669 100644 --- a/test/legacy_test/test_matmul_op.py +++ b/test/legacy_test/test_matmul_op.py @@ -221,48 +221,34 @@ def test_dygraph_without_out(self): class API_TestMmError(unittest.TestCase): + @test_with_pir_api def test_errors(self): - with paddle_static_guard(): + paddle.enable_static() + with paddle.static.program_guard( + paddle.static.Program(), paddle.static.Program() + ): def test_error1(): - with paddle.base.program_guard( - paddle.base.Program(), paddle.base.Program() - ): - data1 = paddle.static.data( - name="data1", shape=[10, 2], dtype="float32" - ) - data2 = paddle.static.data( - name="data2", shape=[3, 10], dtype="float32" - ) - paddle.mm(data1, data2) + data1 = paddle.static.data( + name="data1", shape=[10, 2], dtype="float32" + ) + data2 = paddle.static.data( + name="data2", shape=[3, 10], dtype="float32" + ) + paddle.mm(data1, data2) self.assertRaises(ValueError, test_error1) def test_error2(): - with paddle.base.program_guard( - paddle.base.Program(), paddle.base.Program() - ): - data1 = paddle.static.data( - name="data1", shape=[-1, 10, 2], dtype="float32" - ) - data2 = paddle.static.data( - name="data2", shape=[-1, 2, 10], dtype="float32" - ) - paddle.mm(data1, data2) - - test_error2() - - def test_error3(): - with base.program_guard(base.Program(), base.Program()): - data1 = paddle.static.data( - name="data1", shape=[10, 10, 2], dtype="float32" - ) - data2 = paddle.static.data( - name="data2", shape=[3, 2, 10], dtype="float32" - ) - paddle.mm(data1, data2) - - self.assertRaises(ValueError, test_error3) + data3 = paddle.static.data( + name="data3", shape=[10, 10, 2], dtype="float32" + ) + data4 = paddle.static.data( + name="data4", shape=[3, 2, 10], dtype="float32" + ) + paddle.mm(data3, data4) + + self.assertRaises(ValueError, test_error2) if __name__ == "__main__":