From f64d00662238c279062012399f4ed3f8e2aada3c Mon Sep 17 00:00:00 2001 From: juncaipeng <52520497+juncaipeng@users.noreply.github.com> Date: Thu, 12 Dec 2019 09:45:00 +0800 Subject: [PATCH] Change several tests to inherit the right parent class, test=develop (#21652) * change several tests to use the right parent class, test=develop * add dtype for TestLoDTensorAndSelectedRowsOp, test=develop --- .../paddle/fluid/tests/unittests/test_clip_by_norm_op.py | 2 +- python/paddle/fluid/tests/unittests/test_dropout_op.py | 9 +++++++-- .../fluid/tests/unittests/test_fill_constant_op.py | 2 +- python/paddle/fluid/tests/unittests/test_fill_op.py | 2 +- .../fluid/tests/unittests/test_lookup_sparse_table_op.py | 2 +- .../paddle/fluid/tests/unittests/test_lookup_table_op.py | 4 ++-- .../fluid/tests/unittests/test_lookup_table_v2_op.py | 2 +- python/paddle/fluid/tests/unittests/test_sum_op.py | 3 ++- 8 files changed, 16 insertions(+), 10 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_clip_by_norm_op.py b/python/paddle/fluid/tests/unittests/test_clip_by_norm_op.py index 46433d78252..d78cb9b0321 100644 --- a/python/paddle/fluid/tests/unittests/test_clip_by_norm_op.py +++ b/python/paddle/fluid/tests/unittests/test_clip_by_norm_op.py @@ -65,7 +65,7 @@ class TestCase3(TestClipByNormOp): self.max_norm = 1.0 -class TestClipByNormOpWithSelectedRows(OpTest): +class TestClipByNormOpWithSelectedRows(unittest.TestCase): def check_with_place(self, place): self.config_test_case() scope = core.Scope() diff --git a/python/paddle/fluid/tests/unittests/test_dropout_op.py b/python/paddle/fluid/tests/unittests/test_dropout_op.py index 7047e5a2d87..29460d07dfd 100644 --- a/python/paddle/fluid/tests/unittests/test_dropout_op.py +++ b/python/paddle/fluid/tests/unittests/test_dropout_op.py @@ -171,6 +171,9 @@ class TestDropoutOpWithSeed(OpTest): self.check_grad(['X'], 'Out', max_relative_error=0.05) +@unittest.skipIf( + not core.is_compiled_with_cuda() or not core.op_support_gpu("dropout"), + "core is not compiled with CUDA or core is not support dropout") class TestFP16DropoutOp(OpTest): def setUp(self): self.op_type = "dropout" @@ -192,10 +195,12 @@ class TestFP16DropoutOp(OpTest): self.fix_seed = True def test_check_output(self): - if core.is_compiled_with_cuda() and core.op_support_gpu("dropout"): - self.check_output_with_place(core.CUDAPlace(0), atol=1e-3) + self.check_output_with_place(core.CUDAPlace(0), atol=1e-3) +@unittest.skipIf( + not core.is_compiled_with_cuda() or not core.op_support_gpu("dropout"), + "core is not compiled with CUDA or core is not support dropout") class TestFP16DropoutOp2(TestFP16DropoutOp): def init_test_case(self): self.input_size = [32, 64, 3] diff --git a/python/paddle/fluid/tests/unittests/test_fill_constant_op.py b/python/paddle/fluid/tests/unittests/test_fill_constant_op.py index 1263657025a..2baec782c42 100644 --- a/python/paddle/fluid/tests/unittests/test_fill_constant_op.py +++ b/python/paddle/fluid/tests/unittests/test_fill_constant_op.py @@ -81,7 +81,7 @@ class TestFillConstantOp4(OpTest): self.check_output() -class TestFillConstantOpWithSelectedRows(OpTest): +class TestFillConstantOpWithSelectedRows(unittest.TestCase): def check_with_place(self, place): scope = core.Scope() # create Out Variable diff --git a/python/paddle/fluid/tests/unittests/test_fill_op.py b/python/paddle/fluid/tests/unittests/test_fill_op.py index 96af96f6c7c..36b56ab9280 100644 --- a/python/paddle/fluid/tests/unittests/test_fill_op.py +++ b/python/paddle/fluid/tests/unittests/test_fill_op.py @@ -55,7 +55,7 @@ class TestFillOp2(OpTest): self.check_output(check_dygraph=False) -class TestFillOp3(OpTest): +class TestFillOp3(unittest.TestCase): def check_with_place(self, place, f_cpu): scope = core.Scope() # create Out Variable diff --git a/python/paddle/fluid/tests/unittests/test_lookup_sparse_table_op.py b/python/paddle/fluid/tests/unittests/test_lookup_sparse_table_op.py index c7f4f3e913b..a2a036e02a1 100644 --- a/python/paddle/fluid/tests/unittests/test_lookup_sparse_table_op.py +++ b/python/paddle/fluid/tests/unittests/test_lookup_sparse_table_op.py @@ -21,7 +21,7 @@ import paddle.fluid.core as core from paddle.fluid.op import Operator -class TestLookupSpraseTable(OpTest): +class TestLookupSpraseTable(unittest.TestCase): def check_with_place(self, place): scope = core.Scope() diff --git a/python/paddle/fluid/tests/unittests/test_lookup_table_op.py b/python/paddle/fluid/tests/unittests/test_lookup_table_op.py index 5c0c155b1d9..3442cd71d90 100644 --- a/python/paddle/fluid/tests/unittests/test_lookup_table_op.py +++ b/python/paddle/fluid/tests/unittests/test_lookup_table_op.py @@ -85,7 +85,7 @@ class TestLookupTableOpWithTensorIdsAndPadding(TestLookupTableOpWithTensorIds): pass -class TestLookupTableWIsSelectedRows(OpTest): +class TestLookupTableWIsSelectedRows(unittest.TestCase): def prepare_ids(self, scope, place): ids_tensor = scope.var('Ids').get_tensor() ids_array = np.array([[0], [4], [3], [5]]).astype("int64") @@ -250,7 +250,7 @@ class TestLookupTableOpWithTensorIdsAndPaddingInt8( pass -class TestLookupTableWIsSelectedRowsInt8(OpTest): +class TestLookupTableWIsSelectedRowsInt8(unittest.TestCase): def prepare_ids(self, scope, place): ids_tensor = scope.var('Ids').get_tensor() ids_array = np.array([[0], [4], [3], [5]]).astype("int64") diff --git a/python/paddle/fluid/tests/unittests/test_lookup_table_v2_op.py b/python/paddle/fluid/tests/unittests/test_lookup_table_v2_op.py index 811d48452e3..29772cd4004 100644 --- a/python/paddle/fluid/tests/unittests/test_lookup_table_v2_op.py +++ b/python/paddle/fluid/tests/unittests/test_lookup_table_v2_op.py @@ -84,7 +84,7 @@ class TestLookupTableOpWithTensorIdsAndPadding(TestLookupTableOpWithTensorIds): pass -class TestLookupTableWIsSelectedRows(OpTest): +class TestLookupTableWIsSelectedRows(unittest.TestCase): def prepare_ids(self, scope, place): ids_tensor = scope.var('Ids').get_tensor() ids_array = np.array([0, 4, 3, 5]).astype("int64") diff --git a/python/paddle/fluid/tests/unittests/test_sum_op.py b/python/paddle/fluid/tests/unittests/test_sum_op.py index 0be5be6e97d..ebf153eb2c4 100644 --- a/python/paddle/fluid/tests/unittests/test_sum_op.py +++ b/python/paddle/fluid/tests/unittests/test_sum_op.py @@ -48,7 +48,7 @@ class TestSumOp(OpTest): pass -class TestSelectedRowsSumOp(OpTest): +class TestSelectedRowsSumOp(unittest.TestCase): def setUp(self): self.height = 10 self.row_numel = 12 @@ -144,6 +144,7 @@ class TestLoDTensorAndSelectedRowsOp(TestSelectedRowsSumOp): self.height = 10 self.row_numel = 12 self.rows = [0, 1, 2, 2, 4, 5, 6] + self.dtype = np.float32 def check_with_place(self, place, inplace): scope = core.Scope() -- GitLab