Skip to content

Commit

Permalink
fix unit tests that do not need to inherit OpTest (PaddlePaddle#21460)
Browse files Browse the repository at this point in the history
* fix PythonAPI test in Op unittest, test=develop
* fix unit tests that do not need to inherit OpTest, test=develop
  • Loading branch information
Zhang Ting authored and seiriosPlus committed Dec 9, 2019
1 parent 42c97a4 commit 8a60277
Show file tree
Hide file tree
Showing 23 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_accuracy_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_check_output(self):
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.
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/fluid/tests/unittests/test_activation_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
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.
Expand Down Expand Up @@ -537,7 +537,7 @@ def test_check_grad(self):
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ def init_test_case(self):
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")

Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_cast_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_check_output(self):
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ def init_test_case(self):
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')
Expand Down Expand Up @@ -796,7 +796,7 @@ def test_case1(self):
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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ def init_op_type(self):
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')
Expand Down Expand Up @@ -642,7 +642,7 @@ def test_case1(self):
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")
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_crop_tensor_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def initTestCase(self):
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")
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_downpoursgd.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import paddle.fluid.incubate.fleet.parameter_server.pslib.ps_pb2 as pslib


class TestListenAndServOp(OpTest):
class TestListenAndServOp(unittest.TestCase):
"""TestListenAndServOp."""

def setUp(self):
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/fluid/tests/unittests/test_expand_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def test_check_output(self):
self.check_output()


class TestExpandError(OpTest):
class TestExpandError(unittest.TestCase):
def test_errors(self):
with program_guard(Program(), Program()):
x1 = fluid.create_lod_tensor(
Expand All @@ -208,7 +208,7 @@ def test_errors(self):


# 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(
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_fc_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def config(self):
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")
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_fetch_var.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_group_norm_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def test_case1(self):
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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def test_api(self):
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")
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_mul_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_check_grad_ingore_y(self):
['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.
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_one_hot_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def test_check_output(self):
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
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_one_hot_v2_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_check_output(self):
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
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/fluid/tests/unittests/test_pool2d_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ def init_shape(self):


# ----- 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")
Expand Down Expand Up @@ -1204,7 +1204,7 @@ def test_api(self):
data_format="NHWC"))


class TestPool2dAPI_Error(OpTest):
class TestPool2dAPI_Error(unittest.TestCase):
def test_api(self):
input_NHWC = fluid.layers.data(
name="input_NHWC",
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/fluid/tests/unittests/test_reduce_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def test_check_grad(self):
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.
Expand All @@ -426,7 +426,7 @@ def test_errors(self):
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.
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/fluid/tests/unittests/test_reshape_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def init_data(self):


# 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")
Expand Down Expand Up @@ -227,7 +227,7 @@ def test_1(self):


# 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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)
Expand All @@ -39,7 +39,7 @@ def _run_program():
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)

Expand Down
4 changes: 2 additions & 2 deletions python/paddle/fluid/tests/unittests/test_scatter_nd_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def test_check_grad(self):


#Test Python API
class TestScatterNdOpAPI(OpTest):
class TestScatterNdOpAPI(unittest.TestCase):
"""
test scatter_nd_add api and scatter_nd api
"""
Expand Down Expand Up @@ -231,7 +231,7 @@ def testcase4(self):


#Test Raise Error
class TestScatterNdOpRaise(OpTest):
class TestScatterNdOpRaise(unittest.TestCase):
def test_check_raise(self):
def check_raise_is_test():
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def test_check_grad_normal(self):


# 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)
Expand Down

0 comments on commit 8a60277

Please sign in to comment.