2 Created on Jan 24, 2014
12 log = logging.getLogger('Comparator')
15 def compare_results(actual, expected):
16 #print 'ACT: ', actual
17 #print 'EXP: ', expected
19 list_unused = list(set(actual.keys()) - set(expected.keys()))
20 if len(list_unused) > 0:
21 Comparator.log.info('unchecked tags: {}'.format(list_unused))
23 list_duration = ['duration','hard_timeout','idle_timeout']
25 Comparator.test_duration(actual, expected)
27 # compare results from actual flow (mn dump result) and expepected flow (stored result)
28 for k in expected.keys():
29 if k not in list_duration:
30 assert k in actual, 'cannot find key {} in flow {}'.format(k, actual)
31 assert actual[k] == expected[k], 'key:{}, actual:{} != expected:{}'.format(k, actual[k], expected[k])
34 def test_duration(actual, expected):
35 duration_key = 'duration'
36 hard_to_key = 'hard_timeout'
38 if duration_key in expected.keys():
39 assert duration_key in actual.keys(), '{} is not set in {}'.format(duration_key, actual)
41 duration = float(expected['duration'].rstrip('s'))
42 hard_timeout = int(actual['hard_timeout'])
43 assert duration <= hard_timeout, 'duration is higher than hard_timeout, {} > {}'.format(duration, hard_timeout)
45 Comparator.log.warning('cannot find keys to test duration tag', exc_info=True)
47 # VD - what should we do in this case