|
| 1 | +# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +import unittest |
| 15 | + |
| 16 | +import paddle |
| 17 | + |
| 18 | + |
| 19 | +class TestUtilsAttrError(unittest.TestCase): |
| 20 | + def test_error(self): |
| 21 | + with self.assertRaises(AttributeError): |
| 22 | + type(paddle.utils.nonexist) |
| 23 | + |
| 24 | + |
| 25 | +class TestAlias(unittest.TestCase): |
| 26 | + def setUp(self): |
| 27 | + self.ioObject = paddle.io.Dataset |
| 28 | + self.utilsObject = paddle.utils.data.Dataset |
| 29 | + |
| 30 | + def test_compatibility(self): |
| 31 | + self.assertTrue(type(self.ioObject) == type(self.utilsObject)) |
| 32 | + |
| 33 | + |
| 34 | +class TestChainDatasetAlias(TestAlias): |
| 35 | + def setUp(self): |
| 36 | + self.ioObject = paddle.io.ChainDataset |
| 37 | + self.utilsObject = paddle.utils.data.ChainDataset |
| 38 | + |
| 39 | + |
| 40 | +class TestConcatDatasetAlias(TestAlias): |
| 41 | + def setUp(self): |
| 42 | + self.ioObject = paddle.io.ConcatDataset |
| 43 | + self.utilsObject = paddle.utils.data.ConcatDataset |
| 44 | + |
| 45 | + |
| 46 | +class TestIterableDatasetAlias(TestAlias): |
| 47 | + def setUp(self): |
| 48 | + self.ioObject = paddle.io.IterableDataset |
| 49 | + self.utilsObject = paddle.utils.data.IterableDataset |
| 50 | + |
| 51 | + |
| 52 | +class TestSamplerAlias(TestAlias): |
| 53 | + def setUp(self): |
| 54 | + self.ioObject = paddle.io.Sampler |
| 55 | + self.utilsObject = paddle.utils.data.Sampler |
| 56 | + |
| 57 | + |
| 58 | +class TestSequentialSamplerAlias(TestAlias): |
| 59 | + def setUp(self): |
| 60 | + self.ioObject = paddle.io.SequenceSampler |
| 61 | + self.utilsObject = paddle.utils.data.SequentialSampler |
| 62 | + |
| 63 | + |
| 64 | +class TestSubsetAlias(TestAlias): |
| 65 | + def setUp(self): |
| 66 | + self.ioObject = paddle.io.Subset |
| 67 | + self.utilsObject = paddle.utils.data.Subset |
| 68 | + |
| 69 | + |
| 70 | +class TestGetWorkerInfoAlias(TestAlias): |
| 71 | + def setUp(self): |
| 72 | + self.ioObject = paddle.io.get_worker_info |
| 73 | + self.utilsObject = paddle.utils.data.get_worker_info |
| 74 | + |
| 75 | + |
| 76 | +class TestRandomSplitAlias(TestAlias): |
| 77 | + def setUp(self): |
| 78 | + self.ioObject = paddle.io.random_split |
| 79 | + self.utilsObject = paddle.utils.data.random_split |
| 80 | + |
| 81 | + |
| 82 | +class TestDefaultCollateAlias(TestAlias): |
| 83 | + def setUp(self): |
| 84 | + self.ioObject = paddle.io.dataloader.collate.default_collate_fn |
| 85 | + self.utilsObject = paddle.utils.data.default_collate |
| 86 | + |
| 87 | + |
| 88 | +if __name__ == "__main__": |
| 89 | + unittest.main() |
0 commit comments