-
Notifications
You must be signed in to change notification settings - Fork 7
/
rulestable.py
59 lines (52 loc) · 2.12 KB
/
rulestable.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
import json
import sys
if len(sys.argv) < 2:
print('Usage python rulestable.py rulesets/standard.json')
exit()
rulesets = json.load(open(sys.argv[1]))
print("""
.. list-table::
:header-rows: 1
* - Context
- Element/Attribute
- Requirement
- Tested if
""") # noqa
english = {
'date_order': 'Dates must be in correct order',
'no_more_than_one': 'No more than one',
'only_one_of': 'Excluded elements must not coexist with selected elements, and only one of these elements must exist',
'atleast_one': 'Atleast one must be present',
'one_or_all': 'One must be present or all of the others must be',
'sum': 'Must sum to {0}',
'startswith': 'Must start with ``{0}``',
'unique': 'Unique',
'range': 'The value must be at least ``min`` and no more than ``max`` (inclusive).',
'time_limit': 'Length must be under a year',
'date_now': 'Date must not be more recent than the current date',
'between_dates': 'Date must be within a defined time period',
'if_then': 'If ```if``` evaluates to true, ```then``` must evaluate to true',
'loop': 'Loops through different values of an attribute or element.',
'strict_sum': 'Must sum to {0} as a decimal'
}
for xpath, rules in rulesets.items():
for rule in rules:
cases = rules[rule]['cases']
for case in cases:
print(' * -', xpath)
if rule not in ['date_order']:
for i, path in enumerate(case['paths']):
print(' ' if i else ' -', '``{0}``'.format(path))
elif rule == 'date_order':
print(' -', case['less'])
print(' ', case['more'])
if rule in english:
requirement = english[rule]
if rule == 'sum':
requirement = requirement.format(case['sum'])
elif rule == 'startswith':
requirement = requirement.format(case['start'])
else:
requirement = rule
print(' -', requirement)
print(' -', '``{0}``'.format(case['condition']) if 'condition' in case else '')