Skip to content

Commit

Permalink
[CodeStyle][task 10] enable ruff B017 rule in python/paddle/base (Pad…
Browse files Browse the repository at this point in the history
  • Loading branch information
enkilee authored and wentaoyu committed Oct 24, 2023
1 parent 43042e9 commit 3dd85f7
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 28 deletions.
11 changes: 0 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,3 @@ ignore = [
"test/dygraph_to_static/test_loop.py" = ["C416", "F821"]
# Ignore unnecessary lambda in dy2st unittest test_lambda
"test/dygraph_to_static/test_lambda.py" = ["PLC3002"]

# 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"]
2 changes: 1 addition & 1 deletion test/auto_parallel/spmd_rules/test_reshape_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
)
Expand Down
2 changes: 1 addition & 1 deletion test/dygraph_to_static/test_assert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(BaseException): # noqa: B017
with base.dygraph.guard():
func(x)
else:
Expand Down
4 changes: 2 additions & 2 deletions test/legacy_test/test_cuda_max_memory_allocated.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def test_max_memory_allocated_exception(self):
"gpu1",
]
for device in wrong_device:
with self.assertRaises(BaseException):
with self.assertRaises(BaseException): # noqa: B017
max_memory_allocated(device)
else:
with self.assertRaises(BaseException):
with self.assertRaises(ValueError):
max_memory_allocated()


Expand Down
4 changes: 2 additions & 2 deletions test/legacy_test/test_cuda_max_memory_reserved.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ def test_max_memory_reserved_exception(self):
"gpu1",
]
for device in wrong_device:
with self.assertRaises(BaseException):
with self.assertRaises(BaseException): # noqa: B017
max_memory_reserved(device)
else:
with self.assertRaises(BaseException):
with self.assertRaises(ValueError):
max_memory_reserved()


Expand Down
4 changes: 2 additions & 2 deletions test/legacy_test/test_cuda_memory_allocated.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def test_memory_allocated_exception(self):
"gpu1",
]
for device in wrong_device:
with self.assertRaises(BaseException):
with self.assertRaises(BaseException): # noqa: B017
memory_allocated(device)
else:
with self.assertRaises(BaseException):
with self.assertRaises(ValueError):
memory_allocated()


Expand Down
4 changes: 2 additions & 2 deletions test/legacy_test/test_cuda_memory_reserved.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def test_memory_reserved_exception(self):
"gpu1",
]
for device in wrong_device:
with self.assertRaises(BaseException):
with self.assertRaises(BaseException): # noqa: B017
memory_reserved(device)
else:
with self.assertRaises(BaseException):
with self.assertRaises(ValueError):
memory_reserved()


Expand Down
4 changes: 2 additions & 2 deletions test/legacy_test/test_eigvals_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,13 @@ def test_cases(self):
def test_error(self):
paddle.disable_static()
x = paddle.to_tensor([1])
with self.assertRaises(BaseException):
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(BaseException):
with self.assertRaises(ValueError):
paddle.linalg.eigvals(x)


Expand Down
18 changes: 15 additions & 3 deletions test/legacy_test/test_tensordot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
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):
Expand Down
4 changes: 2 additions & 2 deletions test/legacy_test/test_top_k_v2_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 3dd85f7

Please sign in to comment.