Skip to content

Commit 56c20f8

Browse files
authored
Merge pull request #734 from hohdiy/dev-test
test code for issue #729
2 parents 8431513 + 957794c commit 56c20f8

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

python/paddle/trainer_config_helpers/tests/configs/generate_protostr.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ for conf in ${configs[*]}
1111
do
1212
echo "Generating " $conf
1313
python -m paddle.utils.dump_config $conf.py > $protostr/$conf.protostr.unittest
14+
cat ${conf}.py |python test_config_parser_for_non_file_config.py > $protostr/$conf.protostr.non_file_config.unittest
1415
done
1516

1617
for conf in ${whole_configs[*]}
1718
do
1819
echo "Generating " $conf
1920
python -m paddle.utils.dump_config $conf.py "" --whole > $protostr/$conf.protostr.unittest
21+
cat ${conf}.py |python test_config_parser_for_non_file_config.py --whole > $protostr/$conf.protostr.non_file_config.unittest
2022
done

python/paddle/trainer_config_helpers/tests/configs/run_tests.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,26 @@ if [ -z $1 ]; then
1717
base_protostr=$protostr/$file
1818
new_protostr=$protostr/$file.unittest
1919
diff $base_protostr $new_protostr -u
20+
diff $protostr/$file $protostr/$file.non_file_config.unittest -u
2021
done
2122
else
2223
for file in ${configs[*]}
2324
do
2425
if ! $1 $protostr/$file.protostr $protostr/$file.protostr.unittest; then
2526
diff $protostr/$file.protostr $protostr/$file.protostr.unittest -u
2627
fi
28+
if ! $1 $protostr/$file.protostr $protostr/$file.protostr.non_file_config.unittest; then
29+
diff $protostr/$file.protostr $protostr/$file.protostr.non_file_config.unittest -u
30+
fi
2731
done
2832

2933
for file in ${whole_configs[*]}
3034
do
3135
if ! $1 $protostr/$file.protostr $protostr/$file.protostr.unittest --whole; then
3236
diff $protostr/$file.protostr $protostr/$file.protostr.unittest -u
3337
fi
38+
if ! $1 $protostr/$file.protostr $protostr/$file.protostr.non_file_config.unittest --whole; then
39+
diff $protostr/$file.protostr $protostr/$file.protostr.non_file_config.unittest -u
40+
fi
3441
done
3542
fi
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import sys
17+
import re
18+
import getopt
19+
20+
def main(print_whole_config, globals, locals):
21+
'''
22+
this test will all test_config.py
23+
'''
24+
cmdstr = """from paddle.trainer.config_parser import parse_config\n"""
25+
importstr = ""
26+
functionstr = ""
27+
28+
for line in sys.stdin:
29+
if re.match("^import", line) or re.match("^from.*import", line):
30+
importstr = importstr + line
31+
else:
32+
functionstr = functionstr + " " + line
33+
34+
cmdstr = cmdstr + importstr + """def configs():\n""" + functionstr
35+
#cmdstr = cmdstr + """def configs():\n""" + importstr + functionstr
36+
if print_whole_config:
37+
cmdstr = cmdstr + """print parse_config(configs, "")"""
38+
else:
39+
cmdstr = cmdstr + """print parse_config(configs, "").model_config"""
40+
41+
exec(cmdstr, globals, locals)
42+
43+
if __name__ == '__main__':
44+
whole = False
45+
opts, args = getopt.getopt(sys.argv[1:], "", ["whole"])
46+
for op, value in opts:
47+
if op == "--whole":
48+
whole = True
49+
main(whole, globals(), locals())

0 commit comments

Comments
 (0)