-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtests.py
66 lines (55 loc) · 1.8 KB
/
tests.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
54
55
56
57
58
59
60
61
62
63
64
65
66
'''
# TODO: use a test framework / runner
'''
import os
import mnlgxdprog
import mnlgxdlib
import xd_prog_bin
def round_trip(patch_bin):
parsed = xd_prog_bin.parse(patch_bin)
print 'Patch name: {}'.format(parsed['name'])
serialized = parsed.serialize()
if serialized != patch_bin:
raise ValueError('Patch {} did not round trip successfully'.format(parsed['name']))
else:
print 'Successfully round tripped: {}'.format(parsed['name'])
print
def test_patches_round_trip():
root = 'tests/patches/valid'
patch_files = os.listdir(root)
for f in patch_files:
print 'round trip patch: {}'.format(f)
patch_bin = mnlgxdprog.extract_patch_bin(os.path.join(root, f))
round_trip(patch_bin)
def test_libraries_round_trip():
root = 'tests/libraries/'
library_files = os.listdir(root)
for f in library_files:
print 'round trip library: {}'.format(f)
for p_file, p_bin in mnlgxdlib.extract_all_patch_bins(os.path.join(root, f)):
print '-> {}'.format(p_file)
round_trip(p_bin)
def test_patches_pp():
root = 'tests/patches/valid'
patch_files = os.listdir(root)
for f in patch_files:
print 'pp: {}'.format(f)
patch_bin = mnlgxdprog.extract_patch_bin(os.path.join(root, f))
parsed = xd_prog_bin.parse(patch_bin)
ignored = parsed.pretty_print()
def test_libraries_pp():
root = 'tests/libraries/'
library_files = os.listdir(root)
for f in library_files:
print 'pp library: {}'.format(f)
for p_file, p_bin in mnlgxdlib.extract_all_patch_bins(os.path.join(root, f)):
print '-> {}'.format(p_file)
parsed = parsed = xd_prog_bin.parse(p_bin)
ignored = parsed.pretty_print()
test_patches_round_trip()
print '-----------'
test_libraries_round_trip()
print '-----------'
test_patches_pp()
print '-----------'
test_libraries_pp()