Skip to content

Commit 5caaa76

Browse files
committed
chore: modernize benchmark test code
1 parent 2ffdec8 commit 5caaa76

1 file changed

Lines changed: 12 additions & 16 deletions

File tree

benchmarks/test_parser.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
import pytest
2-
import os
2+
import shlex
33
import subprocess
4+
from pathlib import Path
5+
from typing import List, Tuple
46
from pyquil._parser.parser import run_parser
57
from pyquil.quil import Program
68

79

8-
def from_corpus():
10+
def from_corpus() -> List[Tuple[Path, str]]:
911
programs = []
10-
dir = os.path.join(os.path.dirname(__file__), "quilc", "tests", "good-test-files")
11-
if not os.path.exists(dir):
12-
subprocess.Popen(["git", "submodule", "update", "--init", "--recursive"]).wait()
13-
14-
for path in os.listdir(dir):
15-
filepath = os.path.join(dir, path)
16-
if os.path.isfile(filepath):
17-
file = open(filepath, "r")
18-
program = file.read()
12+
DIR = Path(__file__).parent / "quilc" / "tests" / "good-test-files"
13+
if not DIR.exists():
14+
subprocess.run(shlex.split("git submodule update --init --recursive"))
15+
for path in DIR.glob("*.quil"):
16+
with path.open() as f:
17+
program = f.read()
1918
try:
2019
run_parser(program)
21-
programs.append((path, program))
20+
programs.append((path.name, program))
2221
except:
23-
continue
24-
finally:
25-
file.close()
26-
22+
continue # TODO log these or something?
2723
return programs
2824

2925

0 commit comments

Comments
 (0)