-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest.py
More file actions
93 lines (73 loc) · 2.11 KB
/
test.py
File metadata and controls
93 lines (73 loc) · 2.11 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""quick-and-dirty test script
put *.fds in fds/ directory, and run this script.
"""
import pathlib
import subprocess
import sys
import tempfile
FDSCHECK = "./fdscheck"
FDSSPLIT = "./fdssplit"
FDSBUILD = "./fdsbuild"
FDS_DIR = pathlib.Path("fds/")
FDSS = tuple(FDS_DIR.glob("*.fds"))
def test_fds(fds):
try:
plain_fds = check_plain(fds)
with tempfile.NamedTemporaryFile(delete=False) as tmp:
body = check_manifest(fds)
if not body: return False
tmp.write(check_manifest(fds))
manifest = tmp.name
with tempfile.TemporaryDirectory() as dir_:
split(fds, dir_)
with tempfile.NamedTemporaryFile(delete=False) as tmp:
fds_out = tmp.name
build(fds_out, manifest, dir_, has_header(fds))
plain_fds_out = check_plain(fds_out)
return plain_fds == plain_fds_out
except Exception as e:
print(e, file=sys.stderr)
return False
def check_plain(fds):
cmdline = ( FDSCHECK, fds )
proc = subprocess.run(cmdline, check=True, stdout=subprocess.PIPE)
return proc.stdout
def check_manifest(fds):
cmdline = (
FDSCHECK,
"-f", "manifest",
fds,
)
proc = subprocess.run(cmdline, check=True, stdout=subprocess.PIPE)
return proc.stdout
def split(fds, destdir):
cmdline = (
FDSSPLIT,
"-d", destdir,
fds,
)
subprocess.run(cmdline, check=True, stdout=subprocess.DEVNULL)
def build(fds_out, manifest, srcdir, with_header):
opts = () if with_header else ("--noheader",)
cmdline = (
FDSBUILD,
"-d", srcdir,
*opts,
fds_out,
manifest,
)
subprocess.run(cmdline, check=True, stdout=subprocess.DEVNULL)
def has_header(fds):
return fds.stat().st_size % 65500 == 16
def main():
n_ok = 0
for fds in FDSS:
if test_fds(fds):
n_ok += 1
else:
print(f"{fds}: failed")
print(f"{n_ok}/{len(FDSS)} success")
sys.exit(0 if n_ok == len(FDSS) else 1)
if __name__ == "__main__": main()