|
17 | 17 | import re |
18 | 18 | import getopt |
19 | 19 |
|
| 20 | + |
20 | 21 | def main(print_whole_config, globals, locals): |
21 | | - ''' |
| 22 | + ''' |
22 | 23 | this test will all test_config.py |
23 | 24 | ''' |
24 | | - cmdstr = """from paddle.trainer.config_parser import parse_config\n""" |
25 | | - importstr = "" |
26 | | - functionstr = "" |
| 25 | + cmdstr = """from paddle.trainer.config_parser import parse_config\n""" |
| 26 | + importstr = "" |
| 27 | + functionstr = "" |
| 28 | + |
| 29 | + for line in sys.stdin: |
| 30 | + if re.match("^import", line) or re.match("^from.*import", line): |
| 31 | + importstr = importstr + line |
| 32 | + else: |
| 33 | + functionstr = functionstr + " " + line |
27 | 34 |
|
28 | | - for line in sys.stdin: |
29 | | - if re.match("^import", line) or re.match("^from.*import", line): |
30 | | - importstr = importstr + line |
| 35 | + cmdstr = cmdstr + importstr + """def configs():\n""" + functionstr |
| 36 | + #cmdstr = cmdstr + """def configs():\n""" + importstr + functionstr |
| 37 | + if print_whole_config: |
| 38 | + cmdstr = cmdstr + """print parse_config(configs, "")""" |
31 | 39 | else: |
32 | | - functionstr = functionstr + " " + line |
| 40 | + cmdstr = cmdstr + """print parse_config(configs, "").model_config""" |
33 | 41 |
|
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""" |
| 42 | + exec (cmdstr, globals, locals) |
40 | 43 |
|
41 | | - exec(cmdstr, globals, locals) |
42 | 44 |
|
43 | 45 | 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()) |
| 46 | + whole = False |
| 47 | + opts, args = getopt.getopt(sys.argv[1:], "", ["whole"]) |
| 48 | + for op, value in opts: |
| 49 | + if op == "--whole": |
| 50 | + whole = True |
| 51 | + main(whole, globals(), locals()) |
0 commit comments