File: conftest.py

package info (click to toggle)
python-pegen 0.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,980 kB
  • sloc: python: 15,064; makefile: 89
file content (36 lines) | stat: -rw-r--r-- 1,213 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
""""Conftest for pure python parser."""
from pathlib import Path

import pytest
from pegen.build import build_parser
from pegen.utils import generate_parser


@pytest.fixture(scope="session")
def python_parser_cls():
    grammar_path = Path(__file__).parent.parent.parent / "data/python.gram"
    grammar = build_parser(grammar_path)[0]
    source_path = str(Path(__file__).parent / "parser_cache" / "py_parser.py")
    parser_cls = generate_parser(grammar, source_path, "PythonParser")

    return parser_cls


@pytest.fixture(scope="session")
def python_parse_file():
    grammar_path = Path(__file__).parent.parent.parent / "data/python.gram"
    grammar = build_parser(grammar_path)[0]
    source_path = str(Path(__file__).parent / "parser_cache" / "py_parser.py")
    parser_cls = generate_parser(grammar, source_path, "parse_file")

    return parser_cls


@pytest.fixture(scope="session")
def python_parse_str():
    grammar_path = Path(__file__).parent.parent.parent / "data/python.gram"
    grammar = build_parser(grammar_path)[0]
    source_path = str(Path(__file__).parent / "parser_cache" / "py_parser.py")
    parser_cls = generate_parser(grammar, source_path, "parse_string")

    return parser_cls