-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-cli.py
34 lines (29 loc) · 1.08 KB
/
test-cli.py
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
import subprocess
from tqdm import tqdm
CLI_PATH = "cmake-build-release/btm"
content = None
with open('data/example_jhotdraw.txt') as f:
content = "".join(f.readlines())
total_iterations = 123
options = [CLI_PATH,
'--iterations', str(total_iterations),
]
process = subprocess.Popen(options, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
process.stdin.write(content.encode("utf-8"))
process.stdin.close()
doctop = []
with tqdm(total=total_iterations) as pbar:
while True:
from_program = process.stdout.readline().decode("utf-8")
if not from_program:
break
if from_program.startswith("#progress "):
pbar.n = int(from_program[len("#progress "):].split(" ")[0])
pbar.update(0)
elif from_program.startswith("#doctop "):
data = [float(x) for x in from_program[len("#doctop "):].strip().split(",")]
doctop.append(data)
else:
print("[btm] " + from_program, end="")
print("doctop received: ", len(doctop))
print("Process exited with code {}".format(process.poll()))