-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_test.py
53 lines (43 loc) · 1.51 KB
/
make_test.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import setup
import sys
import os
import subprocess
import uuid
def main_with_params(L: int, R: int):
if L > R:
print("L must be less than or equal to R.")
sys.exit(1)
config = setup.load_config()
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
relative_work_dir = config["paths"]["relative_work_dir"]
work_dir = os.path.abspath(os.path.join(SCRIPT_DIR, relative_work_dir))
unique_id = uuid.uuid4().hex
tmp_dir = os.path.join(SCRIPT_DIR, f"tmp_dir_{unique_id}")
os.makedirs(tmp_dir, exist_ok=True)
tmp_file = os.path.join(SCRIPT_DIR, f"tmp_{unique_id}.txt")
with open(tmp_file, "w") as f:
for x in range(L, R):
f.write(f"{x}\n")
gen = os.path.join(work_dir, config["files"]["gen_file"])
cmd = [gen, tmp_file, f"--dir={tmp_dir}"]
subprocess.run(cmd, check=True, cwd=SCRIPT_DIR)
in_dir = os.path.join(work_dir, config["test"]["input_dir"])
os.makedirs(in_dir, exist_ok=True)
total_cases = R - L
for i in range(total_cases):
src_path = os.path.join(tmp_dir, f"{i:04d}.txt")
new_file_name = f"{L + i:04d}.txt"
dst_path = os.path.join(in_dir, new_file_name)
if os.path.exists(src_path):
os.rename(src_path, dst_path)
os.remove(tmp_file)
os.rmdir(tmp_dir)
def main():
if len(sys.argv) < 3:
print("Usage: python make_test.py <L> <R>")
sys.exit(1)
L = int(sys.argv[1])
R = int(sys.argv[2])
main_with_params(L, R)
if __name__ == "__main__":
main()