1 | #!/usr/bin/env python2
|
2 | """
|
3 | pyann_driver.py: Collect types
|
4 | """
|
5 | import unittest
|
6 |
|
7 | from pyannotate_runtime import collect_types
|
8 |
|
9 | #from asdl import typed_arith_parse_test
|
10 | from asdl import format_test
|
11 | from core import comp_ui_test
|
12 | from osh import arith_parse_test
|
13 | from osh import bool_parse_test
|
14 | from osh import cmd_parse_test
|
15 | from osh import word_parse_test
|
16 |
|
17 | import glob
|
18 |
|
19 | def TopLevel():
|
20 | """Copy some metaprogramming that only happens at the top level."""
|
21 | # from core/meta.py
|
22 | from core.meta import (
|
23 | _ID_TO_KIND_INTEGERS, BOOL_ARG_TYPES, TEST_UNARY_LOOKUP,
|
24 | TEST_BINARY_LOOKUP, TEST_OTHER_LOOKUP,
|
25 | types_asdl
|
26 | )
|
27 | from core import id_kind_def
|
28 |
|
29 | ID_SPEC = id_kind_def.IdSpec(_ID_TO_KIND_INTEGERS, BOOL_ARG_TYPES)
|
30 |
|
31 | id_kind_def.AddKinds(ID_SPEC)
|
32 | id_kind_def.AddBoolKinds(ID_SPEC, types_asdl.bool_arg_type_e) # must come second
|
33 | id_kind_def.SetupTestBuiltin(ID_SPEC,
|
34 | TEST_UNARY_LOOKUP, TEST_BINARY_LOOKUP,
|
35 | TEST_OTHER_LOOKUP,
|
36 | types_asdl.bool_arg_type_e)
|
37 |
|
38 | from osh import arith_parse
|
39 | spec = arith_parse.MakeShellSpec()
|
40 |
|
41 |
|
42 | def Match():
|
43 | from frontend.match import _MatchOshToken_Slow, _MatchTokenSlow
|
44 | from frontend import lexer_def
|
45 | MATCHER = _MatchOshToken_Slow(lexer_def.LEXER_DEF)
|
46 | ECHO_MATCHER = _MatchTokenSlow(lexer_def.ECHO_E_DEF)
|
47 | GLOB_MATCHER = _MatchTokenSlow(lexer_def.GLOB_DEF)
|
48 | PS1_MATCHER = _MatchTokenSlow(lexer_def.PS1_DEF)
|
49 | HISTORY_MATCHER = _MatchTokenSlow(lexer_def.HISTORY_DEF)
|
50 |
|
51 |
|
52 | def Arith():
|
53 | from osh.arith_parse import MakeShellSpec
|
54 | SPEC = MakeShellSpec()
|
55 |
|
56 |
|
57 | def main():
|
58 | loader = unittest.TestLoader()
|
59 |
|
60 | g = glob.glob
|
61 | py = g('lazylex/*_test.py') + g('doctools/*_test.py')
|
62 | #py = g('frontend/*_test.py') + g('osh/*_test.py') + g('core/*_test.py') + g('')
|
63 | # hangs
|
64 | #py.remove('core/process_test.py')
|
65 |
|
66 | modules = []
|
67 | for p in py:
|
68 | mod_name = p[:-3].replace('/', '.')
|
69 | print(mod_name)
|
70 | modules.append(__import__(mod_name, fromlist=['.']))
|
71 |
|
72 | for m in modules:
|
73 | print(m)
|
74 |
|
75 | suites = [loader.loadTestsFromModule(m) for m in modules]
|
76 |
|
77 | suite = unittest.TestSuite()
|
78 | for s in suites:
|
79 | suite.addTest(s)
|
80 |
|
81 | runner = unittest.TextTestRunner()
|
82 |
|
83 | collect_types.init_types_collection()
|
84 | with collect_types.collect():
|
85 | runner.run(suite)
|
86 | if 0:
|
87 | TopLevel()
|
88 | Match()
|
89 | Arith()
|
90 |
|
91 | collect_types.dump_stats('type_info.json')
|
92 |
|
93 |
|
94 | if __name__ == '__main__':
|
95 | main()
|