OILS / devtools / types-old / pyann_driver.py View on Github | oilshell.org

94 lines, 63 significant
1#!/usr/bin/env python2
2"""
3pyann_driver.py: Collect types
4"""
5import unittest
6
7from pyannotate_runtime import collect_types
8
9#from asdl import typed_arith_parse_test
10from asdl import format_test
11from core import comp_ui_test
12from osh import arith_parse_test
13from osh import bool_parse_test
14from osh import cmd_parse_test
15from osh import word_parse_test
16
17import glob
18
19def 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
42def 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
52def Arith():
53 from osh.arith_parse import MakeShellSpec
54 SPEC = MakeShellSpec()
55
56
57def main():
58 loader = unittest.TestLoader()
59
60 g = glob.glob
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
93if __name__ == '__main__':
94 main()