-
Notifications
You must be signed in to change notification settings - Fork 30
/
test_utils.py
51 lines (39 loc) · 1.74 KB
/
test_utils.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
from sem import list_param_combinations, automatic_parser, stdout_automatic_parser
import json
import numpy as np
from operator import getitem
def test_list_param_combinations():
# Two possible combinations
d1 = {'a': [1, 2]}
assert set(map(lambda x: getitem(x, 'a'),
list_param_combinations(d1))) == set([1, 2])
# Two possible combinations with two specified values
d2 = {'b': [3], 'c': [4, 5]}
assert set(map(lambda x: getitem(x, 'b'),
list_param_combinations(d2))) == set([3, 3])
assert set(map(lambda x: getitem(x, 'c'),
list_param_combinations(d2))) == set([4, 5])
# Four combinations with two specified values
d3 = {'d': [6, 7], 'e': [8, 9]}
assert sorted(map(lambda x: json.dumps(x, sort_keys=True),
list_param_combinations(d3))) == sorted(
map(lambda x: json.dumps(x, sort_keys=True),
[{'d': 6, 'e': 8}, {'d': 7, 'e': 8},
{'d': 6, 'e': 9}, {'d': 7, 'e': 9}]))
def test_stdout_automatic_parser(result):
# Create a dummy result
result['output'] = {}
result['output']['stderr'] = ''
result['output']['stdout'] = '1 2 3 4 5\n6 7 8 9 10'
parsed = stdout_automatic_parser(result)
assert np.all(parsed == [[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10]])
def test_automatic_parser(result):
# Create a dummy result
result['output'] = {}
result['output']['stderr'] = ''
result['output']['stdout'] = '1 2 3 4 5\n6 7 8 9 10'
parsed = automatic_parser(result)
assert np.all(parsed['stdout'] == [[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10]])
assert parsed['stderr'] == []