Skip to content

Commit 823a637

Browse files
fix UT
1 parent c3f6395 commit 823a637

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

test/legacy_test/test_math_op_patch.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,10 @@ def test_dygraph_vanilla_add(self):
684684
a_np = np.random.random((2, 3)).astype(np.float32) * 100
685685
b_f = lambda y: y + 1
686686
a = paddle.to_tensor(a_np)
687-
with self.assertRaises(TypeError):
687+
with self.assertRaisesRegex(
688+
TypeError,
689+
r"__add__\(\): argument \(position 1\) must be int, float, bool or Tensor, but got ",
690+
):
688691
_ = a + b_f
689692

690693
with self.assertRaisesRegex(
@@ -710,7 +713,10 @@ def test_dygraph_vanilla_mul(self):
710713
a_np = np.random.random((2, 3)).astype(np.float32) * 100
711714
b_f = lambda y: y + 1
712715
a = paddle.to_tensor(a_np)
713-
with self.assertRaises(TypeError):
716+
with self.assertRaisesRegex(
717+
TypeError,
718+
r"__mul__\(\): argument \(position 1\) must be int, float, bool or Tensor, but got ",
719+
):
714720
_ = a * b_f
715721

716722
with self.assertRaisesRegex(
@@ -732,7 +738,10 @@ def test_dygraph_vanilla_sub(self):
732738
a_np = np.random.random((2, 3)).astype(np.float32) * 100
733739
b_f = lambda y: y + 1
734740
a = paddle.to_tensor(a_np)
735-
with self.assertRaises(TypeError):
741+
with self.assertRaisesRegex(
742+
TypeError,
743+
r"__sub__\(\): argument \(position 1\) must be int, float, bool or Tensor, but got ",
744+
):
736745
_ = a - b_f
737746

738747
with self.assertRaisesRegex(
@@ -754,7 +763,10 @@ def test_dygraph_vanilla_pow(self):
754763
a_np = np.random.random((2, 3)).astype(np.float32) * 100
755764
b_f = lambda y: y + 1
756765
a = paddle.to_tensor(a_np)
757-
with self.assertRaises(TypeError):
766+
with self.assertRaisesRegex(
767+
TypeError,
768+
r"__pow__\(\): argument \(position 1\) must be int, float, bool or Tensor, but got ",
769+
):
758770
_ = a**b_f
759771

760772
with self.assertRaisesRegex(
@@ -776,7 +788,10 @@ def test_dygraph_vanilla_mod(self):
776788
a_np = np.random.random((2, 3)).astype(np.float32) * 100
777789
b_f = lambda y: y + 1
778790
a = paddle.to_tensor(a_np)
779-
with self.assertRaises(TypeError):
791+
with self.assertRaisesRegex(
792+
TypeError,
793+
r"__mod__\(\): argument \(position 1\) must be int, float, bool or Tensor, but got ",
794+
):
780795
_ = a % b_f
781796

782797
with self.assertRaisesRegex(
@@ -798,13 +813,16 @@ def test_dygraph_vanilla_matmul(self):
798813
a_np = np.random.random((2, 3)).astype(np.float32) * 100
799814
b_f = lambda y: y + 1
800815
a = paddle.to_tensor(a_np)
801-
with self.assertRaises(TypeError):
816+
with self.assertRaisesRegex(
817+
TypeError,
818+
r"__matmul__\(\): argument \(position 1\) must be int, float, bool or Tensor, but got ",
819+
):
802820
_ = a @ b_f
803821

804822
with self.assertRaisesRegex(
805-
ValueError, "Broadcast dimension mismatch"
823+
ValueError, r"\(InvalidArgument\) Input\(Y\) has error dim"
806824
):
807-
_ = a @ a.T
825+
_ = a @ a
808826

809827
def test_dygraph_custom_div(self):
810828
with dygraph_guard():
@@ -820,7 +838,10 @@ def test_dygraph_vanilla_div(self):
820838
a_np = np.random.random((2, 3)).astype(np.float32) * 100
821839
b_f = lambda y: y + 1
822840
a = paddle.to_tensor(a_np)
823-
with self.assertRaises(TypeError):
841+
with self.assertRaisesRegex(
842+
TypeError,
843+
r"__div__\(\): argument \(position 1\) must be int, float, bool or Tensor, but got ",
844+
):
824845
_ = a / b_f
825846

826847
with self.assertRaisesRegex(
@@ -842,7 +863,10 @@ def test_dygraph_vanilla_truediv(self):
842863
a_np = np.random.random((2, 3)).astype(np.float32) * 100
843864
b_f = lambda y: y + 1
844865
a = paddle.to_tensor(a_np)
845-
with self.assertRaises(TypeError):
866+
with self.assertRaisesRegex(
867+
TypeError,
868+
r"__div__\(\): argument \(position 1\) must be int, float, bool or Tensor, but got ",
869+
):
846870
_ = a / b_f
847871

848872
with self.assertRaisesRegex(
@@ -864,7 +888,10 @@ def test_dygraph_vanilla_floordiv(self):
864888
a_np = np.random.random((2, 3)).astype(np.float32) * 100
865889
b_f = lambda y: y + 1
866890
a = paddle.to_tensor(a_np)
867-
with self.assertRaises(TypeError):
891+
with self.assertRaisesRegex(
892+
TypeError,
893+
r"__floordiv__\(\): argument \(position 1\) must be int, float, bool or Tensor, but got ",
894+
):
868895
_ = a // b_f
869896

870897
with self.assertRaisesRegex(

0 commit comments

Comments
 (0)