From e6f2c5989d96a869997f372ed881177042c85c5e Mon Sep 17 00:00:00 2001 From: enkilee Date: Wed, 18 Oct 2023 04:39:10 +0000 Subject: [PATCH 1/7] fix B017 --- pyproject.toml | 18 +++++++++--------- .../spmd_rules/test_reshape_rule.py | 2 +- test/dygraph_to_static/test_assert.py | 2 +- .../test_cuda_max_memory_allocated.py | 4 ++-- .../test_cuda_max_memory_reserved.py | 4 ++-- test/legacy_test/test_cuda_memory_allocated.py | 4 ++-- test/legacy_test/test_cuda_memory_reserved.py | 4 ++-- test/legacy_test/test_eigvals_op.py | 4 ++-- test/legacy_test/test_tensordot.py | 2 +- test/legacy_test/test_top_k_v2_op.py | 4 ++-- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 393d46b6f8a5f8..18fe2e7555928e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -113,12 +113,12 @@ ignore = [ ] # B017 -"test/auto_parallel/spmd_rules/test_reshape_rule.py" = ["B017"] -"test/dygraph_to_static/test_assert.py" = ["B017"] -"test/legacy_test/test_cuda_max_memory_allocated.py" = ["B017"] -"test/legacy_test/test_cuda_max_memory_reserved.py" = ["B017"] -"test/legacy_test/test_cuda_memory_allocated.py" = ["B017"] -"test/legacy_test/test_cuda_memory_reserved.py" = ["B017"] -"test/legacy_test/test_eigvals_op.py" = ["B017"] -"test/legacy_test/test_tensordot.py" = ["B017"] -"test/legacy_test/test_top_k_v2_op.py" = ["B017"] +#"test/auto_parallel/spmd_rules/test_reshape_rule.py" = ["B017"] +#"test/dygraph_to_static/test_assert.py" = ["B017"] +#"test/legacy_test/test_cuda_max_memory_allocated.py" = ["B017"] +#"test/legacy_test/test_cuda_max_memory_reserved.py" = ["B017"] +#"test/legacy_test/test_cuda_memory_allocated.py" = ["B017"] +#"test/legacy_test/test_cuda_memory_reserved.py" = ["B017"] +#"test/legacy_test/test_eigvals_op.py" = ["B017"] +#"test/legacy_test/test_tensordot.py" = ["B017"] +#"test/legacy_test/test_top_k_v2_op.py" = ["B017"] diff --git a/test/auto_parallel/spmd_rules/test_reshape_rule.py b/test/auto_parallel/spmd_rules/test_reshape_rule.py index a370580682d8cb..aa90998e309b41 100644 --- a/test/auto_parallel/spmd_rules/test_reshape_rule.py +++ b/test/auto_parallel/spmd_rules/test_reshape_rule.py @@ -246,7 +246,7 @@ def test_reshape_infer_forward(self): # shape: [6, 12, 48, 24] --> [3, 24, 6, -1, -1] # raise error self.attrs["shape"] = [3, 24, 6, -1, -1] - with self.assertRaises(BaseException): + with self.assertRaises(ValueError): self.rule.infer_forward( self.x_dist_tensor_spec, self.attrs['shape'] ) diff --git a/test/dygraph_to_static/test_assert.py b/test/dygraph_to_static/test_assert.py index 210e904454fd93..895fa9c23089bc 100644 --- a/test/dygraph_to_static/test_assert.py +++ b/test/dygraph_to_static/test_assert.py @@ -42,7 +42,7 @@ class TestAssertVariable(Dy2StTestBase): def _run(self, func, x, with_exception, to_static): paddle.jit.enable_to_static(to_static) if with_exception: - with self.assertRaises(BaseException): + with self.assertRaises(with_exception): with base.dygraph.guard(): func(x) else: diff --git a/test/legacy_test/test_cuda_max_memory_allocated.py b/test/legacy_test/test_cuda_max_memory_allocated.py index 90e016921f8a21..c8830a8db7b6f6 100644 --- a/test/legacy_test/test_cuda_max_memory_allocated.py +++ b/test/legacy_test/test_cuda_max_memory_allocated.py @@ -61,10 +61,10 @@ def test_max_memory_allocated_exception(self): "gpu1", ] for device in wrong_device: - with self.assertRaises(BaseException): + with self.assertRaises(ValueError): max_memory_allocated(device) else: - with self.assertRaises(BaseException): + with self.assertRaises(ValueError): max_memory_allocated() diff --git a/test/legacy_test/test_cuda_max_memory_reserved.py b/test/legacy_test/test_cuda_max_memory_reserved.py index ac3b2b712e2ff7..7fdc880fa60b7f 100644 --- a/test/legacy_test/test_cuda_max_memory_reserved.py +++ b/test/legacy_test/test_cuda_max_memory_reserved.py @@ -61,10 +61,10 @@ def test_max_memory_reserved_exception(self): "gpu1", ] for device in wrong_device: - with self.assertRaises(BaseException): + with self.assertRaises(ValueError): max_memory_reserved(device) else: - with self.assertRaises(BaseException): + with self.assertRaises(ValueError): max_memory_reserved() diff --git a/test/legacy_test/test_cuda_memory_allocated.py b/test/legacy_test/test_cuda_memory_allocated.py index 3e4c2589406590..6fd73b91ce18e3 100644 --- a/test/legacy_test/test_cuda_memory_allocated.py +++ b/test/legacy_test/test_cuda_memory_allocated.py @@ -46,10 +46,10 @@ def test_memory_allocated_exception(self): "gpu1", ] for device in wrong_device: - with self.assertRaises(BaseException): + with self.assertRaises(ValueError): memory_allocated(device) else: - with self.assertRaises(BaseException): + with self.assertRaises(ValueError): memory_allocated() diff --git a/test/legacy_test/test_cuda_memory_reserved.py b/test/legacy_test/test_cuda_memory_reserved.py index d639eab054ff52..fc7b6e310d13e3 100644 --- a/test/legacy_test/test_cuda_memory_reserved.py +++ b/test/legacy_test/test_cuda_memory_reserved.py @@ -46,10 +46,10 @@ def test_memory_reserved_exception(self): "gpu1", ] for device in wrong_device: - with self.assertRaises(BaseException): + with self.assertRaises(ValueError): memory_reserved(device) else: - with self.assertRaises(BaseException): + with self.assertRaises(ValueError): memory_reserved() diff --git a/test/legacy_test/test_eigvals_op.py b/test/legacy_test/test_eigvals_op.py index 6f3f126b2db3ed..d3e6a0dc3ad6ce 100644 --- a/test/legacy_test/test_eigvals_op.py +++ b/test/legacy_test/test_eigvals_op.py @@ -326,13 +326,13 @@ def test_cases(self): def test_error(self): paddle.disable_static() x = paddle.to_tensor([1]) - with self.assertRaises(BaseException): + with self.assertRaises(TypeError): paddle.linalg.eigvals(x) self.input_dims = [1, 2, 3, 4] self.set_input_data() x = paddle.to_tensor(self.input_data) - with self.assertRaises(BaseException): + with self.assertRaises(TypeError): paddle.linalg.eigvals(x) diff --git a/test/legacy_test/test_tensordot.py b/test/legacy_test/test_tensordot.py index 16d2015573d10f..5faeefa7bceb22 100644 --- a/test/legacy_test/test_tensordot.py +++ b/test/legacy_test/test_tensordot.py @@ -343,7 +343,7 @@ def test_error(self): x = paddle.to_tensor(self.x) y = paddle.to_tensor(self.y) for axes in self.all_axes: - with self.assertRaises(BaseException): + with self.assertRaises(ValueError): paddle.tensordot(x, y, axes) diff --git a/test/legacy_test/test_top_k_v2_op.py b/test/legacy_test/test_top_k_v2_op.py index 9ff5d03473afcd..9a1314d418a5f0 100644 --- a/test/legacy_test/test_top_k_v2_op.py +++ b/test/legacy_test/test_top_k_v2_op.py @@ -472,10 +472,10 @@ def test_cases(self): def test_errors(self): with paddle.base.dygraph.guard(): x = paddle.to_tensor([1, 2, 3]) - with self.assertRaises(BaseException): + with self.assertRaises(ValueError): paddle.topk(x, k=-1) - with self.assertRaises(BaseException): + with self.assertRaises(ValueError): paddle.topk(x, k=0) From 023921e018399fbd3ca5720a893a6fcc0005065a Mon Sep 17 00:00:00 2001 From: enkilee Date: Wed, 18 Oct 2023 06:49:34 +0000 Subject: [PATCH 2/7] fix --- test/dygraph_to_static/test_assert.py | 2 +- test/legacy_test/test_eigvals_op.py | 4 ++-- test/legacy_test/test_tensordot.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/dygraph_to_static/test_assert.py b/test/dygraph_to_static/test_assert.py index 895fa9c23089bc..4ac4514fd37ac2 100644 --- a/test/dygraph_to_static/test_assert.py +++ b/test/dygraph_to_static/test_assert.py @@ -42,7 +42,7 @@ class TestAssertVariable(Dy2StTestBase): def _run(self, func, x, with_exception, to_static): paddle.jit.enable_to_static(to_static) if with_exception: - with self.assertRaises(with_exception): + with self.assertRaises(TypeError): with base.dygraph.guard(): func(x) else: diff --git a/test/legacy_test/test_eigvals_op.py b/test/legacy_test/test_eigvals_op.py index d3e6a0dc3ad6ce..ef2ce2648b4f3d 100644 --- a/test/legacy_test/test_eigvals_op.py +++ b/test/legacy_test/test_eigvals_op.py @@ -326,13 +326,13 @@ def test_cases(self): def test_error(self): paddle.disable_static() x = paddle.to_tensor([1]) - with self.assertRaises(TypeError): + with self.assertRaises(ValueError): paddle.linalg.eigvals(x) self.input_dims = [1, 2, 3, 4] self.set_input_data() x = paddle.to_tensor(self.input_data) - with self.assertRaises(TypeError): + with self.assertRaises(ValueError): paddle.linalg.eigvals(x) diff --git a/test/legacy_test/test_tensordot.py b/test/legacy_test/test_tensordot.py index 5faeefa7bceb22..6a58f698755c0f 100644 --- a/test/legacy_test/test_tensordot.py +++ b/test/legacy_test/test_tensordot.py @@ -343,7 +343,7 @@ def test_error(self): x = paddle.to_tensor(self.x) y = paddle.to_tensor(self.y) for axes in self.all_axes: - with self.assertRaises(ValueError): + with self.assertRaises(TypeError): paddle.tensordot(x, y, axes) From bbcf3c71e060fb9fc5a0414c253b7fa52662a16e Mon Sep 17 00:00:00 2001 From: enkilee Date: Thu, 19 Oct 2023 02:07:50 +0000 Subject: [PATCH 3/7] fix --- test/dygraph_to_static/test_assert.py | 2 +- test/legacy_test/test_cuda_max_memory_allocated.py | 2 +- test/legacy_test/test_cuda_max_memory_reserved.py | 2 +- test/legacy_test/test_cuda_memory_allocated.py | 2 +- test/legacy_test/test_cuda_memory_reserved.py | 2 +- test/legacy_test/test_tensordot.py | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/dygraph_to_static/test_assert.py b/test/dygraph_to_static/test_assert.py index 4ac4514fd37ac2..9d4555e133c9bc 100644 --- a/test/dygraph_to_static/test_assert.py +++ b/test/dygraph_to_static/test_assert.py @@ -42,7 +42,7 @@ class TestAssertVariable(Dy2StTestBase): def _run(self, func, x, with_exception, to_static): paddle.jit.enable_to_static(to_static) if with_exception: - with self.assertRaises(TypeError): + with self.assertRaises(BaseException): # noqa: B017 with base.dygraph.guard(): func(x) else: diff --git a/test/legacy_test/test_cuda_max_memory_allocated.py b/test/legacy_test/test_cuda_max_memory_allocated.py index c8830a8db7b6f6..d3f6f6b0c04ad4 100644 --- a/test/legacy_test/test_cuda_max_memory_allocated.py +++ b/test/legacy_test/test_cuda_max_memory_allocated.py @@ -61,7 +61,7 @@ def test_max_memory_allocated_exception(self): "gpu1", ] for device in wrong_device: - with self.assertRaises(ValueError): + with self.assertRaises(AssertionError): max_memory_allocated(device) else: with self.assertRaises(ValueError): diff --git a/test/legacy_test/test_cuda_max_memory_reserved.py b/test/legacy_test/test_cuda_max_memory_reserved.py index 7fdc880fa60b7f..024d9901effd13 100644 --- a/test/legacy_test/test_cuda_max_memory_reserved.py +++ b/test/legacy_test/test_cuda_max_memory_reserved.py @@ -61,7 +61,7 @@ def test_max_memory_reserved_exception(self): "gpu1", ] for device in wrong_device: - with self.assertRaises(ValueError): + with self.assertRaises(AssertionError): max_memory_reserved(device) else: with self.assertRaises(ValueError): diff --git a/test/legacy_test/test_cuda_memory_allocated.py b/test/legacy_test/test_cuda_memory_allocated.py index 6fd73b91ce18e3..2c7a6593298dbc 100644 --- a/test/legacy_test/test_cuda_memory_allocated.py +++ b/test/legacy_test/test_cuda_memory_allocated.py @@ -46,7 +46,7 @@ def test_memory_allocated_exception(self): "gpu1", ] for device in wrong_device: - with self.assertRaises(ValueError): + with self.assertRaises(AssertionError): memory_allocated(device) else: with self.assertRaises(ValueError): diff --git a/test/legacy_test/test_cuda_memory_reserved.py b/test/legacy_test/test_cuda_memory_reserved.py index fc7b6e310d13e3..8daa0b4e93c7c0 100644 --- a/test/legacy_test/test_cuda_memory_reserved.py +++ b/test/legacy_test/test_cuda_memory_reserved.py @@ -46,7 +46,7 @@ def test_memory_reserved_exception(self): "gpu1", ] for device in wrong_device: - with self.assertRaises(ValueError): + with self.assertRaises(AssertionError): memory_reserved(device) else: with self.assertRaises(ValueError): diff --git a/test/legacy_test/test_tensordot.py b/test/legacy_test/test_tensordot.py index 6a58f698755c0f..e68b64d995cfd0 100644 --- a/test/legacy_test/test_tensordot.py +++ b/test/legacy_test/test_tensordot.py @@ -343,7 +343,7 @@ def test_error(self): x = paddle.to_tensor(self.x) y = paddle.to_tensor(self.y) for axes in self.all_axes: - with self.assertRaises(TypeError): + with self.assertRaises(AssertionError): paddle.tensordot(x, y, axes) From 17b9275f8248107d7424e833a7468d573800d33f Mon Sep 17 00:00:00 2001 From: enkilee Date: Thu, 19 Oct 2023 03:12:04 +0000 Subject: [PATCH 4/7] fix --- test/legacy_test/test_tensordot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/legacy_test/test_tensordot.py b/test/legacy_test/test_tensordot.py index e68b64d995cfd0..6a58f698755c0f 100644 --- a/test/legacy_test/test_tensordot.py +++ b/test/legacy_test/test_tensordot.py @@ -343,7 +343,7 @@ def test_error(self): x = paddle.to_tensor(self.x) y = paddle.to_tensor(self.y) for axes in self.all_axes: - with self.assertRaises(AssertionError): + with self.assertRaises(TypeError): paddle.tensordot(x, y, axes) From e07118899b7302a728ea9104a6ba1e5bbd562331 Mon Sep 17 00:00:00 2001 From: enkilee Date: Thu, 19 Oct 2023 06:48:28 +0000 Subject: [PATCH 5/7] fix --- pyproject.toml | 11 ----------- test/legacy_test/test_tensordot.py | 2 +- 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 18fe2e7555928e..d5c6c7b94d21ff 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -111,14 +111,3 @@ ignore = [ "C416", "F821", ] - -# B017 -#"test/auto_parallel/spmd_rules/test_reshape_rule.py" = ["B017"] -#"test/dygraph_to_static/test_assert.py" = ["B017"] -#"test/legacy_test/test_cuda_max_memory_allocated.py" = ["B017"] -#"test/legacy_test/test_cuda_max_memory_reserved.py" = ["B017"] -#"test/legacy_test/test_cuda_memory_allocated.py" = ["B017"] -#"test/legacy_test/test_cuda_memory_reserved.py" = ["B017"] -#"test/legacy_test/test_eigvals_op.py" = ["B017"] -#"test/legacy_test/test_tensordot.py" = ["B017"] -#"test/legacy_test/test_top_k_v2_op.py" = ["B017"] diff --git a/test/legacy_test/test_tensordot.py b/test/legacy_test/test_tensordot.py index 6a58f698755c0f..c132528a1f4390 100644 --- a/test/legacy_test/test_tensordot.py +++ b/test/legacy_test/test_tensordot.py @@ -343,7 +343,7 @@ def test_error(self): x = paddle.to_tensor(self.x) y = paddle.to_tensor(self.y) for axes in self.all_axes: - with self.assertRaises(TypeError): + with self.assertRaises(BaseException): # noqa: B017 paddle.tensordot(x, y, axes) From 2090f9b47e5ad48eab0992aba251dfafc6766657 Mon Sep 17 00:00:00 2001 From: enkilee Date: Thu, 19 Oct 2023 09:05:20 +0000 Subject: [PATCH 6/7] fix --- test/legacy_test/test_cuda_max_memory_allocated.py | 2 +- test/legacy_test/test_cuda_max_memory_reserved.py | 2 +- test/legacy_test/test_cuda_memory_allocated.py | 2 +- test/legacy_test/test_cuda_memory_reserved.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/legacy_test/test_cuda_max_memory_allocated.py b/test/legacy_test/test_cuda_max_memory_allocated.py index d3f6f6b0c04ad4..969489fa8f925e 100644 --- a/test/legacy_test/test_cuda_max_memory_allocated.py +++ b/test/legacy_test/test_cuda_max_memory_allocated.py @@ -61,7 +61,7 @@ def test_max_memory_allocated_exception(self): "gpu1", ] for device in wrong_device: - with self.assertRaises(AssertionError): + with self.assertRaises(BaseException): # noqa: B017 max_memory_allocated(device) else: with self.assertRaises(ValueError): diff --git a/test/legacy_test/test_cuda_max_memory_reserved.py b/test/legacy_test/test_cuda_max_memory_reserved.py index 024d9901effd13..7f0a3f4da388fc 100644 --- a/test/legacy_test/test_cuda_max_memory_reserved.py +++ b/test/legacy_test/test_cuda_max_memory_reserved.py @@ -61,7 +61,7 @@ def test_max_memory_reserved_exception(self): "gpu1", ] for device in wrong_device: - with self.assertRaises(AssertionError): + with self.assertRaises(BaseException): # noqa: B017 max_memory_reserved(device) else: with self.assertRaises(ValueError): diff --git a/test/legacy_test/test_cuda_memory_allocated.py b/test/legacy_test/test_cuda_memory_allocated.py index 2c7a6593298dbc..192126c092a4bb 100644 --- a/test/legacy_test/test_cuda_memory_allocated.py +++ b/test/legacy_test/test_cuda_memory_allocated.py @@ -46,7 +46,7 @@ def test_memory_allocated_exception(self): "gpu1", ] for device in wrong_device: - with self.assertRaises(AssertionError): + with self.assertRaises(BaseException): # noqa: B017 memory_allocated(device) else: with self.assertRaises(ValueError): diff --git a/test/legacy_test/test_cuda_memory_reserved.py b/test/legacy_test/test_cuda_memory_reserved.py index 8daa0b4e93c7c0..8a02834f8fd3a3 100644 --- a/test/legacy_test/test_cuda_memory_reserved.py +++ b/test/legacy_test/test_cuda_memory_reserved.py @@ -46,7 +46,7 @@ def test_memory_reserved_exception(self): "gpu1", ] for device in wrong_device: - with self.assertRaises(AssertionError): + with self.assertRaises(BaseException): # noqa: B017 memory_reserved(device) else: with self.assertRaises(ValueError): From e37064dc304c340232078b1acf82919ed0be5216 Mon Sep 17 00:00:00 2001 From: enkilee Date: Mon, 23 Oct 2023 03:35:41 +0000 Subject: [PATCH 7/7] fix --- test/legacy_test/test_tensordot.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/test/legacy_test/test_tensordot.py b/test/legacy_test/test_tensordot.py index c132528a1f4390..0e41772abd6cb5 100644 --- a/test/legacy_test/test_tensordot.py +++ b/test/legacy_test/test_tensordot.py @@ -342,9 +342,21 @@ def test_error(self): paddle.disable_static() x = paddle.to_tensor(self.x) y = paddle.to_tensor(self.y) - for axes in self.all_axes: - with self.assertRaises(BaseException): # noqa: B017 - paddle.tensordot(x, y, axes) + + with self.assertRaises(TypeError): + paddle.tensordot(x, y, axes=self.all_axes[0]) + with self.assertRaises(TypeError): + paddle.tensordot(x, y, axes=self.all_axes[1]) + with self.assertRaises(AssertionError): + paddle.tensordot(x, y, axes=self.all_axes[2]) + with self.assertRaises(IndexError): + paddle.tensordot(x, y, axes=self.all_axes[3]) + with self.assertRaises(ValueError): + paddle.tensordot(x, y, axes=self.all_axes[4]) + with self.assertRaises(AssertionError): + paddle.tensordot(x, y, axes=self.all_axes[5]) + with self.assertRaises(AssertionError): + paddle.tensordot(x, y, axes=self.all_axes[6]) class TestTensordotAPIAxesTypeFloat64(TestTensordotAPIAxesType):