Skip to content

Commit 23d5733

Browse files
author
hanchao
committed
update cr for pull #734.
1 parent 7f78912 commit 23d5733

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,26 @@ if [ -z $1 ]; then
1616
do
1717
base_protostr=$protostr/$file
1818
new_protostr=$protostr/$file.unittest
19-
diff $base_protostr $new_protostr -u &&
19+
diff $base_protostr $new_protostr -u
2020
diff $protostr/$file $protostr/$file.non_file_config.unittest -u
2121
done
2222
else
2323
for file in ${configs[*]}
2424
do
2525
if ! $1 $protostr/$file.protostr $protostr/$file.protostr.unittest; then
26-
diff $protostr/$file.protostr $protostr/$file.protostr.unittest -u &&
26+
diff $protostr/$file.protostr $protostr/$file.protostr.unittest -u
27+
fi
28+
if ! $1 $protostr/$file.protostr $protostr/$file.protostr.non_file_config.unittest; then
2729
diff $protostr/$file.protostr $protostr/$file.protostr.non_file_config.unittest -u
2830
fi
2931
done
3032

3133
for file in ${whole_configs[*]}
3234
do
3335
if ! $1 $protostr/$file.protostr $protostr/$file.protostr.unittest --whole; then
34-
diff $protostr/$file.protostr $protostr/$file.protostr.unittest -u &&
36+
diff $protostr/$file.protostr $protostr/$file.protostr.unittest -u
37+
fi
38+
if ! $1 $protostr/$file.protostr $protostr/$file.protostr.non_file_config.unittest --whole; then
3539
diff $protostr/$file.protostr $protostr/$file.protostr.non_file_config.unittest -u
3640
fi
3741
done
Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# Copyright (c) 2016 Baidu, Inc. All Rights Reserved
2+
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -14,27 +14,36 @@
1414
# limitations under the License.
1515

1616
import sys
17+
import re
1718
import getopt
1819

19-
whole = False
20-
opts, args = getopt.getopt(sys.argv[1:], "", ["whole"])
21-
for op, value in opts:
22-
if op == "--whole":
23-
whole = True
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 = ""
2427

25-
cmdstr = """
26-
from paddle.trainer.config_parser import *
27-
from paddle.trainer_config_helpers import *
28-
def configs():\n"""
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
2933

30-
for line in sys.stdin:
31-
if "import" in line and "from" in line:
32-
continue
33-
cmdstr = cmdstr + " " + line
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"""
3440

35-
if whole:
36-
cmdstr = cmdstr + """print parse_config(configs, "")"""
37-
else:
38-
cmdstr = cmdstr + """print parse_config(configs, "").model_config"""
41+
exec(cmdstr, globals, locals)
3942

40-
exec(cmdstr)
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)