-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.py
executable file
·32 lines (26 loc) · 1.06 KB
/
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
#!/usr/bin/env python3
import os
from pathlib import Path
import subprocess
import sys
def byml_to_yml(data: bytes) -> bytes:
return subprocess.run(['byml_to_yml'], input=data,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True).stdout
def yml_to_byml(data: bytes) -> bytes:
return subprocess.run(['yml_to_byml'], input=data,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True).stdout
def die(m: str) -> None:
sys.stderr.write(m + '\n')
sys.exit(1)
for path in Path(os.path.dirname(os.path.realpath(__file__))).glob('test_data/*.byml'):
print(path.name)
byml_data = path.open('rb').read()
loaded_yml_data = byml_to_yml(byml_data)
yml_data = path.with_suffix('.yml').open('rb').read()
if loaded_yml_data != yml_data:
die(' parse FAIL: generated YAML does not match known output')
print(' parse OK')
roundtrip_yml_data = byml_to_yml(yml_to_byml(yml_data))
if roundtrip_yml_data != yml_data:
die(' roundtrip test FAIL: byml_to_yml(yml_to_byml(x)) != x')
print(' roundtrip OK')