未验证 提交 b1da3526 编写于 作者: Z Zhang Ting 提交者: GitHub

fix unit tests that do not need to inherit OpTest (#21460)

* fix PythonAPI test in Op unittest, test=develop
* fix unit tests that do not need to inherit OpTest, test=develop
上级 fa7cff1f
......@@ -58,7 +58,7 @@ class TestAccuracyOpFp16(TestAccuracyOp):
self.check_output(atol=1e-3)
class TestAccuracyOpError(OpTest):
class TestAccuracyOpError(unittest.TestCase):
def test_errors(self):
with program_guard(Program(), Program()):
# The input type of accuracy_op must be Variable.
......
......@@ -23,7 +23,7 @@ import paddle.fluid as fluid
from paddle.fluid import compiler, Program, program_guard
class TestSqrtOpError(OpTest):
class TestSqrtOpError(unittest.TestCase):
def test_errors(self):
with program_guard(Program(), Program()):
# The input type of sqrt op must be Variable or numpy.ndarray.
......@@ -537,7 +537,7 @@ class TestELU(TestActivation):
self.check_grad(['X'], 'Out', max_relative_error=0.02)
class TestELUOpError(OpTest):
class TestELUOpError(unittest.TestCase):
def test_errors(self):
with program_guard(Program(), Program()):
# The input type of elu_op must be Variable.
......
......@@ -484,7 +484,7 @@ class TestBilinearInterp_attr_tensor_Case3(TestBilinearInterpOp_attr_tensor):
self.scale_by_1Dtensor = True
class TestBilinearInterpOpAPI(OpTest):
class TestBilinearInterpOpAPI(unittest.TestCase):
def test_case(self):
x = fluid.data(name="x", shape=[2, 3, 6, 6], dtype="float32")
......
......@@ -70,7 +70,7 @@ class TestCastOp3(op_test.OpTest):
self.check_output(atol=1e-3)
class TestCastOpError(op_test.OpTest):
class TestCastOpError(unittest.TestCase):
def test_errors(self):
with program_guard(Program(), Program()):
# The input type of cast_op must be Variable.
......
......@@ -718,7 +718,7 @@ class TestDepthwiseConvTransposeAsymmetricPad_NHWC(TestConv2dTransposeOp):
self.data_format = 'NHWC'
class TestConv2dTransposeAPI(OpTest):
class TestConv2dTransposeAPI(unittest.TestCase):
def test_case1(self):
data1 = fluid.layers.data(
name='data1', shape=[3, 5, 5], dtype='float32')
......@@ -796,7 +796,7 @@ class TestConv2dTransposeAPI(OpTest):
self.assertIsNotNone(results[6])
class TestConv2dTransposeOpException(OpTest):
class TestConv2dTransposeOpException(unittest.TestCase):
def test_exception(self):
data = fluid.layers.data(name='data', shape=[3, 5, 5], dtype="float32")
......
......@@ -563,7 +563,7 @@ class TestCUDNNWithGroups_NHWC(TestWithGroups):
self.op_type = "conv3d_transpose"
class TestConv3dTransposeAPI(OpTest):
class TestConv3dTransposeAPI(unittest.TestCase):
def test_case1(self):
data1 = fluid.layers.data(
name='data1', shape=[3, 5, 5, 5], dtype='float32')
......@@ -642,7 +642,7 @@ class TestConv3dTransposeAPI(OpTest):
self.assertIsNotNone(results[6])
class TestConv3dTransposeOpException(OpTest):
class TestConv3dTransposeOpException(unittest.TestCase):
def test_exception(self):
data = fluid.layers.data(
name='data', shape=[3, 5, 5, 5], dtype="float32")
......
......@@ -217,7 +217,7 @@ class TestCropTensorOpTensorAttrCase4(TestCropTensorOpTensorAttr):
self.OffsetsTensor = True
class TestCropTensorException(OpTest):
class TestCropTensorException(unittest.TestCase):
def test_exception(self):
input1 = fluid.data(name="input1", shape=[2, 3, 6, 6], dtype="float32")
input2 = fluid.data(name="input2", shape=[2, 3, 6, 6], dtype="float16")
......
......@@ -31,7 +31,7 @@ from google.protobuf import text_format
import paddle.fluid.incubate.fleet.parameter_server.pslib.ps_pb2 as pslib
class TestListenAndServOp(OpTest):
class TestListenAndServOp(unittest.TestCase):
"""TestListenAndServOp."""
def setUp(self):
......
......@@ -193,7 +193,7 @@ class TestExpandOpInt64_t(OpTest):
self.check_output()
class TestExpandError(OpTest):
class TestExpandError(unittest.TestCase):
def test_errors(self):
with program_guard(Program(), Program()):
x1 = fluid.create_lod_tensor(
......@@ -208,7 +208,7 @@ class TestExpandError(OpTest):
# Test python API
class TestExpandAPI(OpTest):
class TestExpandAPI(unittest.TestCase):
def test_api(self):
input = np.random.random([12, 14]).astype("float32")
x = fluid.layers.data(
......
......@@ -131,7 +131,7 @@ class TestFCOpWithPadding(TestFCOp):
self.matrix = MatrixGenerate(1, 4, 3, 128, 128, 2)
class TestFCOpError(OpTest):
class TestFCOpError(unittest.TestCase):
def test_errors(self):
with program_guard(Program(), Program()):
input_data = np.random.random((2, 4)).astype("float32")
......
......@@ -21,7 +21,7 @@ import numpy
import unittest
class TestFetchVar(op_test.OpTest):
class TestFetchVar(unittest.TestCase):
def set_input(self):
self.val = numpy.array([1, 3, 5]).astype(numpy.int32)
......
......@@ -91,7 +91,7 @@ def run_pserver(use_cuda, sync_mode, ip, port, trainers, trainer_id):
exe.run(main_program)
class TestFlListenAndServOp(OpTest):
class TestFlListenAndServOp(unittest.TestCase):
def setUp(self):
self.ps_timeout = 5
self.ip = "127.0.0.1"
......
......@@ -222,7 +222,7 @@ class TestGroupNormAPI_With_NHWC(OpTest):
self.assertTrue(np.allclose(results[1], expect_res2[0]))
class TestGroupNormException(OpTest):
class TestGroupNormException(unittest.TestCase):
# data_layout is not NHWC or NCHW
def test_exception(self):
data = fluid.data(name='data', shape=[None, 3, 3, 4], dtype="float32")
......
......@@ -214,7 +214,7 @@ class TestLookupTableApi(unittest.TestCase):
return_numpy=False)
class TestEmbedOpError(OpTest):
class TestEmbedOpError(unittest.TestCase):
def test_errors(self):
with program_guard(Program(), Program()):
input_data = np.random.randint(0, 10, (4, 6)).astype("int64")
......
......@@ -51,7 +51,7 @@ class TestMulOp(OpTest):
['X'], 'Out', max_relative_error=0.5, no_grad_set=set('Y'))
class TestMulOpError(OpTest):
class TestMulOpError(unittest.TestCase):
def test_errors(self):
with program_guard(Program(), Program()):
# The input type of mul_op must be Variable.
......
......@@ -137,7 +137,7 @@ class TestOneHotOp_out_of_range(OpTest):
self.check_output(check_dygraph=False)
class TestOneHotOp_exception(OpTest):
class TestOneHotOp_exception(unittest.TestCase):
def setUp(self):
self.op_type = 'one_hot'
self.depth = 10
......
......@@ -134,7 +134,7 @@ class TestOneHotOp_out_of_range(OpTest):
self.check_output(check_dygraph=False)
class TestOneHotOp_exception(OpTest):
class TestOneHotOp_exception(unittest.TestCase):
def setUp(self):
self.op_type = 'one_hot_v2'
self.depth = 10
......
......@@ -985,7 +985,7 @@ create_test_cudnn_padding_SAME_class(TestCase1_strides)
# ----- test API
class TestPool2dAPI(OpTest):
class TestPool2dAPI(unittest.TestCase):
def test_api(self):
x_NHWC = np.random.random([2, 5, 5, 3]).astype("float32")
x_NCHW = np.random.random([2, 3, 5, 5]).astype("float32")
......@@ -1204,7 +1204,7 @@ class TestPool2dAPI(OpTest):
data_format="NHWC"))
class TestPool2dAPI_Error(OpTest):
class TestPool2dAPI_Error(unittest.TestCase):
def test_api(self):
input_NHWC = fluid.layers.data(
name="input_NHWC",
......
......@@ -414,7 +414,7 @@ class Test1DReduceWithAxes1(OpTest):
self.check_grad(['X'], 'Out')
class TestReduceSumOpError(OpTest):
class TestReduceSumOpError(unittest.TestCase):
def test_errors(self):
with program_guard(Program(), Program()):
# The input type of reduce_sum_op must be Variable.
......@@ -426,7 +426,7 @@ class TestReduceSumOpError(OpTest):
self.assertRaises(TypeError, fluid.layers.reduce_sum, x2)
class TestReduceMeanOpError(OpTest):
class TestReduceMeanOpError(unittest.TestCase):
def test_errors(self):
with program_guard(Program(), Program()):
# The input type of reduce_mean_op must be Variable.
......
......@@ -186,7 +186,7 @@ class TestReshapeOpDimInfer2_attr_OnlyShape(TestReshapeOp_attr_OnlyShape):
# Test python API
class TestReshapeAPI(OpTest):
class TestReshapeAPI(unittest.TestCase):
# situation 1: have shape( list, no tensor), no actual shape(Tensor)
def test_1(self):
input = np.random.random([2, 25]).astype("float32")
......@@ -227,7 +227,7 @@ class TestReshapeAPI(OpTest):
# Test Input Error
class TestReshapeOpError(OpTest):
class TestReshapeOpError(unittest.TestCase):
def test_errors(self):
with program_guard(Program(), Program()):
# The x type of reshape_op must be Variable.
......
......@@ -21,7 +21,7 @@ import paddle.fluid as fluid
import paddle.fluid.core as core
class TestRunTimeException(OpTest):
class TestRunTimeException(unittest.TestCase):
def test_run_time_exception(self):
place = fluid.CPUPlace()
exe = fluid.Executor(place)
......@@ -39,7 +39,7 @@ class TestRunTimeException(OpTest):
self.assertRaises(core.EnforceNotMet, _run_program)
class TestCompileTimeException(OpTest):
class TestCompileTimeException(unittest.TestCase):
def test_compile_time_exception(self):
self.assertRaises(core.EnforceNotMet, self.build_model)
......
......@@ -158,7 +158,7 @@ class TestScatterNdAddWithHighRankDiff(OpTest):
#Test Python API
class TestScatterNdOpAPI(OpTest):
class TestScatterNdOpAPI(unittest.TestCase):
"""
test scatter_nd_add api and scatter_nd api
"""
......@@ -231,7 +231,7 @@ class TestScatterNdOpAPI(OpTest):
#Test Raise Error
class TestScatterNdOpRaise(OpTest):
class TestScatterNdOpRaise(unittest.TestCase):
def test_check_raise(self):
def check_raise_is_test():
try:
......
......@@ -438,7 +438,7 @@ class TestStridedSliceOp_strides_Tensor(OpTest):
# Test python API
class TestStridedSliceAPI(OpTest):
class TestStridedSliceAPI(unittest.TestCase):
def test_1(self):
input = np.random.random([3, 4, 5, 6]).astype("float32")
minus_1 = fluid.layers.fill_constant([1], "int32", -1)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册