-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_texoid.py
40 lines (31 loc) · 1.13 KB
/
test_texoid.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
import argparse
import glob
import os
from base64 import b64decode
import requests
SAMPLE_LATEX_DIR = os.path.join(os.path.dirname(__file__), 'tests')
def main():
parser = argparse.ArgumentParser(description='Texoid testing program.')
parser.add_argument('url', help='the URL on which Texoid runs')
args = parser.parse_args()
for file in glob.iglob(os.path.join(SAMPLE_LATEX_DIR, '*.tex')):
print('Testing Texoid rendering:', file)
with open(file, 'rb') as f:
body = f.read()
resp = requests.post(args.url, data=body, headers={
'Content-Type': 'text/plain'
})
resp.raise_for_status()
data = resp.json()
assert data['success']
assert 'png' in data
assert b64decode(data['png'].encode('ascii')).startswith(b'\x89PNG')
assert 'svg' in data
assert '<svg' in data['svg']
assert 'meta' in data
assert 'width' in data['meta']
assert 'height' in data['meta']
assert isinstance(data['meta']['width'], int)
assert isinstance(data['meta']['height'], int)
if __name__ == '__main__':
main()