From fbdba6e4da91bf4b040a2123b8a6d2fadca9973c Mon Sep 17 00:00:00 2001 From: jinyaohui Date: Fri, 22 May 2020 13:23:13 +0800 Subject: [PATCH] clean pylint --- .../test_reid_gradient_compare_with_pytorch.py | 1 - tests/st/ops/cpu/test_slice_grad_op.py | 15 ++++++++------- tests/st/ops/cpu/test_slice_op.py | 11 ++++++----- tests/st/ops/custom_ops_tbe/test_add3.py | 13 ++++++++----- .../gtest_input/pipeline/parse/parse_primitive.py | 4 +--- .../gtest_input/pipeline/parse/parser_test.py | 2 ++ tests/ut/python/dataset/test_batch.py | 1 + tests/ut/python/dataset/test_center_crop.py | 1 + tests/ut/python/dataset/test_filterop.py | 2 +- tests/ut/python/dataset/test_normalizeOp.py | 1 + tests/ut/python/dataset/test_opt.py | 6 +++--- tests/ut/python/dataset/test_pad.py | 1 + .../ut/python/dataset/test_random_color_adjust.py | 1 + tests/ut/python/dataset/test_take.py | 1 - tests/ut/python/dataset/test_tensor_string.py | 1 + tests/ut/python/dtype/test_dictionary.py | 7 +++++-- tests/ut/python/mindrecord/test_mnist_to_mr.py | 9 +++++---- tests/ut/python/nn/test_parameter.py | 1 + tests/ut/python/ops/test_control_ops.py | 5 +++-- .../dropout/_test_dropout_parallel_4p.py | 1 + tests/ut/python/parallel/test_train_and_eval.py | 15 ++++++++------- .../ut/python/parameter_feature/test_parameter.py | 2 ++ tests/ut/python/pipeline/parse/test_cont_break.py | 3 ++- tests/vm_impl/math_ops_vm_impl.py | 1 + 24 files changed, 63 insertions(+), 42 deletions(-) diff --git a/tests/mindspore_test_framework/apps/test_reid_gradient_compare_with_pytorch.py b/tests/mindspore_test_framework/apps/test_reid_gradient_compare_with_pytorch.py index 46450d048c..82bd1d41b0 100644 --- a/tests/mindspore_test_framework/apps/test_reid_gradient_compare_with_pytorch.py +++ b/tests/mindspore_test_framework/apps/test_reid_gradient_compare_with_pytorch.py @@ -21,7 +21,6 @@ from mindspore import context from mindspore.ops import operations as P from ..mindspore_test import mindspore_test from ..pipeline.gradient.compare_gradient import pipeline_for_compare_inputs_grad_with_npy_for_case_by_case_config -from ...vm_impl import * verification_set = [ ('MatMul', { diff --git a/tests/st/ops/cpu/test_slice_grad_op.py b/tests/st/ops/cpu/test_slice_grad_op.py index 5561d3cf34..0d76ed847e 100644 --- a/tests/st/ops/cpu/test_slice_grad_op.py +++ b/tests/st/ops/cpu/test_slice_grad_op.py @@ -13,15 +13,15 @@ # limitations under the License. # ============================================================================ -import pytest -from mindspore import Tensor -from mindspore.ops import operations as P -from mindspore.ops.operations import _grad_ops as G -import mindspore.nn as nn -from mindspore.common.api import ms_function import numpy as np +import pytest + import mindspore.context as context +import mindspore.nn as nn +from mindspore import Tensor from mindspore.common import dtype as mstype +from mindspore.common.api import ms_function +from mindspore.ops.operations import _grad_ops as G context.set_context(mode=context.GRAPH_MODE, device_target='CPU') @@ -54,5 +54,6 @@ def test_slice(): print("output:\n", output) assert (output.asnumpy() == expect).all() + if __name__ == '__main__': - test_slice() + test_slice() diff --git a/tests/st/ops/cpu/test_slice_op.py b/tests/st/ops/cpu/test_slice_op.py index d8ee86be6a..9789069795 100644 --- a/tests/st/ops/cpu/test_slice_op.py +++ b/tests/st/ops/cpu/test_slice_op.py @@ -13,13 +13,14 @@ # limitations under the License. # ============================================================================ -import pytest -from mindspore import Tensor -from mindspore.ops import operations as P -import mindspore.nn as nn import numpy as np +import pytest + import mindspore.context as context +import mindspore.nn as nn +from mindspore import Tensor from mindspore.common import dtype as mstype +from mindspore.ops import operations as P context.set_context(mode=context.GRAPH_MODE, device_target='CPU') @@ -45,6 +46,6 @@ def test_slice(): print("output:\n", output) assert (output.asnumpy() == expect).all() + if __name__ == '__main__': test_slice() - diff --git a/tests/st/ops/custom_ops_tbe/test_add3.py b/tests/st/ops/custom_ops_tbe/test_add3.py index 076f85ce08..b21fa96cb0 100644 --- a/tests/st/ops/custom_ops_tbe/test_add3.py +++ b/tests/st/ops/custom_ops_tbe/test_add3.py @@ -12,15 +12,17 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ -import pytest import numpy as np -import mindspore.nn as nn +import pytest +from cus_add3 import CusAdd3 + import mindspore.context as context +import mindspore.nn as nn from mindspore import Tensor -from mindspore.ops import composite as C -from cus_add3 import CusAdd3 + context.set_context(mode=context.GRAPH_MODE, device_target="Ascend") + class Net(nn.Cell): """Net definition""" @@ -31,6 +33,7 @@ class Net(nn.Cell): def construct(self, input1, input2): return self.add3(input1, input2) + @pytest.mark.level0 @pytest.mark.platform_x86_ascend_training @pytest.mark.platform_arm_ascend_training @@ -41,4 +44,4 @@ def test_net(): add3_net = Net() output = add3_net(Tensor(input1), Tensor(input2)) expect = np.array([3.0, 7.0, 13.0]).astype(np.float32) - assert (output.asnumpy() == expect).all() \ No newline at end of file + assert (output.asnumpy() == expect).all() diff --git a/tests/ut/cpp/python_input/gtest_input/pipeline/parse/parse_primitive.py b/tests/ut/cpp/python_input/gtest_input/pipeline/parse/parse_primitive.py index 047284b186..255767bf36 100644 --- a/tests/ut/cpp/python_input/gtest_input/pipeline/parse/parse_primitive.py +++ b/tests/ut/cpp/python_input/gtest_input/pipeline/parse/parse_primitive.py @@ -19,16 +19,14 @@ @Desc : parser class method function. """ import logging + import numpy as np -import sys -from collections import * import mindspore.nn as nn from mindspore.common.parameter import Parameter from mindspore.common.tensor import Tensor from mindspore.ops import Primitive, prim_attr_register from mindspore.ops import functional as F -from mindspore.train.model import Model log = logging.getLogger("test") log.setLevel(level=logging.ERROR) diff --git a/tests/ut/cpp/python_input/gtest_input/pipeline/parse/parser_test.py b/tests/ut/cpp/python_input/gtest_input/pipeline/parse/parser_test.py index c0a41debc6..59c64efea3 100644 --- a/tests/ut/cpp/python_input/gtest_input/pipeline/parse/parser_test.py +++ b/tests/ut/cpp/python_input/gtest_input/pipeline/parse/parser_test.py @@ -201,6 +201,7 @@ def get_resolve_fn(x, y): # Test:no return function +# pylint: disable=pointless-statement def get_no_return_fn(x, y): x + y @@ -339,6 +340,7 @@ def func_call(x, y, *var, a=0, b=1, **kwargs): return x + y + var[0] + a + b + kwargs["z"] +# pylint: disable=repeated-keyword def test_call_variable(): t = (1, 2, 3) d = {"z": 10, "e": 11} diff --git a/tests/ut/python/dataset/test_batch.py b/tests/ut/python/dataset/test_batch.py index b2d1919a62..2bc26126d2 100644 --- a/tests/ut/python/dataset/test_batch.py +++ b/tests/ut/python/dataset/test_batch.py @@ -434,6 +434,7 @@ def test_batch_exception_11(): assert "drop_remainder" in str(e) +# pylint: disable=redundant-keyword-arg def test_batch_exception_12(): """ Test batch exception: wrong input order, drop_remainder wrongly used as batch_size diff --git a/tests/ut/python/dataset/test_center_crop.py b/tests/ut/python/dataset/test_center_crop.py index bbe284edc3..33ba89e735 100644 --- a/tests/ut/python/dataset/test_center_crop.py +++ b/tests/ut/python/dataset/test_center_crop.py @@ -106,6 +106,7 @@ def test_center_crop_comp(height=375, width=375, plot=False): visualize(image, image_cropped) +# pylint: disable=unnecessary-lambda def test_crop_grayscale(height=375, width=375): """ Test that centercrop works with pad and grayscale images diff --git a/tests/ut/python/dataset/test_filterop.py b/tests/ut/python/dataset/test_filterop.py index db89fe381b..b63ba27da1 100644 --- a/tests/ut/python/dataset/test_filterop.py +++ b/tests/ut/python/dataset/test_filterop.py @@ -19,7 +19,6 @@ import mindspore.common.dtype as mstype import mindspore.dataset as ds import mindspore.dataset.transforms.c_transforms as C import mindspore.dataset.transforms.vision.c_transforms as cde -from mindspore import log as logger DATA_DIR = ["../data/dataset/test_tf_file_3_images/train-0000-of-0001.data"] SCHEMA_DIR = "../data/dataset/test_tf_file_3_images/datasetSchema.json" @@ -255,6 +254,7 @@ def filter_func_map(col1, col2): return False +# pylint: disable=simplifiable-if-statement def filter_func_map_part(col1): if col1 < 3: return True diff --git a/tests/ut/python/dataset/test_normalizeOp.py b/tests/ut/python/dataset/test_normalizeOp.py index e1b5948fb5..5d76411721 100644 --- a/tests/ut/python/dataset/test_normalizeOp.py +++ b/tests/ut/python/dataset/test_normalizeOp.py @@ -36,6 +36,7 @@ def normalize_np(image): return image +# pylint: disable=inconsistent-return-statements def get_normalized(image_id): """ Reads the image using DE ops and then normalizes using Numpy diff --git a/tests/ut/python/dataset/test_opt.py b/tests/ut/python/dataset/test_opt.py index 939a885156..f16cb51e77 100644 --- a/tests/ut/python/dataset/test_opt.py +++ b/tests/ut/python/dataset/test_opt.py @@ -13,10 +13,10 @@ # limitations under the License. # ============================================================================== import numpy as np -import pytest import mindspore.dataset as ds + # Generate 1d int numpy array from 0 - 63 def generator_1d(): for i in range(64): @@ -33,7 +33,7 @@ def test_case_0(): data1 = data1.shuffle(2) - data1 = data1.map(["data"], operations=(lambda x : x)) + data1 = data1.map(["data"], operations=(lambda x: x)) data1 = data1.batch(2) @@ -43,4 +43,4 @@ def test_case_0(): if __name__ == "__main__": - test_case_0() \ No newline at end of file + test_case_0() diff --git a/tests/ut/python/dataset/test_pad.py b/tests/ut/python/dataset/test_pad.py index 47e3dd0e24..0a6f9c1f67 100644 --- a/tests/ut/python/dataset/test_pad.py +++ b/tests/ut/python/dataset/test_pad.py @@ -70,6 +70,7 @@ def test_pad_op(): assert mse < 0.01 +# pylint: disable=unnecessary-lambda def test_pad_grayscale(): """ Tests that the pad works for grayscale images diff --git a/tests/ut/python/dataset/test_random_color_adjust.py b/tests/ut/python/dataset/test_random_color_adjust.py index ebda48074a..90f3334683 100644 --- a/tests/ut/python/dataset/test_random_color_adjust.py +++ b/tests/ut/python/dataset/test_random_color_adjust.py @@ -253,6 +253,7 @@ def test_random_color_adjust_op_hue(plot=False): visualize(c_image, mse, py_image) +# pylint: disable=unnecessary-lambda def test_random_color_adjust_grayscale(): """ Tests that the random color adjust works for grayscale images diff --git a/tests/ut/python/dataset/test_take.py b/tests/ut/python/dataset/test_take.py index 4494d5caef..fef1556398 100644 --- a/tests/ut/python/dataset/test_take.py +++ b/tests/ut/python/dataset/test_take.py @@ -15,7 +15,6 @@ import numpy as np import mindspore.dataset as ds -import mindspore.dataset.transforms.vision.c_transforms as vision from mindspore import log as logger diff --git a/tests/ut/python/dataset/test_tensor_string.py b/tests/ut/python/dataset/test_tensor_string.py index e7b6917a0b..7f905d61e5 100644 --- a/tests/ut/python/dataset/test_tensor_string.py +++ b/tests/ut/python/dataset/test_tensor_string.py @@ -19,6 +19,7 @@ import pytest import mindspore.dataset as ds +# pylint: disable=comparison-with-itself def test_basic(): x = np.array([["ab", "cde", "121"], ["x", "km", "789"]], dtype='S') # x = np.array(["ab", "cde"], dtype='S') diff --git a/tests/ut/python/dtype/test_dictionary.py b/tests/ut/python/dtype/test_dictionary.py index 8c8b2a9389..049ad34065 100644 --- a/tests/ut/python/dtype/test_dictionary.py +++ b/tests/ut/python/dtype/test_dictionary.py @@ -137,16 +137,19 @@ def test_dict_set_or_get_item_3(): net = DictNet() assert net() == Tensor(np.ones([4, 2, 3], np.float32)) + def test_dict_set_item(): class DictSetNet(Cell): def __init__(self): super(DictSetNet, self).__init__() self.attrs = ("abc", "edf", "ghi", "jkl") + def construct(self, x): - my_dict = {"def": x, "abc":x, "edf":x, "ghi":x, "jkl":x} + my_dict = {"def": x, "abc": x, "edf": x, "ghi": x, "jkl": x} for i in range(len(self.attrs)): my_dict[self.attrs[i]] = x - i return my_dict["jkl"], my_dict["edf"] + x = Tensor(np.ones([2, 2, 3], np.float32)) net = DictSetNet() - out = net(x) \ No newline at end of file + out = net(x) diff --git a/tests/ut/python/mindrecord/test_mnist_to_mr.py b/tests/ut/python/mindrecord/test_mnist_to_mr.py index d24518ceba..be6d7a0c15 100644 --- a/tests/ut/python/mindrecord/test_mnist_to_mr.py +++ b/tests/ut/python/mindrecord/test_mnist_to_mr.py @@ -12,12 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. """test mnist to mindrecord tool""" -import cv2 import gzip -import pytest -import numpy as np import os +import cv2 +import numpy as np +import pytest + from mindspore import log as logger from mindspore.mindrecord import FileReader from mindspore.mindrecord import MnistToMR @@ -144,10 +145,10 @@ def test_mnist_to_mindrecord_compare_data(fixture_file): assert np.array(x['label']) == label reader.close() + def test_mnist_to_mindrecord_multi_partition(fixture_file): """test transform mnist dataset to multiple mindrecord files.""" mnist_transformer = MnistToMR(MNIST_DIR, FILE_NAME, PARTITION_NUM) mnist_transformer.transform() read("mnist_train.mindrecord0", "mnist_test.mindrecord0") - diff --git a/tests/ut/python/nn/test_parameter.py b/tests/ut/python/nn/test_parameter.py index 6d384614d9..886f855a79 100644 --- a/tests/ut/python/nn/test_parameter.py +++ b/tests/ut/python/nn/test_parameter.py @@ -1,3 +1,4 @@ + # Copyright 2020 Huawei Technologies Co., Ltd # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/ut/python/ops/test_control_ops.py b/tests/ut/python/ops/test_control_ops.py index e77f6822b0..1e15457616 100644 --- a/tests/ut/python/ops/test_control_ops.py +++ b/tests/ut/python/ops/test_control_ops.py @@ -13,8 +13,8 @@ # limitations under the License. # ============================================================================ """ test control ops """ -import pytest import numpy as np +import pytest import mindspore as ms from mindspore import Tensor @@ -436,10 +436,11 @@ def test_index_to_switch_layer(): Tensor(np.full([128, 96], 0.6, dtype=np.float32))) C.grad_all(net)(index, Tensor(np.full([128, 96], 0.6, dtype=np.float32))) + def test_control_depend_check(): with pytest.raises(TypeError) as e: depend = P.ControlDepend(0.0) with pytest.raises(ValueError) as e: depend = P.ControlDepend(2) with pytest.raises(TypeError) as e: - depend = P.ControlDepend((2,)) \ No newline at end of file + depend = P.ControlDepend((2,)) diff --git a/tests/ut/python/parallel/parallel_end_to_end/dropout/_test_dropout_parallel_4p.py b/tests/ut/python/parallel/parallel_end_to_end/dropout/_test_dropout_parallel_4p.py index 44b361bcc5..c735b28c43 100644 --- a/tests/ut/python/parallel/parallel_end_to_end/dropout/_test_dropout_parallel_4p.py +++ b/tests/ut/python/parallel/parallel_end_to_end/dropout/_test_dropout_parallel_4p.py @@ -50,6 +50,7 @@ class Net(Cell): return x +# pylint: disable=comparison-with-itself class DropoutFactory: def __init__(self, input_shape, keep_prob, seed0, seed1, strategy0=None): size = 1 diff --git a/tests/ut/python/parallel/test_train_and_eval.py b/tests/ut/python/parallel/test_train_and_eval.py index 3d760a27ee..32abb0d173 100644 --- a/tests/ut/python/parallel/test_train_and_eval.py +++ b/tests/ut/python/parallel/test_train_and_eval.py @@ -13,11 +13,12 @@ # limitations under the License. # ============================================================================ import numpy as np + import mindspore as ms from mindspore import context, Tensor, Parameter -from mindspore.nn import Cell, TrainOneStepCell, Momentum -from mindspore.ops import operations as P from mindspore.common.api import _executor +from mindspore.nn import Cell +from mindspore.ops import operations as P class Net(Cell): @@ -42,7 +43,7 @@ class EvalNet(Cell): def construct(self, x, b): out = self.network(x, b) out = self.relu(out) - return out + return out _x = Tensor(np.ones([8, 8]), dtype=ms.float32) @@ -54,15 +55,15 @@ def test_train_and_eval(): context.set_context(save_graphs=True, mode=0) context.set_auto_parallel_context(parallel_mode="semi_auto_parallel", device_num=16) strategy1 = ((4, 4), (4, 4)) - strategy2 = ((4, 4), ) + strategy2 = ((4, 4),) net = Net(_w1, strategy1, strategy2) eval_net = EvalNet(net, strategy2=strategy2) net.set_train() net.set_auto_parallel() - _executor.compile(net, _x, _b, phase='train', auto_parallel_mode=True) + _executor.compile(net, _x, _b, phase='train', auto_parallel_mode=True) eval_net.set_train(mode=False) eval_net.set_auto_parallel() - _executor.compile(eval_net, _x, _b, phase='eval', auto_parallel_mode=True) + _executor.compile(eval_net, _x, _b, phase='eval', auto_parallel_mode=True) - context.reset_auto_parallel_context() \ No newline at end of file + context.reset_auto_parallel_context() diff --git a/tests/ut/python/parameter_feature/test_parameter.py b/tests/ut/python/parameter_feature/test_parameter.py index 18a8d7365d..b739b96781 100644 --- a/tests/ut/python/parameter_feature/test_parameter.py +++ b/tests/ut/python/parameter_feature/test_parameter.py @@ -50,6 +50,7 @@ def test_parser_three_default_mixed_args_subnet(): assert net(tensor1, tensor2) == tensor1 +# pylint: disable=keyword-arg-before-vararg def test_net_vararg_kwonlyarg_kwarg(): class FirstNet(Cell): def __init__(self): @@ -76,6 +77,7 @@ def test_net_vararg_kwonlyarg_kwarg(): net() +# pylint: disable=keyword-arg-before-vararg def test_net_vararg_normal_input(): class FirstNet(Cell): def __init__(self): diff --git a/tests/ut/python/pipeline/parse/test_cont_break.py b/tests/ut/python/pipeline/parse/test_cont_break.py index 422d93cfd2..1098e27897 100644 --- a/tests/ut/python/pipeline/parse/test_cont_break.py +++ b/tests/ut/python/pipeline/parse/test_cont_break.py @@ -34,6 +34,7 @@ def run_test(netclass, count): # np.testing.assert_array_almost_equal(output_np, output_ms.asnumpy(), decimal=3) +# pylint: disable=unnecessary-pass class for_loop_with_break(Cell): def __init__(self): super().__init__() @@ -70,7 +71,7 @@ class for_loop_with_continue(Cell): def test_for_loop_with_continue(): run_test(for_loop_with_continue, 10) - +# pylint: disable=unnecessary-pass class for_loop_with_cont_break(Cell): def __init__(self): super().__init__() diff --git a/tests/vm_impl/math_ops_vm_impl.py b/tests/vm_impl/math_ops_vm_impl.py index 166b63a6df..d409616436 100644 --- a/tests/vm_impl/math_ops_vm_impl.py +++ b/tests/vm_impl/math_ops_vm_impl.py @@ -38,6 +38,7 @@ def vm_impl_tensor_add(self): return vm_impl +# pylint: disable=used-before-assignment @vm_impl_getters.register(P.LogicalNot) def vm_impl_logical_not(self): x = x.asnumpy()