|
1 | 1 | #!/usr/bin/env python |
2 | | -# Copyright (c) 2016 Baidu, Inc. All Rights Reserved |
| 2 | +# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved. |
3 | 3 | # |
4 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | # you may not use this file except in compliance with the License. |
|
14 | 14 | # limitations under the License. |
15 | 15 |
|
16 | 16 | import sys |
| 17 | +import re |
17 | 18 | import getopt |
18 | 19 |
|
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 = "" |
24 | 27 |
|
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 |
29 | 33 |
|
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""" |
34 | 40 |
|
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) |
39 | 42 |
|
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