Skip to content

Commit 7f78912

Browse files
author
hanchao
committed
test code for issue #729
1 parent 5777fae commit 7f78912

File tree

3 files changed

+49
-4
lines changed

3 files changed

+49
-4
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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,23 @@ 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 &&
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
25-
diff $protostr/$file.protostr $protostr/$file.protostr.unittest -u
26+
diff $protostr/$file.protostr $protostr/$file.protostr.unittest -u &&
27+
diff $protostr/$file.protostr $protostr/$file.protostr.non_file_config.unittest -u
2628
fi
2729
done
2830

2931
for file in ${whole_configs[*]}
30-
do
32+
do
3133
if ! $1 $protostr/$file.protostr $protostr/$file.protostr.unittest --whole; then
32-
diff $protostr/$file.protostr $protostr/$file.protostr.unittest -u
34+
diff $protostr/$file.protostr $protostr/$file.protostr.unittest -u &&
35+
diff $protostr/$file.protostr $protostr/$file.protostr.non_file_config.unittest -u
3336
fi
3437
done
3538
fi
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2016 Baidu, Inc. 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 getopt
18+
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
24+
25+
cmdstr = """
26+
from paddle.trainer.config_parser import *
27+
from paddle.trainer_config_helpers import *
28+
def configs():\n"""
29+
30+
for line in sys.stdin:
31+
if "import" in line and "from" in line:
32+
continue
33+
cmdstr = cmdstr + " " + line
34+
35+
if whole:
36+
cmdstr = cmdstr + """print parse_config(configs, "")"""
37+
else:
38+
cmdstr = cmdstr + """print parse_config(configs, "").model_config"""
39+
40+
exec(cmdstr)

0 commit comments

Comments
 (0)