Skip to content

Commit ff54416

Browse files
committed
Add unittest of unique_name
* Also follow comments, change prefix to key
1 parent e8cb97b commit ff54416

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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:])

python/paddle/v2/fluid/unique_name.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ def __call__(self, key):
5151
generator = UniqueNameGenerator()
5252

5353

54-
def generate(prefix):
55-
return generator(prefix)
54+
def generate(key):
55+
return generator(key)
5656

5757

5858
def switch(new_generator=None):

0 commit comments

Comments
 (0)