diff --git a/pyproject.toml b/pyproject.toml index 4bbc0e56c426d49b9eb74120565e962adab1b6bb..6a5dc31cde60b7b27bdc893c98f3e17eaf1797e1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,10 +41,6 @@ select = [ "B002", "B003", "B004", - # "B005", - # "B006", - # "B007", - # "B008", "B009", "B010", "B011", @@ -53,65 +49,30 @@ select = [ "B014", "B015", "B016", - # "B017", + "B017", "B018", "B019", "B020", "B021", "B022", - # "B023", - # "B024", "B025", - # "B026", - # "B027", - # "B028", "B029", - # "B030", "B032", - # "B904", # Pylint "PLC0414", - # "PLC1901", "PLC3002", "PLE0100", "PLE0101", - # "PLE0116", - # "PLE0117", - # "PLE0118", "PLE0604", "PLE0605", "PLE1142", "PLE1205", "PLE1206", "PLE1307", - # "PLE1310", - # "PLE1507", "PLE2502", - # "PLE2510", - # "PLE2512", - # "PLE2513", - # "PLE2514", - # "PLE2515", - # "PLR0133", "PLR0206", "PLR0402", - # "PLR0911", - # "PLR0912", - # "PLR0913", - # "PLR0915", - # "PLR1701", - # "PLR1711", - # "PLR1722", - # "PLR2004", - # "PLR5501", - # "PLW0120", - # "PLW0129", - # "PLW0602", - # "PLW0603", - # "PLW0711", - # "PLW1508", - # "PLW2901", ] unfixable = [ "NPY001" diff --git a/python/paddle/distributed/fleet/base/graphviz.py b/python/paddle/distributed/fleet/base/graphviz.py index c24fd4516bdf5ac370d3b9dddc4b79d33d53bf59..5e0b0c186b9b8c82972b685b36985de76b6d4cc0 100644 --- a/python/paddle/distributed/fleet/base/graphviz.py +++ b/python/paddle/distributed/fleet/base/graphviz.py @@ -43,7 +43,7 @@ class Rank: return ( '{' - + 'rank={};'.format(self.kind) + + f'rank={self.kind};' + ','.join([node.name for node in self.nodes]) + '}' ) @@ -97,7 +97,7 @@ class Graph: stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) - logging.warning("write block debug graph to {}".format(image_path)) + logging.warning(f"write block debug graph to {image_path}") return image_path def show(self, dot_path): @@ -125,13 +125,11 @@ class Graph: def __str__(self): reprs = [ 'digraph G {', - 'title = {}'.format(crepr(self.title)), + f'title = {crepr(self.title)}', ] for attr in self.attrs: - reprs.append( - "{key}={value};".format(key=attr, value=crepr(self.attrs[attr])) - ) + reprs.append(f"{attr}={crepr(self.attrs[attr])};") reprs.append(self._rank_repr()) @@ -161,8 +159,7 @@ class Node: label=self.label, extra=',' + ','.join( - "%s=%s" % (key, crepr(value)) - for key, value in self.attrs.items() + f"{key}={crepr(value)}" for key, value in self.attrs.items() ) if self.attrs else "", @@ -191,8 +188,7 @@ class Edge: if not self.attrs else "[" + ','.join( - "{}={}".format(attr[0], crepr(attr[1])) - for attr in self.attrs.items() + f"{attr[0]}={crepr(attr[1])}" for attr in self.attrs.items() ) + "]", ) @@ -292,5 +288,5 @@ class GraphPreviewGenerator: source, target, color="#00000" if not highlight else "orange", - **kwargs + **kwargs, ) diff --git a/python/paddle/fluid/tests/unittests/distributed_passes/check_pass_conflict_example.py b/python/paddle/fluid/tests/unittests/distributed_passes/check_pass_conflict_example.py index 2e3db7633f46dfe33f5e392ff22d7c5a64db2ad9..ce7889522031c5bff582d2e68b57c7b46a9826a0 100644 --- a/python/paddle/fluid/tests/unittests/distributed_passes/check_pass_conflict_example.py +++ b/python/paddle/fluid/tests/unittests/distributed_passes/check_pass_conflict_example.py @@ -39,7 +39,7 @@ class CheckPassConflictTest2(PassConflictChecker): ] def test_resnet(self): - with self.assertRaises(Exception): + with self.assertRaises(Exception): # noqa: B017 self.check_main(resnet_model, batch_size=32) diff --git a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_dynamic_shape.py b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_dynamic_shape.py index a2950ad459904be5985bc91061521a3eb2380a42..0a5ef451b93b8b22e47acb1548339856067f8c86 100644 --- a/python/paddle/fluid/tests/unittests/ir/inference/test_trt_dynamic_shape.py +++ b/python/paddle/fluid/tests/unittests/ir/inference/test_trt_dynamic_shape.py @@ -72,7 +72,9 @@ class TRTDynamicShapeOutOfBound1Test(TRTDynamicShapeTest): def test_check_output(self): if core.is_compiled_with_cuda(): use_gpu = True - with self.assertRaises(Exception): + with self.assertRaisesRegex( + ValueError, "The fed Variable 'data' should have dimensions" + ): self.check_output_with_option(use_gpu) @@ -99,7 +101,9 @@ class TRTDynamicShapeOutOfBound3Test(TRTDynamicShapeTest): def test_check_output(self): if core.is_compiled_with_cuda(): use_gpu = True - with self.assertRaises(Exception): + with self.assertRaisesRegex( + ValueError, "The fed Variable 'data' should have dimensions" + ): self.check_output_with_option(use_gpu) diff --git a/test/dygraph_to_static/test_convert_call_generator.py b/test/dygraph_to_static/test_convert_call_generator.py index a938d679158544c8dc0ddabca5b4b803a5ba845c..07597119204b19920355c9ab845aace2f20ebb8f 100644 --- a/test/dygraph_to_static/test_convert_call_generator.py +++ b/test/dygraph_to_static/test_convert_call_generator.py @@ -16,11 +16,12 @@ import unittest import paddle from paddle.jit import to_static +from paddle.jit.dy2static.convert_call_func import translator_logger def dyfunc_generator(): for i in range(100): - yield paddle.fluid.dygraph.to_variable([i] * 10) + yield paddle.to_tensor([i] * 10) def main_func(): @@ -31,8 +32,17 @@ def main_func(): class TestConvertGenerator(unittest.TestCase): def test_raise_error(self): - with self.assertRaises(Exception): + translator_logger.verbosity_level = 1 + with self.assertLogs( + translator_logger.logger_name, level='WARNING' + ) as cm: to_static(main_func)() + self.assertRegex( + cm.output[0], + "Your function:`dyfunc_generator` doesn't support " + "to transform to static function because it is a " + "generator function", + ) if __name__ == '__main__': diff --git a/test/legacy_test/test_transforms.py b/test/legacy_test/test_transforms.py index 7d1280b8944dd0f846445a373b748b2d1a020d00..229b6ced84de2c07f74e25396a02f090f7e84c82 100644 --- a/test/legacy_test/test_transforms.py +++ b/test/legacy_test/test_transforms.py @@ -299,10 +299,10 @@ class TestTransformsCV2(unittest.TestCase): trans_batch = transforms.Compose([transforms.Resize(-1)]) - with self.assertRaises(Exception): + with self.assertRaises((cv2.error, AssertionError, ValueError)): self.do_transform(trans) - with self.assertRaises(Exception): + with self.assertRaises((cv2.error, AssertionError, ValueError)): self.do_transform(trans_batch) with self.assertRaises(ValueError): @@ -411,22 +411,35 @@ class TestTransformsCV2(unittest.TestCase): with self.assertRaises(NotImplementedError): transform = transforms.BrightnessTransform('0.1', keys='a') - with self.assertRaises(Exception): + with self.assertRaisesRegex( + AssertionError, "scale should be a tuple or list" + ): transform = transforms.RandomErasing(scale=0.5) - with self.assertRaises(Exception): + with self.assertRaisesRegex( + AssertionError, "ratio should be a tuple or list" + ): transform = transforms.RandomErasing(ratio=0.8) - with self.assertRaises(Exception): + with self.assertRaisesRegex( + AssertionError, + r"scale should be of kind \(min, max\) and in range \[0, 1\]", + ): transform = transforms.RandomErasing(scale=(10, 0.4)) - with self.assertRaises(Exception): + with self.assertRaisesRegex( + AssertionError, r"ratio should be of kind \(min, max\)" + ): transform = transforms.RandomErasing(ratio=(3.3, 0.3)) - with self.assertRaises(Exception): + with self.assertRaisesRegex( + AssertionError, r"The probability should be in range \[0, 1\]" + ): transform = transforms.RandomErasing(prob=1.5) - with self.assertRaises(Exception): + with self.assertRaisesRegex( + ValueError, r"value must be 'random' when type is str" + ): transform = transforms.RandomErasing(value="0") def test_info(self): @@ -571,10 +584,10 @@ class TestTransformsTensor(TestTransformsCV2): trans_batch = transforms.Compose([transforms.Resize(-1)]) - with self.assertRaises(Exception): + with self.assertRaises((cv2.error, AssertionError, ValueError)): self.do_transform(trans) - with self.assertRaises(Exception): + with self.assertRaises((cv2.error, AssertionError, ValueError)): self.do_transform(trans_batch) with self.assertRaises(ValueError):