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 |
|
20 | def TopLevel():
|
21 | """Copy some metaprogramming that only happens at the top level."""
|
22 | # from core/meta.py
|
23 | from core.meta import (_ID_TO_KIND_INTEGERS, BOOL_ARG_TYPES,
|
24 | TEST_UNARY_LOOKUP, TEST_BINARY_LOOKUP,
|
25 | TEST_OTHER_LOOKUP, types_asdl)
|
26 | from core import id_kind_def
|
27 |
|
28 | ID_SPEC = id_kind_def.IdSpec(_ID_TO_KIND_INTEGERS, BOOL_ARG_TYPES)
|
29 |
|
30 | id_kind_def.AddKinds(ID_SPEC)
|
31 | id_kind_def.AddBoolKinds(ID_SPEC,
|
32 | types_asdl.bool_arg_type_e) # must come second
|
33 | id_kind_def.SetupTestBuiltin(ID_SPEC, TEST_UNARY_LOOKUP,
|
34 | TEST_BINARY_LOOKUP, TEST_OTHER_LOOKUP,
|
35 | types_asdl.bool_arg_type_e)
|
36 |
|
37 | from osh import arith_parse
|
38 | spec = arith_parse.MakeShellSpec()
|
39 |
|
40 |
|
41 | def Match():
|
42 | from frontend.match import _MatchOshToken_Slow, _MatchTokenSlow
|
43 | from frontend import lexer_def
|
44 | MATCHER = _MatchOshToken_Slow(lexer_def.LEXER_DEF)
|
45 | ECHO_MATCHER = _MatchTokenSlow(lexer_def.ECHO_E_DEF)
|
46 | GLOB_MATCHER = _MatchTokenSlow(lexer_def.GLOB_DEF)
|
47 | PS1_MATCHER = _MatchTokenSlow(lexer_def.PS1_DEF)
|
48 | HISTORY_MATCHER = _MatchTokenSlow(lexer_def.HISTORY_DEF)
|
49 |
|
50 |
|
51 | def Arith():
|
52 | from osh.arith_parse import MakeShellSpec
|
53 | SPEC = MakeShellSpec()
|
54 |
|
55 |
|
56 | def UnitTests():
|
57 | loader = unittest.TestLoader()
|
58 |
|
59 | g = glob.glob
|
60 | py = g('lazylex/*_test.py') + g('doctools/*_test.py')
|
61 | #py = g('frontend/*_test.py') + g('osh/*_test.py') + g('core/*_test.py') + g('')
|
62 | # hangs
|
63 | #py.remove('core/process_test.py')
|
64 |
|
65 | modules = []
|
66 | for p in py:
|
67 | mod_name = p[:-3].replace('/', '.')
|
68 | print(mod_name)
|
69 | modules.append(__import__(mod_name, fromlist=['.']))
|
70 |
|
71 | for m in modules:
|
72 | print(m)
|
73 |
|
74 | suites = [loader.loadTestsFromModule(m) for m in modules]
|
75 |
|
76 | suite = unittest.TestSuite()
|
77 | for s in suites:
|
78 | suite.addTest(s)
|
79 |
|
80 | runner = unittest.TextTestRunner()
|
81 |
|
82 | collect_types.init_types_collection()
|
83 | with collect_types.collect():
|
84 | runner.run(suite)
|
85 | if 0:
|
86 | TopLevel()
|
87 | Match()
|
88 | Arith()
|
89 |
|
90 | collect_types.dump_stats('type_info.json')
|
91 |
|
92 |
|
93 | def Doctools():
|
94 | from doctools import help_gen
|
95 | from doctools import oils_doc
|
96 |
|
97 | collect_types.init_types_collection()
|
98 | with collect_types.collect():
|
99 | help_gen.main([
|
100 | '', 'cards-from-chapters', '_devbuild/help',
|
101 | '_tmp/code-blocks/help_meta.py', '_gen/frontend/help_meta',
|
102 | '_release/VERSION/doc/ref/chap-front-end.html'
|
103 | ])
|
104 | #oils_doc.main([])
|
105 |
|
106 | collect_types.dump_stats('type_info.json')
|
107 |
|
108 |
|
109 | def main():
|
110 | #UnitTests()
|
111 | Doctools()
|
112 |
|
113 |
|
114 | if __name__ == '__main__':
|
115 | main()
|