MCPcopy
hub / github.com/rocky/python-uncompyle6 / test_grammar

Function test_grammar

pytest/test_grammar.py:7–129  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5
6
7def test_grammar():
8 def check_tokens(tokens, opcode_set):
9 remain_tokens = set(tokens) - opcode_set
10 remain_tokens = set([re.sub(r"_\d+$", "", t) for t in remain_tokens])
11 remain_tokens = set([re.sub("_CONT$", "", t) for t in remain_tokens])
12 remain_tokens = set([re.sub("LOAD_CODE$", "", t) for t in remain_tokens])
13 remain_tokens = set(remain_tokens) - opcode_set
14 assert remain_tokens == set([]), "Remaining tokens %s\n====\n%s" % (
15 remain_tokens,
16 p.dump_grammar(),
17 )
18
19 p = get_python_parser(PYTHON_VERSION_TRIPLE, is_pypy=IS_PYPY)
20 (lhs, rhs, tokens, right_recursive, dup_rhs) = p.check_sets()
21
22 # We have custom rules that create the below
23 expect_lhs = set(["pos_arg"])
24
25 if PYTHON_VERSION_TRIPLE < (3, 8):
26 if PYTHON_VERSION_TRIPLE < (3, 7):
27 expect_lhs.add("attribute")
28
29 expect_lhs.add("get_iter")
30
31 if PYTHON_VERSION_TRIPLE >= (3, 8) or PYTHON_VERSION_TRIPLE < (3, 0):
32 expect_lhs.add("stmts_opt")
33 else:
34 expect_lhs.add("async_with_as_stmt")
35 expect_lhs.add("async_with_stmt")
36
37 unused_rhs = set(["list", "mkfunc", "lambda_body", "unpack"])
38
39 expect_right_recursive = set([("designList", ("store", "DUP_TOP", "designList"))])
40
41 if PYTHON_VERSION_TRIPLE[:2] <= (3, 6):
42 unused_rhs.add("call")
43
44 if PYTHON_VERSION_TRIPLE >= (2, 7):
45 expect_lhs.add("kvlist")
46 expect_lhs.add("kv3")
47 unused_rhs.add("dict")
48
49 if PYTHON_VERSION_TRIPLE < (3, 7) and PYTHON_VERSION_TRIPLE[:2] != (2, 7):
50 # NOTE: this may disappear
51 expect_lhs.add("except_handler_else")
52
53 expect_lhs.add("load_genexpr")
54
55 unused_rhs = unused_rhs.union(
56 set(
57 """
58 except_pop_except generator_exp
59 """.split()
60 )
61 )
62 if PYTHON_VERSION_TRIPLE < (3, 7):
63 expect_lhs.add("annotate_arg")
64 expect_lhs.add("annotate_tuple")

Callers

nothing calls this directly

Calls 5

get_python_parserFunction · 0.90
get_scannerFunction · 0.90
check_tokensFunction · 0.85
addMethod · 0.80
unionMethod · 0.80

Tested by

no test coverage detected