|
| 1 | +# Copyright (c) 2018 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 | + |
| 15 | +import unittest |
| 16 | +import paddle.v2.fluid as fluid |
| 17 | + |
| 18 | + |
| 19 | +class TestUniqueName(unittest.TestCase): |
| 20 | + def test_guard(self): |
| 21 | + with fluid.unique_name.guard(): |
| 22 | + name_1 = fluid.unique_name.generate('') |
| 23 | + |
| 24 | + with fluid.unique_name.guard(): |
| 25 | + name_2 = fluid.unique_name.generate('') |
| 26 | + |
| 27 | + self.assertEqual(name_1, name_2) |
| 28 | + |
| 29 | + with fluid.unique_name.guard("A"): |
| 30 | + name_1 = fluid.unique_name.generate('') |
| 31 | + |
| 32 | + with fluid.unique_name.guard('B'): |
| 33 | + name_2 = fluid.unique_name.generate('') |
| 34 | + |
| 35 | + self.assertNotEqual(name_1, name_2) |
| 36 | + |
| 37 | + def test_generate(self): |
| 38 | + with fluid.unique_name.guard(): |
| 39 | + name1 = fluid.unique_name.generate('fc') |
| 40 | + name2 = fluid.unique_name.generate('fc') |
| 41 | + name3 = fluid.unique_name.generate('tmp') |
| 42 | + self.assertNotEqual(name1, name2) |
| 43 | + self.assertEqual(name1[-2:], name3[-2:]) |
0 commit comments